LSPS2: Include channels pending intial payment in the per-peer limit

We include any `OutboundJITChannel` that has not made it further than
`PendingInitialPayment` in the per-peer request limit, and will of
course prune it once it expires.
This commit is contained in:
Elias Rohrer 2024-12-13 10:28:18 +01:00
parent 440962e4fe
commit 7a8952110c
No known key found for this signature in database
GPG Key ID: 36153082BDF676FD

View File

@ -436,16 +436,15 @@ impl OutboundJITChannel {
Ok(action)
}
fn is_pending_initial_payment(&self) -> bool {
matches!(self.state, OutboundJITChannelState::PendingInitialPayment { .. })
}
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
self.is_pending_initial_payment() && is_expired
}
}
@ -496,6 +495,16 @@ impl PeerState {
});
}
fn pending_requests_and_channels(&self) -> usize {
let pending_requests = self.pending_requests.len();
let pending_outbound_channels = self
.outbound_channels_by_intercept_scid
.iter()
.filter(|(_, v)| v.is_pending_initial_payment())
.count();
pending_requests + pending_outbound_channels
}
fn is_prunable(&self) -> bool {
// Return whether the entire state is empty.
self.pending_requests.is_empty() && self.outbound_channels_by_intercept_scid.is_empty()
@ -1208,7 +1217,7 @@ where
return (result, msg);
}
if peer_state_lock.pending_requests.len() < MAX_PENDING_REQUESTS_PER_PEER {
if peer_state_lock.pending_requests_and_channels() < MAX_PENDING_REQUESTS_PER_PEER {
peer_state_lock.pending_requests.insert(request_id, request);
self.total_pending_requests.fetch_add(1, Ordering::Relaxed);
(Ok(()), None)