Browse Source

lnsweep: fix create_sweeptxs_for_their_just_revoked_ctx

in the case where an htlc is failed, it could happen
that we use the wrong list of htlcs to generate sweep
tx'es. we would use the pending list instead of the
committed list.

observed by sending 12300sat and then 123000sat,
the second payment fails and an AssertionError was
triggered cause the htlc output could not be found
in the ctx.

added some documentation to clarify the behaviour
of lnchan.included_htlcs.
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
Janus 6 years ago
committed by ThomasV
parent
commit
47c07f77b4
  1. 12
      electrum/lnchan.py
  2. 8
      electrum/lnsweep.py

12
electrum/lnchan.py

@ -635,6 +635,18 @@ class Channel(PrintError):
def htlcs(self, subject, only_pending): def htlcs(self, subject, only_pending):
""" """
only_pending: require the htlc's settlement to be pending (needs additional signatures/acks) only_pending: require the htlc's settlement to be pending (needs additional signatures/acks)
sets returned with True and False are disjunct
only_pending true:
skipped if settled or failed
<=>
included if not settled and not failed
only_pending false:
skipped if not (settled or failed)
<=>
included if not not (settled or failed)
included if settled or failed
""" """
update_log = self.log[subject] update_log = self.log[subject]
res = [] res = []

8
electrum/lnsweep.py

@ -103,9 +103,10 @@ def create_sweeptxs_for_their_just_revoked_ctx(chan: 'Channel', ctx: Transaction
privkey=other_revocation_privkey, privkey=other_revocation_privkey,
is_revocation=True) is_revocation=True)
return direct_sweep_tx, secondstage_sweep_tx, htlc_tx return direct_sweep_tx, secondstage_sweep_tx, htlc_tx
ctn = extract_ctn_from_tx_and_chan(ctx, chan)
assert ctn == chan.config[REMOTE].ctn
# received HTLCs, in their ctx # received HTLCs, in their ctx
# TODO consider carefully if "included_htlcs" is what we need here received_htlcs = chan.included_htlcs(REMOTE, LOCAL, False)
received_htlcs = list(chan.included_htlcs(REMOTE, LOCAL)) # type: List[UpdateAddHtlc]
for htlc in received_htlcs: for htlc in received_htlcs:
direct_sweep_tx, secondstage_sweep_tx, htlc_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=True) direct_sweep_tx, secondstage_sweep_tx, htlc_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=True)
if direct_sweep_tx: if direct_sweep_tx:
@ -113,8 +114,7 @@ def create_sweeptxs_for_their_just_revoked_ctx(chan: 'Channel', ctx: Transaction
if secondstage_sweep_tx: if secondstage_sweep_tx:
txs.append((htlc_tx.txid(), EncumberedTransaction(f'their_htlctx_{bh2u(htlc.payment_hash)}', secondstage_sweep_tx, csv_delay=0, cltv_expiry=0))) txs.append((htlc_tx.txid(), EncumberedTransaction(f'their_htlctx_{bh2u(htlc.payment_hash)}', secondstage_sweep_tx, csv_delay=0, cltv_expiry=0)))
# offered HTLCs, in their ctx # offered HTLCs, in their ctx
# TODO consider carefully if "included_htlcs" is what we need here offered_htlcs = chan.included_htlcs(REMOTE, REMOTE, False)
offered_htlcs = list(chan.included_htlcs(REMOTE, REMOTE)) # type: List[UpdateAddHtlc]
for htlc in offered_htlcs: for htlc in offered_htlcs:
direct_sweep_tx, secondstage_sweep_tx, htlc_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=False) direct_sweep_tx, secondstage_sweep_tx, htlc_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=False)
if direct_sweep_tx: if direct_sweep_tx:

Loading…
Cancel
Save