@@ -247,15 +247,15 @@ def justice_txin(output_idx):
247
247
)
248
248
index_to_sweepinfo = {}
249
249
for output_idx in htlc_outputs_idxs :
250
- prevout = htlc_tx . txid () + f': { output_idx } '
251
- index_to_sweepinfo [ prevout ] = SweepInfo (
252
- name = f'second-stage-htlc: { output_idx } ' ,
253
- csv_delay = 0 ,
254
- cltv_abs = None ,
255
- txin = justice_txin ( output_idx ) ,
256
- txout = None
257
- )
258
-
250
+ if txin := justice_txin ( output_idx ):
251
+ prevout = htlc_tx . txid () + f': { output_idx } '
252
+ index_to_sweepinfo [ prevout ] = SweepInfo (
253
+ name = f'second-stage-htlc: { output_idx } ' ,
254
+ csv_delay = 0 ,
255
+ cltv_abs = None ,
256
+ txin = txin ,
257
+ txout = None
258
+ )
259
259
return index_to_sweepinfo
260
260
261
261
@@ -338,22 +338,23 @@ def sweep_our_ctx(
338
338
output_idxs = ctx .get_output_idxs_from_address (to_local_address )
339
339
if actual_htlc_tx is None and output_idxs :
340
340
output_idx = output_idxs .pop ()
341
- txin = sweep_ctx_to_local (
342
- ctx = ctx ,
343
- output_idx = output_idx ,
344
- witness_script = to_local_witness_script ,
345
- privkey = our_localdelayed_privkey .get_secret_bytes (),
346
- is_revocation = False ,
347
- to_self_delay = to_self_delay ,
348
- config = chan .lnworker .config )
349
- prevout = ctx .txid () + ':%d' % output_idx
350
- txs [prevout ] = SweepInfo (
351
- name = 'our_ctx_to_local' ,
352
- csv_delay = to_self_delay ,
353
- cltv_abs = None ,
354
- txin = txin ,
355
- txout = None ,
356
- )
341
+ if txin := sweep_ctx_to_local (
342
+ ctx = ctx ,
343
+ output_idx = output_idx ,
344
+ witness_script = to_local_witness_script ,
345
+ privkey = our_localdelayed_privkey .get_secret_bytes (),
346
+ is_revocation = False ,
347
+ to_self_delay = to_self_delay ,
348
+ config = chan .lnworker .config ,
349
+ ):
350
+ prevout = ctx .txid () + ':%d' % output_idx
351
+ txs [prevout ] = SweepInfo (
352
+ name = 'our_ctx_to_local' ,
353
+ csv_delay = to_self_delay ,
354
+ cltv_abs = None ,
355
+ txin = txin ,
356
+ txout = None ,
357
+ )
357
358
we_breached = ctn < chan .get_oldest_unrevoked_ctn (LOCAL )
358
359
if we_breached :
359
360
chan .logger .info (f"(lnsweep) we breached. txid: { ctx .txid ()} " )
@@ -393,21 +394,22 @@ def txs_htlc(
393
394
address = bitcoin .script_to_p2wsh (htlctx_witness_script )
394
395
output_idxs = actual_htlc_tx .get_output_idxs_from_address (address )
395
396
for output_idx in output_idxs :
396
- sweep_txin = sweep_htlctx_output (
397
- to_self_delay = to_self_delay ,
398
- htlc_tx = actual_htlc_tx ,
399
- output_idx = output_idx ,
400
- htlctx_witness_script = htlctx_witness_script ,
401
- privkey = our_localdelayed_privkey .get_secret_bytes (),
402
- is_revocation = False ,
403
- config = chan .lnworker .config )
404
- txs [actual_htlc_tx .txid () + f':{ output_idx } ' ] = SweepInfo (
405
- name = f'second-stage-htlc:{ output_idx } ' ,
406
- csv_delay = to_self_delay ,
407
- cltv_abs = 0 ,
408
- txin = sweep_txin ,
409
- txout = None ,
410
- )
397
+ if sweep_txin := sweep_htlctx_output (
398
+ to_self_delay = to_self_delay ,
399
+ htlc_tx = actual_htlc_tx ,
400
+ output_idx = output_idx ,
401
+ htlctx_witness_script = htlctx_witness_script ,
402
+ privkey = our_localdelayed_privkey .get_secret_bytes (),
403
+ is_revocation = False ,
404
+ config = chan .lnworker .config
405
+ ):
406
+ txs [actual_htlc_tx .txid () + f':{ output_idx } ' ] = SweepInfo (
407
+ name = f'second-stage-htlc:{ output_idx } ' ,
408
+ csv_delay = to_self_delay ,
409
+ cltv_abs = 0 ,
410
+ txin = sweep_txin ,
411
+ txout = None ,
412
+ )
411
413
412
414
# offered HTLCs, in our ctx --> "timeout"
413
415
# received HTLCs, in our ctx --> "success"
@@ -553,20 +555,20 @@ def sweep_their_ctx_to_remote_backup(
553
555
if output_idxs :
554
556
output_idx = output_idxs .pop ()
555
557
prevout = ctx .txid () + ':%d' % output_idx
556
- txin = sweep_their_ctx_to_remote (
557
- ctx = ctx ,
558
- output_idx = output_idx ,
559
- our_payment_privkey = our_payment_privkey ,
560
- config = chan .lnworker .config ,
561
- has_anchors = True
562
- )
563
- txs [prevout ] = SweepInfo (
564
- name = 'their_ctx_to_remote_backup' ,
565
- csv_delay = csv_delay ,
566
- cltv_abs = None ,
567
- txin = txin ,
568
- txout = None ,
569
- )
558
+ if txin : = sweep_their_ctx_to_remote (
559
+ ctx = ctx ,
560
+ output_idx = output_idx ,
561
+ our_payment_privkey = our_payment_privkey ,
562
+ config = chan .lnworker .config ,
563
+ has_anchors = True
564
+ ):
565
+ txs [prevout ] = SweepInfo (
566
+ name = 'their_ctx_to_remote_backup' ,
567
+ csv_delay = csv_delay ,
568
+ cltv_abs = None ,
569
+ txin = txin ,
570
+ txout = None ,
571
+ )
570
572
return txs
571
573
572
574
@@ -628,8 +630,7 @@ def sweep_their_ctx(
628
630
# to_local is handled by lnwatcher
629
631
if is_revocation :
630
632
our_revocation_privkey = derive_blinded_privkey (our_conf .revocation_basepoint .privkey , per_commitment_secret )
631
- txin = sweep_their_ctx_justice (chan , ctx , per_commitment_secret )
632
- if txin :
633
+ if txin := sweep_their_ctx_justice (chan , ctx , per_commitment_secret ):
633
634
txs [txin .prevout .to_str ()] = SweepInfo (
634
635
name = 'to_local_for_revoked_ctx' ,
635
636
csv_delay = 0 ,
@@ -655,20 +656,20 @@ def sweep_their_ctx(
655
656
if output_idxs :
656
657
output_idx = output_idxs .pop ()
657
658
prevout = ctx .txid () + ':%d' % output_idx
658
- txin = sweep_their_ctx_to_remote (
659
- ctx = ctx ,
660
- output_idx = output_idx ,
661
- our_payment_privkey = our_payment_privkey ,
662
- config = chan .lnworker .config ,
663
- has_anchors = chan .has_anchors ()
664
- )
665
- txs [prevout ] = SweepInfo (
666
- name = 'their_ctx_to_remote' ,
667
- csv_delay = csv_delay ,
668
- cltv_abs = None ,
669
- txin = txin ,
670
- txout = None ,
671
- )
659
+ if txin : = sweep_their_ctx_to_remote (
660
+ ctx = ctx ,
661
+ output_idx = output_idx ,
662
+ our_payment_privkey = our_payment_privkey ,
663
+ config = chan .lnworker .config ,
664
+ has_anchors = chan .has_anchors ()
665
+ ):
666
+ txs [prevout ] = SweepInfo (
667
+ name = 'their_ctx_to_remote' ,
668
+ csv_delay = csv_delay ,
669
+ cltv_abs = None ,
670
+ txin = txin ,
671
+ txout = None ,
672
+ )
672
673
673
674
# HTLCs
674
675
our_htlc_privkey = derive_privkey (secret = int .from_bytes (our_conf .htlc_basepoint .privkey , 'big' ), per_commitment_point = their_pcp )
@@ -691,24 +692,24 @@ def tx_htlc(
691
692
cltv_abs = htlc .cltv_abs if is_received_htlc and not is_revocation else 0
692
693
csv_delay = 1 if chan .has_anchors () else 0
693
694
prevout = ctx .txid () + ':%d' % ctx_output_idx
694
- txin = sweep_their_ctx_htlc (
695
- ctx = ctx ,
696
- witness_script = htlc_output_witness_script ,
697
- preimage = preimage ,
698
- output_idx = ctx_output_idx ,
699
- privkey = our_revocation_privkey if is_revocation else our_htlc_privkey .get_secret_bytes (),
700
- is_revocation = is_revocation ,
701
- cltv_abs = cltv_abs ,
702
- config = chan .lnworker .config ,
703
- has_anchors = chan .has_anchors (),
704
- )
705
- txs [prevout ] = SweepInfo (
706
- name = f'their_ctx_htlc_{ ctx_output_idx } { "_for_revoked_ctx" if is_revocation else "" } ' ,
707
- csv_delay = csv_delay ,
708
- cltv_abs = cltv_abs ,
709
- txin = txin ,
710
- txout = None ,
711
- )
695
+ if txin : = sweep_their_ctx_htlc (
696
+ ctx = ctx ,
697
+ witness_script = htlc_output_witness_script ,
698
+ preimage = preimage ,
699
+ output_idx = ctx_output_idx ,
700
+ privkey = our_revocation_privkey if is_revocation else our_htlc_privkey .get_secret_bytes (),
701
+ is_revocation = is_revocation ,
702
+ cltv_abs = cltv_abs ,
703
+ config = chan .lnworker .config ,
704
+ has_anchors = chan .has_anchors (),
705
+ ):
706
+ txs [prevout ] = SweepInfo (
707
+ name = f'their_ctx_htlc_{ ctx_output_idx } { "_for_revoked_ctx" if is_revocation else "" } ' ,
708
+ csv_delay = csv_delay ,
709
+ cltv_abs = cltv_abs ,
710
+ txin = txin ,
711
+ txout = None ,
712
+ )
712
713
# received HTLCs, in their ctx --> "timeout"
713
714
# offered HTLCs, in their ctx --> "success"
714
715
htlc_to_ctx_output_idx_map = map_htlcs_to_ctx_output_idxs (
0 commit comments