1
0

lnsweep: use lnworker.is_accepted_mpp to decide if we can

release the preimage. (see #9280)

lnworker.is_accepted_mpp includes an assert that will raise
if the MPP has been cleaned-up too early.
This commit is contained in:
ThomasV
2024-10-25 11:51:17 +02:00
parent a1a28afee6
commit fabc3637a2
2 changed files with 9 additions and 6 deletions

View File

@@ -297,7 +297,7 @@ 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.is_incomplete_mpp(htlc.payment_hash):
if not chan.lnworker.is_accepted_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)
@@ -434,11 +434,13 @@ def create_sweeptxs_for_their_ctx(
for (direction, htlc), (ctx_output_idx, htlc_relative_idx) in htlc_to_ctx_output_idx_map.items():
is_received_htlc = direction == RECEIVED
if not is_received_htlc and not is_revocation:
if chan.lnworker.get_payment_status(htlc.payment_hash) == PR_PAID:
preimage = chan.lnworker.get_preimage(htlc.payment_hash)
else:
if not chan.lnworker.is_accepted_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_sweeptx_for_htlc(

View File

@@ -2332,10 +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:
def is_accepted_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
assert status is not None
return status.resolution == RecvMPPResolution.ACCEPTED
def get_first_timestamp_of_mpp(self, payment_key: bytes) -> int:
mpp_status = self.received_mpp_htlcs.get(payment_key.hex())