From 776ede44cb8d17d847469d9d58babd7e0e553f21 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Tue, 10 Dec 2024 09:36:09 +0100 Subject: [PATCH] LSPS2: Also prune expired `OutboundJITChannels` pending initial payments We're now also pruning any expired `OutboundJITChannels` if we haven't seen any related HTLCs. --- lightning-liquidity/src/lsps2/service.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lightning-liquidity/src/lsps2/service.rs b/lightning-liquidity/src/lsps2/service.rs index d2e67fa13..578a2f14e 100644 --- a/lightning-liquidity/src/lsps2/service.rs +++ b/lightning-liquidity/src/lsps2/service.rs @@ -435,6 +435,18 @@ impl OutboundJITChannel { self.state = new_state; Ok(action) } + + fn is_prunable(&self) -> bool { + // We deem an OutboundJITChannel prunable if our offer expired and we haven't intercepted + // any HTLCs initiating the flow yet. + let is_pending_initial_payment = match self.state { + OutboundJITChannelState::PendingInitialPayment { .. } => true, + _ => false, + }; + + let is_expired = is_expired_opening_fee_params(&self.opening_fee_params); + is_pending_initial_payment && is_expired + } } struct PeerState { @@ -472,6 +484,16 @@ impl PeerState { }, } }); + + self.outbound_channels_by_intercept_scid.retain(|intercept_scid, entry| { + if entry.is_prunable() { + // We abort the flow, and prune any data kept. + self.intercept_scid_by_channel_id.retain(|_, iscid| intercept_scid != iscid); + self.intercept_scid_by_user_channel_id.retain(|_, iscid| intercept_scid != iscid); + return false; + } + true + }); } }