electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit ef661050c8da36b7b2b73bec47dbaeddb38301f5
parent a125cd5392d8aa873b15663e59b5d3c269977afc
Author: ThomasV <thomasv@electrum.org>
Date:   Tue,  9 Mar 2021 09:35:43 +0100

lnworker: set request status after LN payment

Diffstat:
Melectrum/lnpeer.py | 11+++++++----
Melectrum/lnworker.py | 8+++++---
Melectrum/tests/test_lnpeer.py | 1+
3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py @@ -49,6 +49,7 @@ from .interface import GracefulDisconnect from .lnrouter import fee_for_edge_msat from .lnutil import ln_dummy_address from .json_db import StoredDict +from .invoices import PR_PAID if TYPE_CHECKING: from .lnworker import LNGossip, LNWallet, LNBackups @@ -1562,6 +1563,7 @@ class Peer(Logger): log_fail_reason(f"total_msat={total_msat} too different from invoice_msat={invoice_msat}") raise exc_incorrect_or_unknown_pd self.logger.info(f"maybe_fulfill_htlc. will FULFILL HTLC: chan {chan.short_channel_id}. htlc={str(htlc)}") + self.lnworker.set_request_status(htlc.payment_hash, PR_PAID) return preimage, None def fulfill_htlc(self, chan: Channel, htlc_id: int, preimage: bytes): @@ -1569,10 +1571,11 @@ class Peer(Logger): assert chan.can_send_ctx_updates(), f"cannot send updates: {chan.short_channel_id}" assert chan.hm.is_add_htlc_irrevocably_committed_yet(htlc_proposer=REMOTE, htlc_id=htlc_id) chan.settle_htlc(preimage, htlc_id) - self.send_message("update_fulfill_htlc", - channel_id=chan.channel_id, - id=htlc_id, - payment_preimage=preimage) + self.send_message( + "update_fulfill_htlc", + channel_id=chan.channel_id, + id=htlc_id, + payment_preimage=preimage) def fail_htlc(self, *, chan: Channel, htlc_id: int, error_bytes: bytes): self.logger.info(f"fail_htlc. chan {chan.short_channel_id}. htlc_id {htlc_id}.") diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -1617,9 +1617,6 @@ class LNWallet(LNWorker): is_expired = True elif total == expected_msat: is_accepted = True - if self.get_payment_info(payment_hash) is not None: - self.set_payment_status(payment_hash, PR_PAID) - util.trigger_callback('request_status', self.wallet, payment_hash.hex(), PR_PAID) if is_accepted or is_expired: htlc_set.remove(key) if len(htlc_set) > 0: @@ -1652,6 +1649,11 @@ class LNWallet(LNWorker): self.set_payment_status(bfh(key), status) util.trigger_callback('invoice_status', self.wallet, key) + def set_request_status(self, payment_hash: bytes, status: int) -> None: + if self.get_payment_status(payment_hash) != status: + self.set_payment_status(payment_hash, status) + util.trigger_callback('request_status', self.wallet, payment_hash.hex(), status) + def set_payment_status(self, payment_hash: bytes, status: int) -> None: info = self.get_payment_info(payment_hash) if info is None: diff --git a/electrum/tests/test_lnpeer.py b/electrum/tests/test_lnpeer.py @@ -182,6 +182,7 @@ class MockLNWallet(Logger, NetworkRetryManager[LNPeerAddr]): get_payment_info = LNWallet.get_payment_info save_payment_info = LNWallet.save_payment_info set_invoice_status = LNWallet.set_invoice_status + set_request_status = LNWallet.set_request_status set_payment_status = LNWallet.set_payment_status get_payment_status = LNWallet.get_payment_status add_received_htlc = LNWallet.add_received_htlc