commit 693583edc5010ece804e312626c7c40157613ff1
parent 06ea06f7d37a02d7d242d84eca89da3d85191c1b
Author: ThomasV <thomasv@electrum.org>
Date: Tue, 2 Mar 2021 10:23:30 +0100
lnworker: amount passed in HtlcLog must be without fees
Diffstat:
3 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py
@@ -993,7 +993,7 @@ class Channel(AbstractChannel):
if self.lnworker:
sent = self.hm.sent_in_ctn(new_ctn)
for htlc in sent:
- self.lnworker.htlc_fulfilled(self, htlc.payment_hash, htlc.htlc_id, htlc.amount_msat)
+ self.lnworker.htlc_fulfilled(self, htlc.payment_hash, htlc.htlc_id)
failed = self.hm.failed_in_ctn(new_ctn)
for htlc in failed:
try:
@@ -1004,7 +1004,7 @@ class Channel(AbstractChannel):
if self.lnworker.get_payment_info(htlc.payment_hash) is None:
self.save_fail_htlc_reason(htlc.htlc_id, error_bytes, failure_message)
else:
- self.lnworker.htlc_failed(self, htlc.payment_hash, htlc.htlc_id, htlc.amount_msat, error_bytes, failure_message)
+ self.lnworker.htlc_failed(self, htlc.payment_hash, htlc.htlc_id, error_bytes, failure_message)
def save_fail_htlc_reason(
self,
@@ -1049,7 +1049,7 @@ class Channel(AbstractChannel):
info = self.lnworker.get_payment_info(payment_hash)
if info is not None and info.status != PR_PAID:
if is_sent:
- self.lnworker.htlc_fulfilled(self, payment_hash, htlc.htlc_id, htlc.amount_msat)
+ self.lnworker.htlc_fulfilled(self, payment_hash, htlc.htlc_id)
else:
# FIXME
#self.lnworker.htlc_received(self, payment_hash)
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -658,7 +658,7 @@ class LNWallet(LNWorker):
self._channels[bfh(channel_id)] = Channel(c, sweep_address=self.sweep_address, lnworker=self)
self.sent_htlcs = defaultdict(asyncio.Queue) # type: Dict[bytes, asyncio.Queue[HtlcLog]]
- self.sent_htlcs_routes = dict() # (RHASH, scid, htlc_id) -> route
+ self.sent_htlcs_routes = dict() # (RHASH, scid, htlc_id) -> route, amount_for_receiver
self.received_htlcs = dict() # RHASH -> mpp_status, htlc_set
self.swap_manager = SwapManager(wallet=self.wallet, lnworker=self)
@@ -1166,7 +1166,7 @@ class LNWallet(LNWorker):
min_final_cltv_expiry=min_cltv_expiry,
payment_secret=payment_secret,
fwd_trampoline_onion=trampoline_onion)
- self.sent_htlcs_routes[(payment_hash, short_channel_id, htlc.htlc_id)] = route
+ self.sent_htlcs_routes[(payment_hash, short_channel_id, htlc.htlc_id)] = route, amount_msat
util.trigger_callback('htlc_added', chan, htlc, SENT)
def handle_error_code_from_failed_htlc(self, htlc_log):
@@ -1739,11 +1739,11 @@ class LNWallet(LNWorker):
info = info._replace(status=status)
self.save_payment_info(info)
- def htlc_fulfilled(self, chan, payment_hash: bytes, htlc_id:int, amount_msat:int):
+ def htlc_fulfilled(self, chan, payment_hash: bytes, htlc_id:int):
util.trigger_callback('htlc_fulfilled', payment_hash, chan.channel_id)
q = self.sent_htlcs.get(payment_hash)
if q:
- route = self.sent_htlcs_routes[(payment_hash, chan.short_channel_id, htlc_id)]
+ route, amount_msat = self.sent_htlcs_routes[(payment_hash, chan.short_channel_id, htlc_id)]
htlc_log = HtlcLog(
success=True,
route=route,
@@ -1759,14 +1759,13 @@ class LNWallet(LNWorker):
chan: Channel,
payment_hash: bytes,
htlc_id: int,
- amount_msat:int,
error_bytes: Optional[bytes],
failure_message: Optional['OnionRoutingFailure']):
util.trigger_callback('htlc_failed', payment_hash, chan.channel_id)
q = self.sent_htlcs.get(payment_hash)
if q:
- route = self.sent_htlcs_routes[(payment_hash, chan.short_channel_id, htlc_id)]
+ route, amount_msat = self.sent_htlcs_routes[(payment_hash, chan.short_channel_id, htlc_id)]
if error_bytes:
# TODO "decode_onion_error" might raise, catch and maybe blacklist/penalise someone?
try:
diff --git a/electrum/tests/test_lnpeer.py b/electrum/tests/test_lnpeer.py
@@ -134,7 +134,7 @@ class MockLNWallet(Logger, NetworkRetryManager[LNPeerAddr]):
self.enable_htlc_settle.set()
self.received_htlcs = dict()
self.sent_htlcs = defaultdict(asyncio.Queue)
- self.sent_htlcs_routes = defaultdict(list)
+ self.sent_htlcs_routes = dict()
def get_invoice_status(self, key):
pass
@@ -498,26 +498,24 @@ class TestPeer(ElectrumTestCase):
# alice sends htlc BUT NOT COMMITMENT_SIGNED
p1.maybe_send_commitment = lambda x: None
route1, amount_msat1 = w1.create_routes_from_invoice(lnaddr2.get_amount_msat(), decoded_invoice=lnaddr2)[0]
- p1.pay(
+ await w1.pay_to_route(
route=route1,
- chan=alice_channel,
amount_msat=lnaddr2.get_amount_msat(),
total_msat=lnaddr2.get_amount_msat(),
payment_hash=lnaddr2.paymenthash,
- min_final_cltv_expiry=lnaddr2.get_min_final_cltv_expiry(),
+ min_cltv_expiry=lnaddr2.get_min_final_cltv_expiry(),
payment_secret=lnaddr2.payment_secret,
)
p1.maybe_send_commitment = _maybe_send_commitment1
# bob sends htlc BUT NOT COMMITMENT_SIGNED
p2.maybe_send_commitment = lambda x: None
route2, amount_msat2 = w2.create_routes_from_invoice(lnaddr1.get_amount_msat(), decoded_invoice=lnaddr1)[0]
- p2.pay(
+ await w2.pay_to_route(
route=route2,
- chan=bob_channel,
amount_msat=lnaddr1.get_amount_msat(),
total_msat=lnaddr1.get_amount_msat(),
payment_hash=lnaddr1.paymenthash,
- min_final_cltv_expiry=lnaddr1.get_min_final_cltv_expiry(),
+ min_cltv_expiry=lnaddr1.get_min_final_cltv_expiry(),
payment_secret=lnaddr1.payment_secret,
)
p2.maybe_send_commitment = _maybe_send_commitment2