Fix detection of payments.
1. In lnhtlc, sent_in_ctn and failed_in_ctn need to look at the remote ctx, and they need to be called when we receive a revocation, not when we send one. 2. In lnchannel, we use 3 lnworker callbacks: - payment sent/payment failed (called when we receive a revocation) - payment received (called when we send a revocation) 3. Make revoke_current_commitment return a single value. The second value was only used in tests, there is no need to bloat the code with that
This commit is contained in:
@@ -517,15 +517,6 @@ class LNWallet(LNWorker):
|
||||
return ps.name
|
||||
return cs.name
|
||||
|
||||
def payment_completed(self, chan: Channel, direction: Direction,
|
||||
htlc: UpdateAddHtlc):
|
||||
chan_id = chan.channel_id
|
||||
preimage = self.get_preimage(htlc.payment_hash)
|
||||
timestamp = int(time.time())
|
||||
self.network.trigger_callback('ln_payment_completed', timestamp, direction, htlc, preimage, chan_id)
|
||||
if direction == SENT:
|
||||
self.payment_sent(htlc.payment_hash)
|
||||
|
||||
def get_settled_payments(self):
|
||||
# return one item per payment_hash
|
||||
# note: with AMP we will have several channels per payment
|
||||
@@ -1208,22 +1199,24 @@ class LNWallet(LNWorker):
|
||||
info = info._replace(status=status)
|
||||
self.save_payment_info(info)
|
||||
|
||||
def payment_failed(self, payment_hash: bytes, reason):
|
||||
def payment_failed(self, chan, payment_hash: bytes, reason):
|
||||
self.set_payment_status(payment_hash, PR_UNPAID)
|
||||
f = self.pending_payments[payment_hash]
|
||||
if not f.cancelled():
|
||||
f.set_result((False, None, reason))
|
||||
|
||||
def payment_sent(self, payment_hash: bytes):
|
||||
def payment_sent(self, chan, payment_hash: bytes):
|
||||
self.set_payment_status(payment_hash, PR_PAID)
|
||||
preimage = self.get_preimage(payment_hash)
|
||||
f = self.pending_payments[payment_hash]
|
||||
if not f.cancelled():
|
||||
f.set_result((True, preimage, None))
|
||||
self.network.trigger_callback('ln_payment_completed', payment_hash, chan.channel_id)
|
||||
|
||||
def payment_received(self, payment_hash: bytes):
|
||||
def payment_received(self, chan, payment_hash: bytes):
|
||||
self.set_payment_status(payment_hash, PR_PAID)
|
||||
self.network.trigger_callback('request_status', payment_hash.hex(), PR_PAID)
|
||||
self.network.trigger_callback('ln_payment_completed', payment_hash, chan.channel_id)
|
||||
|
||||
async def _calc_routing_hints_for_invoice(self, amount_sat):
|
||||
"""calculate routing hints (BOLT-11 'r' field)"""
|
||||
|
||||
Reference in New Issue
Block a user