Skip to content

Commit

Permalink
Merge pull request #7065 from SomberNight/20210224_mpp_recv_amt_sum
Browse files Browse the repository at this point in the history
lnpeer: MPP recv: only fulfill htlc if amt sum exact-matches total_msat
  • Loading branch information
ecdsa authored Feb 25, 2021
2 parents 5dc7b5b + 16f0b30 commit 61e7f7e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion electrum/lnchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,9 @@ def extract_preimage_from_htlc_txin(self, txin: TxInput) -> None:
if is_sent:
self.lnworker.htlc_fulfilled(self, payment_hash, htlc.htlc_id, htlc.amount_msat)
else:
self.lnworker.htlc_received(self, payment_hash)
# FIXME
#self.lnworker.htlc_received(self, payment_hash)
pass

def balance(self, whose: HTLCOwner, *, ctx_owner=HTLCOwner.LOCAL, ctn: int = None) -> int:
assert type(whose) is HTLCOwner
Expand Down
9 changes: 3 additions & 6 deletions electrum/lnpeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1566,13 +1566,10 @@ def maybe_fulfill_htlc(
else:
if payment_secret_from_onion != derive_payment_secret_from_payment_preimage(preimage):
raise OnionRoutingFailure(code=OnionFailureCode.INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS, data=b'')
expected_received_msat = info.amount_msat
if expected_received_msat is None:
return preimage

if not (expected_received_msat <= total_msat <= 2 * expected_received_msat):
invoice_msat = info.amount_msat
if not (invoice_msat is None or invoice_msat <= total_msat <= 2 * invoice_msat):
raise OnionRoutingFailure(code=OnionFailureCode.INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS, data=b'')
accepted, expired = self.lnworker.htlc_received(chan.short_channel_id, htlc, expected_received_msat)
accepted, expired = self.lnworker.htlc_received(chan.short_channel_id, htlc, total_msat)
if accepted:
return preimage
elif expired:
Expand Down
2 changes: 1 addition & 1 deletion electrum/lnworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ def htlc_received(self, short_channel_id, htlc: UpdateAddHtlc, expected_msat: in
total = sum([htlc.amount_msat for scid, htlc in s])
first_timestamp = min([htlc.timestamp for scid, htlc in s])
expired = time.time() - first_timestamp > MPP_EXPIRY
if total >= expected_msat and not expired:
if total == expected_msat and not expired:
# status must be persisted
self.set_payment_status(htlc.payment_hash, PR_PAID)
util.trigger_callback('request_status', self.wallet, htlc.payment_hash.hex(), PR_PAID)
Expand Down

0 comments on commit 61e7f7e

Please sign in to comment.