Browse Source

lnworker: set request status after LN payment

patch-4
ThomasV 4 years ago
parent
commit
ef661050c8
  1. 11
      electrum/lnpeer.py
  2. 8
      electrum/lnworker.py
  3. 1
      electrum/tests/test_lnpeer.py

11
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}.")

8
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:

1
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

Loading…
Cancel
Save