Browse Source

lnworker: always call check_received_htlc (no only for MPP)

This will be a generic placeholder to decide if we need to wait
before settling a payment (to be used with hold invoices and
bundled payments)
master
ThomasV 3 years ago
parent
commit
df5b98792e
  1. 16
      electrum/lnpeer.py
  2. 11
      electrum/lnworker.py
  3. 2
      electrum/tests/test_lnpeer.py

16
electrum/lnpeer.py

@ -1804,14 +1804,14 @@ class Peer(Logger):
# TODO fail here if invoice has set PAYMENT_SECRET_REQ
payment_secret_from_onion = None
if total_msat > amt_to_forward:
mpp_status = self.lnworker.check_received_mpp_htlc(payment_secret_from_onion, chan.short_channel_id, htlc, total_msat)
if mpp_status is None:
return None, None
if mpp_status is False:
log_fail_reason(f"MPP_TIMEOUT")
raise OnionRoutingFailure(code=OnionFailureCode.MPP_TIMEOUT, data=b'')
assert mpp_status is True
payment_status = self.lnworker.check_received_htlc(payment_secret_from_onion, chan.short_channel_id, htlc, total_msat)
if payment_status is None:
return None, None
elif payment_status is False:
log_fail_reason(f"MPP_TIMEOUT")
raise OnionRoutingFailure(code=OnionFailureCode.MPP_TIMEOUT, data=b'')
else:
assert payment_status is True
# if there is a trampoline_onion, maybe_fulfill_htlc will be called again
if processed_onion.trampoline_onion_packet:

11
electrum/lnworker.py

@ -1888,8 +1888,15 @@ class LNWallet(LNWorker):
if write_to_disk:
self.wallet.save_db()
def check_received_mpp_htlc(self, payment_secret, short_channel_id, htlc: UpdateAddHtlc, expected_msat: int) -> Optional[bool]:
""" return MPP status: True (accepted), False (expired) or None """
def check_received_htlc(self, payment_secret, short_channel_id, htlc: UpdateAddHtlc, expected_msat: int) -> Optional[bool]:
""" return MPP status: True (accepted), False (expired) or None (waiting)
"""
amt_to_forward = htlc.amount_msat # check this
if amt_to_forward >= expected_msat:
# not multi-part
return True
payment_hash = htlc.payment_hash
is_expired, is_accepted, htlc_set = self.received_mpp_htlcs.get(payment_secret, (False, False, set()))
if self.get_payment_status(payment_hash) == PR_PAID:

2
electrum/tests/test_lnpeer.py

@ -247,7 +247,7 @@ class MockLNWallet(Logger, EventListener, NetworkRetryManager[LNPeerAddr]):
set_request_status = LNWallet.set_request_status
set_payment_status = LNWallet.set_payment_status
get_payment_status = LNWallet.get_payment_status
check_received_mpp_htlc = LNWallet.check_received_mpp_htlc
check_received_htlc = LNWallet.check_received_htlc
htlc_fulfilled = LNWallet.htlc_fulfilled
htlc_failed = LNWallet.htlc_failed
save_preimage = LNWallet.save_preimage

Loading…
Cancel
Save