|
|
@ -143,7 +143,7 @@ def create_sweeptxs_for_our_latest_ctx(chan: 'Channel', ctx: Transaction, |
|
|
|
to_self_delay = chan.config[REMOTE].to_self_delay |
|
|
|
this_htlc_privkey = derive_privkey(secret=int.from_bytes(this_conf.htlc_basepoint.privkey, 'big'), |
|
|
|
per_commitment_point=our_pcp).to_bytes(32, 'big') |
|
|
|
txs = [] |
|
|
|
txs = {} |
|
|
|
# to_local |
|
|
|
sweep_tx = maybe_create_sweeptx_that_spends_to_local_in_our_ctx(ctx=ctx, |
|
|
|
sweep_address=sweep_address, |
|
|
@ -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(EncumberedTransaction('our_ctx_to_local', sweep_tx, csv_delay=to_self_delay, cltv_expiry=0)) |
|
|
|
txs[sweep_tx.prevout(0)] = 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(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)) |
|
|
|
txs[to_wallet_tx.prevout(0)] = EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0) |
|
|
|
txs[htlc_tx.prevout(0)] = 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(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)) |
|
|
|
txs[to_wallet_tx.prevout(0)] = EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0) |
|
|
|
txs[htlc_tx.prevout(0)] = EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=0) |
|
|
|
return txs |
|
|
|
|
|
|
|
|
|
|
@ -232,7 +232,7 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction, |
|
|
|
other_payment_privkey = derive_privkey(other_payment_bp_privkey.secret_scalar, their_pcp) |
|
|
|
other_payment_privkey = ecc.ECPrivkey.from_secret_scalar(other_payment_privkey) |
|
|
|
|
|
|
|
txs = [] |
|
|
|
txs = {} |
|
|
|
if per_commitment_secret: # breach |
|
|
|
# to_local |
|
|
|
other_revocation_privkey = derive_blinded_privkey(other_conf.revocation_basepoint.privkey, |
|
|
@ -250,7 +250,7 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction, |
|
|
|
sweep_address=sweep_address, |
|
|
|
our_payment_privkey=other_payment_privkey) |
|
|
|
if sweep_tx: |
|
|
|
txs.append(EncumberedTransaction('their_ctx_to_remote', sweep_tx, csv_delay=0, cltv_expiry=0)) |
|
|
|
txs[sweep_tx.prevout(0)] = 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(EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=htlc.cltv_expiry)) |
|
|
|
txs[prevout] = 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(EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=0)) |
|
|
|
txs[prevout] = EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=0) |
|
|
|
return txs |
|
|
|
|
|
|
|
|
|
|
|