From 4420944b7671e9060172d075cbf8d0dd501ae2d7 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 23 Oct 2024 12:32:08 +0200 Subject: [PATCH] lnsweep: detect incomplete MPP using mpp status instead of get_payment_status get_payment_status is not set in the case of a hold invvoice --- electrum/lnsweep.py | 8 +++++--- electrum/lnworker.py | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/electrum/lnsweep.py b/electrum/lnsweep.py index 9834176f4..e879d4dc0 100644 --- a/electrum/lnsweep.py +++ b/electrum/lnsweep.py @@ -297,11 +297,13 @@ def create_sweeptxs_for_our_ctx( ctn=ctn) for (direction, htlc), (ctx_output_idx, htlc_relative_idx) in htlc_to_ctx_output_idx_map.items(): if direction == RECEIVED: - if chan.lnworker.get_payment_status(htlc.payment_hash) == PR_PAID: - preimage = chan.lnworker.get_preimage(htlc.payment_hash) - else: + if chan.lnworker.is_incomplete_mpp(htlc.payment_hash): # do not redeem this, it might publish the preimage of an incomplete MPP continue + preimage = chan.lnworker.get_preimage(htlc.payment_hash) + if not preimage: + # we might not have the preimage if this is a hold invoice + continue else: preimage = None create_txns_for_htlc( diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 750746ff2..dec4dc9dc 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -2332,6 +2332,11 @@ class LNWallet(LNWorker): total = sum([_htlc.amount_msat for scid, _htlc in mpp_status.htlc_set]) return total >= mpp_status.expected_msat + def is_incomplete_mpp(self, payment_hash: bytes) -> bool: + payment_key = self._get_payment_key(payment_hash) + status = self.received_mpp_htlcs.get(payment_key.hex()) + return status and status.resolution == RecvMPPResolution.WAITING + def get_first_timestamp_of_mpp(self, payment_key: bytes) -> int: mpp_status = self.received_mpp_htlcs.get(payment_key.hex()) if not mpp_status: