Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 6ce2675

Browse files
committed
Re-introduce feature gate for lsps1_service
1 parent 97d6150 commit 6ce2675

File tree

7 files changed

+28
-4
lines changed

7 files changed

+28
-4
lines changed

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,10 @@ lightning-background-processor = { version = "0.0.123", default-features = false
4343
# lightning-background-processor = { path = "../rust-lightning/lightning-background-processor", default-features = false, features = ["std"] }
4444
proptest = "1.0.0"
4545
tokio = { version = "1.35", default-features = false, features = [ "rt-multi-thread", "time", "sync", "macros" ] }
46+
47+
[lints.rust.unexpected_cfgs]
48+
level = "forbid"
49+
# When adding a new cfg attribute, ensure that it is added to this list.
50+
check-cfg = [
51+
"cfg(lsps1_service)",
52+
]

src/events.rs

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub enum Event {
9999
/// An LSPS1 (Channel Request) client event.
100100
LSPS1Client(lsps1::event::LSPS1ClientEvent),
101101
/// An LSPS1 (Channel Request) server event.
102+
#[cfg(lsps1_service)]
102103
LSPS1Service(lsps1::event::LSPS1ServiceEvent),
103104
/// An LSPS2 (JIT Channel) client event.
104105
LSPS2Client(lsps2::event::LSPS2ClientEvent),

src/lsps1/event.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
//! Contains LSPS1 event types
1111
12-
use super::msgs::{ChannelInfo, OptionsSupported, OrderId, OrderParams, PaymentInfo};
12+
#[cfg(lsps1_service)]
13+
use super::msgs::OrderId;
14+
use super::msgs::{ChannelInfo, OptionsSupported, OrderParams, PaymentInfo};
1315

16+
#[cfg(lsps1_service)]
1417
use crate::lsps0::ser::RequestId;
1518
use crate::prelude::String;
1619

@@ -67,6 +70,7 @@ pub enum LSPS1ClientEvent {
6770
}
6871

6972
/// An event which an LSPS1 server should take some action in response to.
73+
#[cfg(lsps1_service)]
7074
#[derive(Clone, Debug, PartialEq, Eq)]
7175
pub enum LSPS1ServiceEvent {
7276
/// A client has selected the parameters to use from the supported options of the LSP

src/lsps1/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
pub mod client;
1313
pub mod event;
1414
pub mod msgs;
15+
#[cfg(lsps1_service)]
1516
pub mod service;
1617
pub(crate) mod utils;

src/lsps1/msgs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub(crate) const LSPS1_GET_INFO_METHOD_NAME: &str = "lsps1.get_info";
2121
pub(crate) const LSPS1_CREATE_ORDER_METHOD_NAME: &str = "lsps1.create_order";
2222
pub(crate) const LSPS1_GET_ORDER_METHOD_NAME: &str = "lsps1.get_order";
2323

24-
pub(crate) const LSPS1_CREATE_ORDER_REQUEST_INVALID_PARAMS_ERROR_CODE: i32 = -32602;
24+
pub(crate) const _LSPS1_CREATE_ORDER_REQUEST_INVALID_PARAMS_ERROR_CODE: i32 = -32602;
25+
#[cfg(lsps1_service)]
2526
pub(crate) const LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE: i32 = 100;
2627

2728
/// The identifier of an order.

src/manager.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::message_queue::MessageQueue;
1111

1212
use crate::lsps1::client::{LSPS1ClientConfig, LSPS1ClientHandler};
1313
use crate::lsps1::msgs::LSPS1Message;
14+
#[cfg(lsps1_service)]
1415
use crate::lsps1::service::{LSPS1ServiceConfig, LSPS1ServiceHandler};
1516

1617
use crate::lsps2::client::{LSPS2ClientConfig, LSPS2ClientHandler};
@@ -41,6 +42,7 @@ const LSPS_FEATURE_BIT: usize = 729;
4142
/// to provide liquidity services to clients.
4243
pub struct LiquidityServiceConfig {
4344
/// Optional server-side configuration for LSPS1 channel requests.
45+
#[cfg(lsps1_service)]
4446
pub lsps1_service_config: Option<LSPS1ServiceConfig>,
4547
/// Optional server-side configuration for JIT channels
4648
/// should you want to support them.
@@ -92,6 +94,7 @@ where
9294
ignored_peers: RwLock<HashSet<PublicKey>>,
9395
lsps0_client_handler: LSPS0ClientHandler<ES>,
9496
lsps0_service_handler: Option<LSPS0ServiceHandler>,
97+
#[cfg(lsps1_service)]
9598
lsps1_service_handler: Option<LSPS1ServiceHandler<ES, CM, C>>,
9699
lsps1_client_handler: Option<LSPS1ClientHandler<ES, CM, C>>,
97100
lsps2_service_handler: Option<LSPS2ServiceHandler<CM>>,
@@ -163,6 +166,7 @@ where {
163166
})
164167
});
165168

169+
#[cfg(lsps1_service)]
166170
let lsps1_service_handler = service_config.as_ref().and_then(|config| {
167171
if let Some(number) =
168172
<LSPS1ServiceHandler<ES> as ProtocolMessageHandler>::PROTOCOL_NUMBER
@@ -201,6 +205,7 @@ where {
201205
lsps0_client_handler,
202206
lsps0_service_handler,
203207
lsps1_client_handler,
208+
#[cfg(lsps1_service)]
204209
lsps1_service_handler,
205210
lsps2_client_handler,
206211
lsps2_service_handler,
@@ -227,6 +232,7 @@ where {
227232
}
228233

229234
/// Returns a reference to the LSPS1 server-side handler.
235+
#[cfg(lsps1_service)]
230236
pub fn lsps1_service_handler(&self) -> Option<&LSPS1ServiceHandler<ES, CM, C>> {
231237
self.lsps1_service_handler.as_ref()
232238
}
@@ -420,15 +426,18 @@ where {
420426
},
421427
}
422428
},
423-
LSPSMessage::LSPS1(msg @ LSPS1Message::Request(..)) => {
429+
LSPSMessage::LSPS1(_msg @ LSPS1Message::Request(..)) => {
430+
#[cfg(lsps1_service)]
424431
match &self.lsps1_service_handler {
425432
Some(lsps1_service_handler) => {
426-
lsps1_service_handler.handle_message(msg, sender_node_id)?;
433+
lsps1_service_handler.handle_message(_msg, sender_node_id)?;
427434
},
428435
None => {
429436
return Err(LightningError { err: format!("Received LSPS1 request message without LSPS1 service handler configured. From node = {:?}", sender_node_id), action: ErrorAction::IgnoreAndLog(Level::Info)});
430437
},
431438
}
439+
#[cfg(not(lsps1_service))]
440+
return Err(LightningError { err: format!("Received LSPS1 request message without LSPS1 service handler configured. From node = {:?}", sender_node_id), action: ErrorAction::IgnoreAndLog(Level::Info)});
432441
},
433442
LSPSMessage::LSPS2(msg @ LSPS2Message::Response(..)) => {
434443
match &self.lsps2_client_handler {

tests/lsps2_integration_tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ fn invoice_generation_flow() {
8585
let promise_secret = [42; 32];
8686
let lsps2_service_config = LSPS2ServiceConfig { promise_secret };
8787
let service_config = LiquidityServiceConfig {
88+
#[cfg(lsps1_service)]
8889
lsps1_service_config: None,
8990
lsps2_service_config: Some(lsps2_service_config),
9091
advertise_service: true,

0 commit comments

Comments
 (0)