From b0401a6386bb229435f786e050ba75e5eedd335c Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 17 Oct 2023 16:22:31 +0000 Subject: [PATCH] lnpeer.maybe_forward_trampoline: fix abs-cltv vs cltv-delta confusion lnworker.pay_to_node(min_cltv_expiry=) expects a relative cltv, and we were passing an absolute one. It is not so clear what precisely should be passed here, and that is because pay_to_node's API was not written with forwarding in mind. The value chosen here is just some guess that typically should work. --- electrum/lnpeer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 70bf25c0e..1d965fba4 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -1771,7 +1771,7 @@ class Peer(Logger): # these are the fee/cltv paid by the sender # pay_to_node will raise if they are not sufficient - trampoline_cltv_delta = cltv_expiry - cltv_from_onion + trampoline_cltv_delta = cltv_expiry - cltv_from_onion # cltv budget total_msat = outer_onion.hop_data.payload["payment_data"]["total_msat"] trampoline_fee = total_msat - amt_to_forward self.logger.info(f'trampoline cltv and fee: {trampoline_cltv_delta, trampoline_fee}') @@ -1782,7 +1782,10 @@ class Peer(Logger): payment_hash=payment_hash, payment_secret=payment_secret, amount_to_pay=amt_to_forward, - min_cltv_expiry=cltv_from_onion, + # FIXME this API (min_cltv_expiry) is bad. This is setting the cltv-delta for the last edge + # on the path to the *next trampoline* node. We should just let lnrouter set this. + # Instead, we should rewrite pay_to_node to operate on a fee-budget and cltv-budget. + min_cltv_expiry=lnutil.MIN_FINAL_CLTV_EXPIRY_FOR_INVOICE, r_tags=r_tags, invoice_features=invoice_features, fwd_trampoline_onion=next_trampoline_onion,