Skip to content

Commit 5c7a247

Browse files
committed
lnsweep: use batch payment manager:
- return tx inputs instead if fully signed tx - tx inputs have make_witness method and privkey - regtest use force mpp
1 parent 25f478d commit 5c7a247

9 files changed

+248
-299
lines changed

electrum/lnchannel.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
fee_for_htlc_output, offered_htlc_trim_threshold_sat,
5858
received_htlc_trim_threshold_sat, make_commitment_output_to_remote_address, FIXED_ANCHOR_SAT,
5959
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
60+
from .lnsweep import sweep_our_ctx, sweep_their_ctx
61+
from .lnsweep import sweep_their_htlctx_justice, sweep_our_htlctx, SweepInfo
62+
from .lnsweep import sweep_their_ctx_to_remote_backup
6363
from .lnhtlc import HTLCManager
6464
from .lnmsg import encode_msg, decode_msg
6565
from .address_synchronizer import TX_HEIGHT_LOCAL
@@ -285,10 +285,10 @@ def delete_closing_height(self):
285285
self.storage.pop('closing_height', None)
286286

287287
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())
288+
return sweep_our_ctx(chan=self, ctx=ctx)
289289

290290
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())
291+
return sweep_their_ctx(chan=self, ctx=ctx)
292292

293293
def is_backup(self) -> bool:
294294
return False
@@ -315,8 +315,8 @@ def sweep_ctx(self, ctx: Transaction) -> Dict[str, SweepInfo]:
315315
self.logger.info(f'not sure who closed.')
316316
return self._sweep_info[txid]
317317

318-
def maybe_sweep_revoked_htlc(self, ctx: Transaction, htlc_tx: Transaction) -> Optional[SweepInfo]:
319-
return None
318+
def maybe_sweep_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Optional[SweepInfo]:
319+
return {}
320320

321321
def extract_preimage_from_htlc_txin(self, txin: TxInput) -> None:
322322
return
@@ -595,15 +595,15 @@ def is_backup(self):
595595
return True
596596

597597
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())
598+
return sweep_their_ctx_to_remote_backup(chan=self, ctx=ctx)
599599

600600
def create_sweeptxs_for_our_ctx(self, ctx):
601601
if self.is_imported:
602-
return txs_our_ctx(chan=self, ctx=ctx, sweep_address=self.get_sweep_address())
602+
return sweep_our_ctx(chan=self, ctx=ctx)
603603
else:
604604
return
605605

606-
def maybe_sweep_revoked_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[int, SweepInfo]:
606+
def maybe_sweep_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[int, SweepInfo]:
607607
return {}
608608

609609
def extract_preimage_from_htlc_txin(self, txin: TxInput) -> None:
@@ -1491,9 +1491,9 @@ def get_oldest_unrevoked_commitment(self, subject: HTLCOwner) -> PartialTransact
14911491
return self.get_commitment(subject, ctn=ctn)
14921492

14931493
def create_sweeptxs_for_watchtower(self, ctn: int) -> List[Transaction]:
1494-
from .lnsweep import txs_their_ctx_watchtower
1494+
from .lnsweep import sweep_their_ctx_watchtower
14951495
secret, ctx = self.get_secret_and_commitment(REMOTE, ctn=ctn)
1496-
return txs_their_ctx_watchtower(self, ctx, secret, self.get_sweep_address())
1496+
return sweep_their_ctx_watchtower(self, ctx, secret, self.get_sweep_address())
14971497

14981498
def get_oldest_unrevoked_ctn(self, subject: HTLCOwner) -> int:
14991499
return self.hm.ctn_oldest_unrevoked(subject)
@@ -1726,9 +1726,12 @@ def get_close_options(self) -> Sequence[ChanCloseOption]:
17261726
assert not (self.get_state() == ChannelState.WE_ARE_TOXIC and ChanCloseOption.LOCAL_FCLOSE in ret), "local force-close unsafe if we are toxic"
17271727
return ret
17281728

1729-
def maybe_sweep_revoked_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[int, SweepInfo]:
1729+
def maybe_sweep_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[int, SweepInfo]:
17301730
# look at the output address, check if it matches
1731-
return txs_their_htlctx_justice(self, ctx, htlc_tx, self.get_sweep_address())
1731+
d = sweep_their_htlctx_justice(self, ctx, htlc_tx)
1732+
d2 = sweep_our_htlctx(self, ctx, htlc_tx)
1733+
d.update(d2)
1734+
return d
17321735

17331736
def has_pending_changes(self, subject: HTLCOwner) -> bool:
17341737
next_htlcs = self.hm.get_htlcs_in_next_ctx(subject)

0 commit comments

Comments
 (0)