From 06687e06d8f4b699c2a1e6580300bfc5f258d186 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 30 May 2022 16:46:31 +0200 Subject: [PATCH] lnpeer: forwarding: better handle if next_peer is offline --- electrum/lnpeer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index c1f5ec4c4..e427cbc3f 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -1607,14 +1607,17 @@ class Peer(Logger): if htlc.amount_msat - next_amount_msat_htlc < forwarding_fees: data = next_amount_msat_htlc.to_bytes(8, byteorder="big") + outgoing_chan_upd_message raise OnionRoutingFailure(code=OnionFailureCode.FEE_INSUFFICIENT, data=data) - self.logger.info(f'forwarding htlc to {next_chan.node_id}') + self.logger.info(f'forwarding htlc to {next_chan.node_id.hex()}') + next_peer = self.lnworker.peers.get(next_chan.node_id) + if next_peer is None: + self.logger.info(f"failed to forward htlc: next_peer offline ({next_chan.node_id.hex()})") + raise OnionRoutingFailure(code=OnionFailureCode.TEMPORARY_CHANNEL_FAILURE, data=outgoing_chan_upd_message) next_htlc = UpdateAddHtlc( amount_msat=next_amount_msat_htlc, payment_hash=htlc.payment_hash, cltv_expiry=next_cltv_expiry, timestamp=int(time.time())) next_htlc = next_chan.add_htlc(next_htlc) - next_peer = self.lnworker.peers[next_chan.node_id] try: next_peer.send_message( "update_add_htlc",