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:
@@ -297,7 +297,7 @@ def create_sweeptxs_for_our_ctx(
|
|||||||
ctn=ctn)
|
ctn=ctn)
|
||||||
for (direction, htlc), (ctx_output_idx, htlc_relative_idx) in htlc_to_ctx_output_idx_map.items():
|
for (direction, htlc), (ctx_output_idx, htlc_relative_idx) in htlc_to_ctx_output_idx_map.items():
|
||||||
if direction == RECEIVED:
|
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
|
# do not redeem this, it might publish the preimage of an incomplete MPP
|
||||||
continue
|
continue
|
||||||
preimage = chan.lnworker.get_preimage(htlc.payment_hash)
|
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():
|
for (direction, htlc), (ctx_output_idx, htlc_relative_idx) in htlc_to_ctx_output_idx_map.items():
|
||||||
is_received_htlc = direction == RECEIVED
|
is_received_htlc = direction == RECEIVED
|
||||||
if not is_received_htlc and not is_revocation:
|
if not is_received_htlc and not is_revocation:
|
||||||
if chan.lnworker.get_payment_status(htlc.payment_hash) == PR_PAID:
|
if not chan.lnworker.is_accepted_mpp(htlc.payment_hash):
|
||||||
preimage = chan.lnworker.get_preimage(htlc.payment_hash)
|
|
||||||
else:
|
|
||||||
# do not redeem this, it might publish the preimage of an incomplete MPP
|
# do not redeem this, it might publish the preimage of an incomplete MPP
|
||||||
continue
|
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:
|
else:
|
||||||
preimage = None
|
preimage = None
|
||||||
create_sweeptx_for_htlc(
|
create_sweeptx_for_htlc(
|
||||||
|
|||||||
@@ -2332,10 +2332,11 @@ class LNWallet(LNWorker):
|
|||||||
total = sum([_htlc.amount_msat for scid, _htlc in mpp_status.htlc_set])
|
total = sum([_htlc.amount_msat for scid, _htlc in mpp_status.htlc_set])
|
||||||
return total >= mpp_status.expected_msat
|
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)
|
payment_key = self._get_payment_key(payment_hash)
|
||||||
status = self.received_mpp_htlcs.get(payment_key.hex())
|
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:
|
def get_first_timestamp_of_mpp(self, payment_key: bytes) -> int:
|
||||||
mpp_status = self.received_mpp_htlcs.get(payment_key.hex())
|
mpp_status = self.received_mpp_htlcs.get(payment_key.hex())
|
||||||
|
|||||||
Reference in New Issue
Block a user