Skip to content

Commit 3a318f8

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 4d20463 commit 3a318f8

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
@@ -451,6 +451,18 @@ impl OutboundJITChannel {
451451
self.state = new_state;
452452
Ok(action)
453453
}
454+
455+
fn is_prunable(&self) -> bool {
456+
// We deem an OutboundJITChannel prunable if our offer expired and we haven't intercepted
457+
// any HTLCs initiating the flow yet.
458+
let is_pending_initial_payment = match self.state {
459+
OutboundJITChannelState::PendingInitialPayment { .. } => true,
460+
_ => false,
461+
};
462+
463+
let is_expired = is_expired_opening_fee_params(&self.opening_fee_params);
464+
is_pending_initial_payment && is_expired
465+
}
454466
}
455467

456468
struct PeerState {
@@ -488,6 +500,16 @@ impl PeerState {
488500
},
489501
}
490502
});
503+
504+
self.outbound_channels_by_intercept_scid.retain(|intercept_scid, entry| {
505+
if entry.is_prunable() {
506+
// We abort the flow, and prune any data kept.
507+
self.intercept_scid_by_channel_id.retain(|_, iscid| intercept_scid != iscid);
508+
self.intercept_scid_by_user_channel_id.retain(|_, iscid| intercept_scid != iscid);
509+
return false;
510+
}
511+
true
512+
});
491513
}
492514
}
493515

0 commit comments

Comments
 (0)