From 2252def3fc7f05bc87a4e42d00750ea080214aa6 Mon Sep 17 00:00:00 2001 From: Martin Saposnic Date: Fri, 20 Mar 2026 09:43:31 -0300 Subject: [PATCH] fix(lsps4): trigger channel open at peer_connected even during reestablish When an HTLC arrives for an offline peer, htlc_intercepted stores it and sends a webhook. When the peer reconnects, peer_connected deferred all processing if channels existed but weren't usable yet (reestablish in progress). Later, process_pending_htlcs found insufficient capacity but assumed a channel open was already in flight - nobody ever opened the channel. Fix: call process_htlcs_for_peer even when channels aren't usable. calculate_htlc_actions skips non-usable channels, so if existing capacity is insufficient it returns new_channel_needed_msat and execute_htlc_actions emits OpenChannel. No premature forwarding occurs since the forwards list is empty (no usable channels). The actual HTLC forwards happen via channel_ready once the new channel is established. --- lightning-liquidity/src/lsps4/service.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lightning-liquidity/src/lsps4/service.rs b/lightning-liquidity/src/lsps4/service.rs index 5d9b7ee673e..52b23f31170 100644 --- a/lightning-liquidity/src/lsps4/service.rs +++ b/lightning-liquidity/src/lsps4/service.rs @@ -390,14 +390,22 @@ where // at all (process_htlcs_for_peer will trigger OpenChannel for JIT). self.process_htlcs_for_peer(counterparty_node_id.clone(), htlcs); } else { - // Channels exist but none usable: reestablish still in progress. - // Defer until process_pending_htlcs picks them up on the timer. + // Channels exist but none usable yet (reestablish in progress). + // We still call process_htlcs_for_peer because calculate_htlc_actions + // skips non-usable channels. If existing capacity is insufficient, this + // will emit OpenChannel now rather than deferring to process_pending_htlcs + // (which would never open a channel). Forwards through existing channels + // will be empty since none are usable, so no premature forwarding occurs. + // The actual forwards happen later via channel_ready or process_pending_htlcs + // once reestablish completes. log_info!( self.logger, - "[LSPS4] peer_connected: {counterparty_node_id} has {} pending HTLCs but channels \ - not yet usable (reestablish in progress), deferring", + "[LSPS4] peer_connected: {} has {} pending HTLCs, channels not yet usable \ + (reestablish in progress) - checking if new channel needed", + counterparty_node_id, htlcs.len() ); + self.process_htlcs_for_peer(counterparty_node_id.clone(), htlcs); } log_info!(