From ffba3fb7fc3a37b3a200b68702c5716d55882f28 Mon Sep 17 00:00:00 2001 From: bitromortac Date: Mon, 6 Dec 2021 16:53:44 +0100 Subject: [PATCH] lnpeer: fix possibly nonexistant to_remote check `drop_to_remote` can be False and at the same time the to_remote output is not present, because it is below dust. Therefore, we have to explicitly check if to_remote is present when checking for the allowed script types and dust limits. This affects channels which have sent only dust values, they can't be closed unilaterally without this fix. Fixes a regression introduced by 947693c90d6579ca52281ea7228a91fd59a81c81. --- electrum/lnpeer.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 1435389dc..4de547064 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -1807,8 +1807,9 @@ class Peer(Logger): raise Exception('failed to verify their signature') # at this point we know how the closing tx looks like # check that their output is above their scriptpubkey's network dust limit - if not drop_to_remote: - to_remote_idx = closing_tx.get_output_idxs_from_scriptpubkey(their_scriptpubkey.hex()).pop() + to_remote_set = closing_tx.get_output_idxs_from_scriptpubkey(their_scriptpubkey.hex()) + if not drop_to_remote and to_remote_set: + to_remote_idx = to_remote_set.pop() to_remote_amount = closing_tx.outputs()[to_remote_idx].value transaction.check_scriptpubkey_template_and_dust(their_scriptpubkey, to_remote_amount)