From 2664ee7f63c7ab3736a1825902c7ed44d6efebb7 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 18 Oct 2023 19:32:08 +0200 Subject: [PATCH] pay_to_node: raise failure_msg if we received a trampoline error from the next onion. that way, the error is sent back to the payer --- electrum/lnworker.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/electrum/lnworker.py b/electrum/lnworker.py index e89b7ec26..19272eac2 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -1523,8 +1523,6 @@ class LNWallet(LNWorker): self.network.path_finder.update_inflight_htlcs(htlc_log.route, add_htlcs=False) return # htlc failed - if (attempts is not None and len(log) >= attempts) or (attempts is None and time.time() - paysession.start_time > self.PAYMENT_TIMEOUT): - raise PaymentFailure('Giving up after %d attempts'%len(log)) # if we get a tmp channel failure, it might work to split the amount and try more routes # if we get a channel update, we might retry the same route and amount route = htlc_log.route @@ -1537,6 +1535,11 @@ class LNWallet(LNWorker): self.logger.info(f"error reported by {erring_node_id.hex()}") if code == OnionFailureCode.MPP_TIMEOUT: raise PaymentFailure(failure_msg.code_name()) + # errors returned by the next trampoline. + if fwd_trampoline_onion and code in [ + OnionFailureCode.TRAMPOLINE_FEE_INSUFFICIENT, + OnionFailureCode.TRAMPOLINE_EXPIRY_TOO_SOON]: + raise failure_msg # trampoline if self.uses_trampoline(): paysession.handle_failed_trampoline_htlc( @@ -1544,6 +1547,9 @@ class LNWallet(LNWorker): else: self.handle_error_code_from_failed_htlc( route=route, sender_idx=sender_idx, failure_msg=failure_msg, amount=htlc_log.amount_msat) + # max attempts or timeout + if (attempts is not None and len(log) >= attempts) or (attempts is None and time.time() - paysession.start_time > self.PAYMENT_TIMEOUT): + raise PaymentFailure('Giving up after %d attempts'%len(log)) finally: paysession.is_active = False if paysession.can_be_deleted():