Skip to content

Commit c0fe4c2

Browse files
committed
f Use MAX_PENDING_REQUESTS_PER_PEER const
1 parent 71450f7 commit c0fe4c2

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

lightning-liquidity/src/lsps2/service.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ use crate::lsps2::msgs::{
4242
LSPS2_GET_INFO_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE,
4343
};
4444

45-
/// The default value applied for [`LSPS2ServiceLimits::max_pending_requests_per_peer`].
46-
pub const DEFAULT_MAX_PENDING_REQUESTS_PER_PEER: usize = 10;
45+
const MAX_PENDING_REQUESTS_PER_PEER: usize = 10;
4746

4847
/// Server-side configuration options for JIT channels.
4948
#[derive(Clone, Debug)]
@@ -52,23 +51,6 @@ pub struct LSPS2ServiceConfig {
5251
///
5352
/// Note: If this changes then old promises given out will be considered invalid.
5453
pub promise_secret: [u8; 32],
55-
/// Configuration limits for JIT channels.
56-
pub service_limits: LSPS2ServiceLimits,
57-
}
58-
59-
/// Server-side configuration limits for JIT channels.
60-
#[derive(Clone, Debug)]
61-
pub struct LSPS2ServiceLimits {
62-
/// The maximum number of pending requests we allow on a per-peer basis.
63-
///
64-
/// Any requests beyond this limit will be ignored.
65-
pub max_pending_requests_per_peer: usize,
66-
}
67-
68-
impl Default for LSPS2ServiceLimits {
69-
fn default() -> Self {
70-
Self { max_pending_requests_per_peer: DEFAULT_MAX_PENDING_REQUESTS_PER_PEER }
71-
}
7254
}
7355

7456
/// Information about the initial payment size and JIT channel opening fee.
@@ -1010,9 +992,7 @@ where
1010992
.entry(*counterparty_node_id)
1011993
.or_insert(Mutex::new(PeerState::new()));
1012994
let mut peer_state_lock = inner_state_lock.lock().unwrap();
1013-
if peer_state_lock.pending_requests.len()
1014-
< self.config.service_limits.max_pending_requests_per_peer
1015-
{
995+
if peer_state_lock.pending_requests.len() < MAX_PENDING_REQUESTS_PER_PEER {
1016996
peer_state_lock
1017997
.pending_requests
1018998
.insert(request_id.clone(), LSPS2Request::GetInfo(params.clone()));
@@ -1035,7 +1015,7 @@ where
10351015

10361016
let err = format!(
10371017
"Peer {} reached maximum number of pending requests: {}",
1038-
counterparty_node_id, self.config.service_limits.max_pending_requests_per_peer
1018+
counterparty_node_id, MAX_PENDING_REQUESTS_PER_PEER
10391019
);
10401020

10411021
let result =
@@ -1143,9 +1123,7 @@ where
11431123
.or_insert(Mutex::new(PeerState::new()));
11441124
let mut peer_state_lock = inner_state_lock.lock().unwrap();
11451125

1146-
if peer_state_lock.pending_requests.len()
1147-
< self.config.service_limits.max_pending_requests_per_peer
1148-
{
1126+
if peer_state_lock.pending_requests.len() < MAX_PENDING_REQUESTS_PER_PEER {
11491127
peer_state_lock
11501128
.pending_requests
11511129
.insert(request_id.clone(), LSPS2Request::Buy(params.clone()));
@@ -1170,7 +1148,7 @@ where
11701148

11711149
let err = format!(
11721150
"Peer {} reached maximum number of pending requests: {}",
1173-
counterparty_node_id, self.config.service_limits.max_pending_requests_per_peer
1151+
counterparty_node_id, MAX_PENDING_REQUESTS_PER_PEER
11741152
);
11751153
let result =
11761154
Err(LightningError { err, action: ErrorAction::IgnoreAndLog(Level::Debug) });

lightning-liquidity/tests/lsps2_integration_tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ fn create_jit_invoice(
8383
#[test]
8484
fn invoice_generation_flow() {
8585
let promise_secret = [42; 32];
86-
let service_limits = Default::default();
87-
let lsps2_service_config = LSPS2ServiceConfig { promise_secret, service_limits };
86+
let lsps2_service_config = LSPS2ServiceConfig { promise_secret };
8887
let service_config = LiquidityServiceConfig {
8988
#[cfg(lsps1_service)]
9089
lsps1_service_config: None,

0 commit comments

Comments
 (0)