Skip to content

Commit eedd9d2

Browse files
committed
lnworker: allow overwriting amount of sent payment info
Allows replacing a saved `PaymentInfo` of `SENT` direction if the old one is not yet paid. This allows the user to retry paying a 0 amount invoice with different amount if the previous attempt failed.
1 parent 8a40feb commit eedd9d2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

electrum/lnworker.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,9 +2549,15 @@ def save_payment_info(self, info: PaymentInfo, *, write_to_disk: bool = True) ->
25492549
if old_info := self.get_payment_info(payment_hash=info.payment_hash, direction=info.direction):
25502550
if info == old_info:
25512551
return # already saved
2552-
if info.direction == SENT:
2553-
# allow saving of newer PaymentInfo if it is a sending attempt
2554-
old_info = dataclasses.replace(old_info, creation_ts=info.creation_ts)
2552+
if info.direction == SENT and old_info.status in (PR_UNPAID, PR_FAILED):
2553+
# allow saving of newer PaymentInfo if it is a sending attempt and the previous
2554+
# payment failed or was not yet attempted
2555+
old_info = dataclasses.replace(
2556+
old_info,
2557+
creation_ts=info.creation_ts,
2558+
status=info.status,
2559+
amount_msat=info.amount_msat, # might retrying to pay 0 amount invoice
2560+
)
25552561
if info != dataclasses.replace(old_info, status=info.status):
25562562
# differs more than in status. let's fail
25572563
raise Exception(f"payment_hash already in use: {info=} != {old_info=}")

0 commit comments

Comments
 (0)