Skip to content

Commit bdea03e

Browse files
committed
LSPS2: Also prune expired OutboundJITChannels pending initial payments
We're now also pruning any expired `OutboundJITChannels` if we haven't seen any related HTLCs.
1 parent 806fffb commit bdea03e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lightning-liquidity/src/lsps2/service.rs

+22
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,18 @@ impl OutboundJITChannel {
435435
self.state = new_state;
436436
Ok(action)
437437
}
438+
439+
fn is_prunable(&self) -> bool {
440+
// We deem an OutboundJITChannel prunable if our offer expired and we haven't intercepted
441+
// any HTLCs initiating the flow yet.
442+
let is_pending_initial_payment = match self.state {
443+
OutboundJITChannelState::PendingInitialPayment { .. } => true,
444+
_ => false,
445+
};
446+
447+
let is_expired = is_expired_opening_fee_params(&self.opening_fee_params);
448+
is_pending_initial_payment && is_expired
449+
}
438450
}
439451

440452
struct PeerState {
@@ -472,6 +484,16 @@ impl PeerState {
472484
},
473485
}
474486
});
487+
488+
self.outbound_channels_by_intercept_scid.retain(|intercept_scid, entry| {
489+
if entry.is_prunable() {
490+
// We abort the flow, and prune any data kept.
491+
self.intercept_scid_by_channel_id.retain(|_, iscid| intercept_scid != iscid);
492+
self.intercept_scid_by_user_channel_id.retain(|_, iscid| intercept_scid != iscid);
493+
return false;
494+
}
495+
true
496+
});
475497
}
476498
}
477499

0 commit comments

Comments
 (0)