Skip to content

Commit c0c52b1

Browse files
committed
Require supported_options in LSPS1ServiceConfig
In the future we might want to inline the fields in `LSPS1ServiceConfig` (especially once some are added that we'd want to always/never set for the user), but for now we just make the `supported_options` field in `LSPS1ServiceConfig` required, avoiding some dangerous `unwrap`s.
1 parent c0e4bf6 commit c0c52b1

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

lightning-liquidity/src/lsps1/service.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct LSPS1ServiceConfig {
4747
/// A token to be send with each channel request.
4848
pub token: Option<String>,
4949
/// The options supported by the LSP.
50-
pub supported_options: Option<LSPS1Options>,
50+
pub supported_options: LSPS1Options,
5151
}
5252

5353
/// The main object allowing to send and receive bLIP-51 / LSPS1 messages.
@@ -118,15 +118,7 @@ where
118118
let mut message_queue_notifier = self.pending_messages.notifier();
119119

120120
let response = LSPS1Response::GetInfo(LSPS1GetInfoResponse {
121-
options: self
122-
.config
123-
.supported_options
124-
.clone()
125-
.ok_or(LightningError {
126-
err: format!("Configuration for LSP server not set."),
127-
action: ErrorAction::IgnoreAndLog(Level::Info),
128-
})
129-
.unwrap(),
121+
options: self.config.supported_options.clone(),
130122
});
131123

132124
let msg = LSPS1Message::Response(request_id, response).into();
@@ -141,14 +133,11 @@ where
141133
let mut message_queue_notifier = self.pending_messages.notifier();
142134
let event_queue_notifier = self.pending_events.notifier();
143135

144-
if !is_valid(&params.order, &self.config.supported_options.as_ref().unwrap()) {
136+
if !is_valid(&params.order, &self.config.supported_options) {
145137
let response = LSPS1Response::CreateOrderError(LSPSResponseError {
146138
code: LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE,
147139
message: format!("Order does not match options supported by LSP server"),
148-
data: Some(format!(
149-
"Supported options are {:?}",
150-
&self.config.supported_options.as_ref().unwrap()
151-
)),
140+
data: Some(format!("Supported options are {:?}", &self.config.supported_options)),
152141
});
153142
let msg = LSPS1Message::Response(request_id, response).into();
154143
message_queue_notifier.enqueue(counterparty_node_id, msg);

lightning-liquidity/tests/lsps0_integration_tests.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use lightning_liquidity::lsps0::event::LSPS0ClientEvent;
99
#[cfg(lsps1_service)]
1010
use lightning_liquidity::lsps1::client::LSPS1ClientConfig;
1111
#[cfg(lsps1_service)]
12+
use lightning_liquidity::lsps1::msgs::LSPS1Options;
13+
#[cfg(lsps1_service)]
1214
use lightning_liquidity::lsps1::service::LSPS1ServiceConfig;
1315
use lightning_liquidity::lsps2::client::LSPS2ClientConfig;
1416
use lightning_liquidity::lsps2::service::LSPS2ServiceConfig;
@@ -34,7 +36,21 @@ fn list_protocols_integration_test() {
3436
let promise_secret = [42; 32];
3537
let lsps2_service_config = LSPS2ServiceConfig { promise_secret };
3638
#[cfg(lsps1_service)]
37-
let lsps1_service_config = LSPS1ServiceConfig { supported_options: None, token: None };
39+
let lsps1_service_config = {
40+
let supported_options = LSPS1Options {
41+
min_required_channel_confirmations: 0,
42+
min_funding_confirms_within_blocks: 6,
43+
supports_zero_channel_reserve: true,
44+
max_channel_expiry_blocks: 144,
45+
min_initial_client_balance_sat: 10_000_000,
46+
max_initial_client_balance_sat: 100_000_000,
47+
min_initial_lsp_balance_sat: 100_000,
48+
max_initial_lsp_balance_sat: 100_000_000,
49+
min_channel_balance_sat: 100_000,
50+
max_channel_balance_sat: 100_000_000,
51+
};
52+
LSPS1ServiceConfig { supported_options, token: None }
53+
};
3854
let lsps5_service_config = LSPS5ServiceConfig::default();
3955
let service_config = LiquidityServiceConfig {
4056
#[cfg(lsps1_service)]

lightning-liquidity/tests/lsps1_integration_tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use lightning::ln::functional_test_utils::{create_network, Node};
3030
fn build_lsps1_configs(
3131
supported_options: LSPS1Options,
3232
) -> (LiquidityServiceConfig, LiquidityClientConfig) {
33-
let lsps1_service_config =
34-
LSPS1ServiceConfig { token: None, supported_options: Some(supported_options) };
33+
let lsps1_service_config = LSPS1ServiceConfig { token: None, supported_options };
3534
let service_config = LiquidityServiceConfig {
3635
lsps1_service_config: Some(lsps1_service_config),
3736
lsps2_service_config: None,

0 commit comments

Comments
 (0)