on_close_channel: fix output index, and simplify lnsweep
This commit is contained in:
@@ -151,7 +151,7 @@ def create_sweeptxs_for_our_latest_ctx(chan: 'Channel', ctx: Transaction,
|
||||
remote_revocation_pubkey=other_revocation_pubkey,
|
||||
to_self_delay=to_self_delay)
|
||||
if sweep_tx:
|
||||
txs.append((ctx.txid(), EncumberedTransaction('our_ctx_to_local', sweep_tx, csv_delay=to_self_delay, cltv_expiry=0)))
|
||||
txs.append(EncumberedTransaction('our_ctx_to_local', sweep_tx, csv_delay=to_self_delay, cltv_expiry=0))
|
||||
# HTLCs
|
||||
def create_txns_for_htlc(htlc: 'UpdateAddHtlc', is_received_htlc: bool) -> Tuple[Optional[Transaction], Optional[Transaction]]:
|
||||
if is_received_htlc:
|
||||
@@ -184,16 +184,16 @@ def create_sweeptxs_for_our_latest_ctx(chan: 'Channel', ctx: Transaction,
|
||||
for htlc in offered_htlcs:
|
||||
htlc_tx, to_wallet_tx = create_txns_for_htlc(htlc, is_received_htlc=False)
|
||||
if htlc_tx and to_wallet_tx:
|
||||
txs.append((htlc_tx.txid(), EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0)))
|
||||
txs.append((ctx.txid(), EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=htlc.cltv_expiry)))
|
||||
txs.append(EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0))
|
||||
txs.append(EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=htlc.cltv_expiry))
|
||||
# received HTLCs, in our ctx --> "success"
|
||||
# TODO consider carefully if "included_htlcs" is what we need here
|
||||
received_htlcs = list(chan.included_htlcs(LOCAL, REMOTE)) # type: List[UpdateAddHtlc]
|
||||
for htlc in received_htlcs:
|
||||
htlc_tx, to_wallet_tx = create_txns_for_htlc(htlc, is_received_htlc=True)
|
||||
if htlc_tx and to_wallet_tx:
|
||||
txs.append((htlc_tx.txid(), EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0)))
|
||||
txs.append((ctx.txid(), EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=0)))
|
||||
txs.append(EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0))
|
||||
txs.append(EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=0))
|
||||
return txs
|
||||
|
||||
|
||||
@@ -244,13 +244,13 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction,
|
||||
delayed_pubkey=this_delayed_pubkey,
|
||||
sweep_address=sweep_address)
|
||||
if sweep_tx:
|
||||
txs.append((ctx.txid(), EncumberedTransaction('their_ctx_to_local', sweep_tx, csv_delay=0, cltv_expiry=0)))
|
||||
txs.append(EncumberedTransaction('their_ctx_to_local', sweep_tx, csv_delay=0, cltv_expiry=0))
|
||||
# to_remote
|
||||
sweep_tx = maybe_create_sweeptx_for_their_ctx_to_remote(ctx=ctx,
|
||||
sweep_address=sweep_address,
|
||||
our_payment_privkey=other_payment_privkey)
|
||||
if sweep_tx:
|
||||
txs.append((ctx.txid(), EncumberedTransaction('their_ctx_to_remote', sweep_tx, csv_delay=0, cltv_expiry=0)))
|
||||
txs.append(EncumberedTransaction('their_ctx_to_remote', sweep_tx, csv_delay=0, cltv_expiry=0))
|
||||
# HTLCs
|
||||
# from their ctx, we can only redeem HTLCs if the ctx was not revoked,
|
||||
# as old HTLCs are not stored. (if it was revoked, then we should have presigned txns
|
||||
@@ -286,13 +286,13 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction,
|
||||
for htlc in received_htlcs:
|
||||
sweep_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=True)
|
||||
if sweep_tx:
|
||||
txs.append((ctx.txid(), EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=htlc.cltv_expiry)))
|
||||
txs.append(EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=htlc.cltv_expiry))
|
||||
# offered HTLCs, in their ctx --> "success"
|
||||
offered_htlcs = chan.included_htlcs_in_their_latest_ctxs(REMOTE)[ctn] # type: List[UpdateAddHtlc]
|
||||
for htlc in offered_htlcs:
|
||||
sweep_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=False)
|
||||
if sweep_tx:
|
||||
txs.append((ctx.txid(), EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=0)))
|
||||
txs.append(EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=0))
|
||||
return txs
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user