44
44
from .transaction import Transaction , PartialTransaction , TxInput , Sighash
45
45
from .logging import Logger
46
46
from .lntransport import LNPeerAddr
47
- from .lnonion import OnionFailureCode , OnionRoutingFailure
47
+ from .lnonion import OnionRoutingFailure
48
48
from . import lnutil
49
49
from .lnutil import (Outpoint , LocalConfig , RemoteConfig , Keypair , OnlyPubkeyKeypair , ChannelConstraints ,
50
50
get_per_commitment_secret_from_seed , secret_to_pubkey , derive_privkey , make_closing_tx ,
51
51
sign_and_get_sig_string , RevocationStore , derive_blinded_pubkey , Direction , derive_pubkey ,
52
- make_htlc_tx_with_open_channel , make_commitment , make_received_htlc , make_offered_htlc ,
53
- HTLC_TIMEOUT_WEIGHT , HTLC_SUCCESS_WEIGHT , extract_ctn_from_tx_and_chan , UpdateAddHtlc ,
52
+ make_htlc_tx_with_open_channel , make_commitment , UpdateAddHtlc ,
54
53
funding_output_script , SENT , RECEIVED , LOCAL , REMOTE , HTLCOwner , make_commitment_outputs ,
55
54
ScriptHtlc , PaymentFailure , calc_fees_for_commitment_tx , RemoteMisbehaving , make_htlc_output_witness_script ,
56
55
ShortChannelID , map_htlcs_to_ctx_output_idxs ,
57
56
fee_for_htlc_output , offered_htlc_trim_threshold_sat ,
58
57
received_htlc_trim_threshold_sat , make_commitment_output_to_remote_address , FIXED_ANCHOR_SAT ,
59
- ChannelType , LNProtocolWarning , ctx_has_anchors )
60
- from .lnsweep import txs_our_ctx , txs_their_ctx
61
- from .lnsweep import txs_their_htlctx_justice , SweepInfo
62
- from .lnsweep import tx_their_ctx_to_remote_backup
58
+ ChannelType , LNProtocolWarning )
59
+ from .lnsweep import sweep_our_ctx , sweep_their_ctx
60
+ from .lnsweep import sweep_their_htlctx_justice , sweep_our_htlctx , SweepInfo
61
+ from .lnsweep import sweep_their_ctx_to_remote_backup
63
62
from .lnhtlc import HTLCManager
64
63
from .lnmsg import encode_msg , decode_msg
65
64
from .address_synchronizer import TX_HEIGHT_LOCAL
@@ -284,11 +283,11 @@ def get_closing_height(self) -> Optional[Tuple[str, int, Optional[int]]]:
284
283
def delete_closing_height (self ):
285
284
self .storage .pop ('closing_height' , None )
286
285
287
- def create_sweeptxs_for_our_ctx (self , ctx : Transaction ) -> Optional [ Dict [str , SweepInfo ] ]:
288
- return txs_our_ctx (chan = self , ctx = ctx , sweep_address = self . get_sweep_address () )
286
+ def create_sweeptxs_for_our_ctx (self , ctx : Transaction ) -> Dict [str , SweepInfo ]:
287
+ return sweep_our_ctx (chan = self , ctx = ctx )
289
288
290
- def create_sweeptxs_for_their_ctx (self , ctx : Transaction ) -> Optional [ Dict [str , SweepInfo ] ]:
291
- return txs_their_ctx (chan = self , ctx = ctx , sweep_address = self . get_sweep_address () )
289
+ def create_sweeptxs_for_their_ctx (self , ctx : Transaction ) -> Dict [str , SweepInfo ]:
290
+ return sweep_their_ctx (chan = self , ctx = ctx )
292
291
293
292
def is_backup (self ) -> bool :
294
293
return False
@@ -315,8 +314,8 @@ def sweep_ctx(self, ctx: Transaction) -> Dict[str, SweepInfo]:
315
314
self .logger .info (f'not sure who closed.' )
316
315
return self ._sweep_info [txid ]
317
316
318
- def maybe_sweep_revoked_htlc (self , ctx : Transaction , htlc_tx : Transaction ) -> Optional [ SweepInfo ]:
319
- return None
317
+ def maybe_sweep_htlcs (self , ctx : Transaction , htlc_tx : Transaction ) -> Dict [ str , SweepInfo ]:
318
+ return {}
320
319
321
320
def extract_preimage_from_htlc_txin (self , txin : TxInput ) -> None :
322
321
return
@@ -595,15 +594,15 @@ def is_backup(self):
595
594
return True
596
595
597
596
def create_sweeptxs_for_their_ctx (self , ctx ):
598
- return tx_their_ctx_to_remote_backup (chan = self , ctx = ctx , sweep_address = self . get_sweep_address () )
597
+ return sweep_their_ctx_to_remote_backup (chan = self , ctx = ctx )
599
598
600
599
def create_sweeptxs_for_our_ctx (self , ctx ):
601
600
if self .is_imported :
602
- return txs_our_ctx (chan = self , ctx = ctx , sweep_address = self . get_sweep_address () )
601
+ return sweep_our_ctx (chan = self , ctx = ctx )
603
602
else :
604
- return
603
+ return {}
605
604
606
- def maybe_sweep_revoked_htlcs (self , ctx : Transaction , htlc_tx : Transaction ) -> Dict [int , SweepInfo ]:
605
+ def maybe_sweep_htlcs (self , ctx : Transaction , htlc_tx : Transaction ) -> Dict [str , SweepInfo ]:
607
606
return {}
608
607
609
608
def extract_preimage_from_htlc_txin (self , txin : TxInput ) -> None :
@@ -1491,9 +1490,23 @@ def get_oldest_unrevoked_commitment(self, subject: HTLCOwner) -> PartialTransact
1491
1490
return self .get_commitment (subject , ctn = ctn )
1492
1491
1493
1492
def create_sweeptxs_for_watchtower (self , ctn : int ) -> List [Transaction ]:
1494
- from .lnsweep import txs_their_ctx_watchtower
1493
+ from .lnsweep import sweep_their_ctx_watchtower
1494
+ from .transaction import PartialTxOutput , PartialTransaction
1495
1495
secret , ctx = self .get_secret_and_commitment (REMOTE , ctn = ctn )
1496
- return txs_their_ctx_watchtower (self , ctx , secret , self .get_sweep_address ())
1496
+ txs = []
1497
+ txins = sweep_their_ctx_watchtower (self , ctx , secret )
1498
+ for txin in txins :
1499
+ output_idx = txin .prevout .out_idx
1500
+ value = ctx .outputs ()[output_idx ].value
1501
+ tx_size_bytes = 121
1502
+ fee = self .lnworker .config .estimate_fee (tx_size_bytes , allow_fallback_to_static_rates = True )
1503
+ outvalue = value - fee
1504
+ sweep_outputs = [PartialTxOutput .from_address_and_value (self .get_sweep_address (), outvalue )]
1505
+ sweep_tx = PartialTransaction .from_io ([txin ], sweep_outputs , version = 2 )
1506
+ sig = sweep_tx .sign_txin (0 , txin .privkey )
1507
+ txin .witness = txin .make_witness (sig )
1508
+ txs .append (sweep_tx )
1509
+ return txs
1497
1510
1498
1511
def get_oldest_unrevoked_ctn (self , subject : HTLCOwner ) -> int :
1499
1512
return self .hm .ctn_oldest_unrevoked (subject )
@@ -1726,9 +1739,12 @@ def get_close_options(self) -> Sequence[ChanCloseOption]:
1726
1739
assert not (self .get_state () == ChannelState .WE_ARE_TOXIC and ChanCloseOption .LOCAL_FCLOSE in ret ), "local force-close unsafe if we are toxic"
1727
1740
return ret
1728
1741
1729
- def maybe_sweep_revoked_htlcs (self , ctx : Transaction , htlc_tx : Transaction ) -> Dict [int , SweepInfo ]:
1742
+ def maybe_sweep_htlcs (self , ctx : Transaction , htlc_tx : Transaction ) -> Dict [str , SweepInfo ]:
1730
1743
# look at the output address, check if it matches
1731
- return txs_their_htlctx_justice (self , ctx , htlc_tx , self .get_sweep_address ())
1744
+ d = sweep_their_htlctx_justice (self , ctx , htlc_tx )
1745
+ d2 = sweep_our_htlctx (self , ctx , htlc_tx )
1746
+ d .update (d2 )
1747
+ return d
1732
1748
1733
1749
def has_pending_changes (self , subject : HTLCOwner ) -> bool :
1734
1750
next_htlcs = self .hm .get_htlcs_in_next_ctx (subject )
0 commit comments