Skip to content

Commit 3dd18db

Browse files
committed
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.
1 parent 08fd499 commit 3dd18db

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lightning-liquidity/src/lsps2/service.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,15 @@ impl OutboundJITChannel {
436436
Ok(action)
437437
}
438438

439+
fn is_pending_initial_payment(&self) -> bool {
440+
matches!(self.state, OutboundJITChannelState::PendingInitialPayment { .. })
441+
}
442+
439443
fn is_prunable(&self) -> bool {
440444
// We deem an OutboundJITChannel prunable if our offer expired and we haven't intercepted
441445
// any HTLCs initiating the flow yet.
442-
let is_pending_initial_payment = match self.state {
443-
OutboundJITChannelState::PendingInitialPayment { .. } => true,
444-
_ => false,
445-
};
446-
447446
let is_expired = is_expired_opening_fee_params(&self.opening_fee_params);
448-
is_pending_initial_payment && is_expired
447+
self.is_pending_initial_payment() && is_expired
449448
}
450449
}
451450

@@ -496,6 +495,16 @@ impl PeerState {
496495
});
497496
}
498497

498+
fn pending_requests_and_channels(&self) -> usize {
499+
let pending_requests = self.pending_requests.len();
500+
let pending_outbound_channels = self
501+
.outbound_channels_by_intercept_scid
502+
.iter()
503+
.filter(|(_, v)| v.is_pending_initial_payment())
504+
.count();
505+
pending_requests + pending_outbound_channels
506+
}
507+
499508
fn is_prunable(&self) -> bool {
500509
// Return whether the entire state is empty.
501510
self.pending_requests.is_empty() && self.outbound_channels_by_intercept_scid.is_empty()
@@ -1208,7 +1217,7 @@ where
12081217
return (result, msg);
12091218
}
12101219

1211-
if peer_state_lock.pending_requests.len() < MAX_PENDING_REQUESTS_PER_PEER {
1220+
if peer_state_lock.pending_requests_and_channels() < MAX_PENDING_REQUESTS_PER_PEER {
12121221
peer_state_lock.pending_requests.insert(request_id, request);
12131222
self.total_pending_requests.fetch_add(1, Ordering::Relaxed);
12141223
(Ok(()), None)

0 commit comments

Comments
 (0)