Skip to content

Commit 004c5c3

Browse files
WIP
1 parent 0e3ea87 commit 004c5c3

File tree

4 files changed

+22
-37
lines changed

4 files changed

+22
-37
lines changed

lightning-liquidity/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ categories = ["cryptography::cryptocurrencies"]
1616
[features]
1717
default = ["std", "time"]
1818
std = ["lightning/std"]
19-
time = []
19+
time = ["std"]
2020
backtrace = ["dep:backtrace"]
2121

2222
[dependencies]

lightning-liquidity/src/lsps5/service.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,6 @@ pub struct LSPS5ServiceConfig {
8989
pub notification_cooldown_hours: Duration,
9090
}
9191

92-
/// Default maximum number of webhooks allowed per client.
93-
pub const DEFAULT_MAX_WEBHOOKS_PER_CLIENT: u32 = 10;
94-
/// Default notification cooldown time in hours.
95-
pub const DEFAULT_NOTIFICATION_COOLDOWN_HOURS: Duration = Duration::from_secs(24 * 60 * 60);
96-
97-
impl Default for LSPS5ServiceConfig {
98-
fn default() -> Self {
99-
Self {
100-
max_webhooks_per_client: DEFAULT_MAX_WEBHOOKS_PER_CLIENT,
101-
signing_key: SecretKey::from_slice(&[1; 32]).expect("Static key should be valid"),
102-
notification_cooldown_hours: DEFAULT_NOTIFICATION_COOLDOWN_HOURS,
103-
}
104-
}
105-
}
106-
10792
/// Service for handling LSPS5 webhook registration
10893
pub struct LSPS5ServiceHandler<CM: Deref>
10994
where
@@ -184,8 +169,7 @@ where
184169
Ok(())
185170
}
186171

187-
/// Handle a set_webhook request.
188-
pub fn handle_set_webhook(
172+
fn handle_set_webhook(
189173
&self, counterparty_node_id: PublicKey, request_id: LSPSRequestId,
190174
params: SetWebhookRequest,
191175
) -> Result<(), LightningError> {
@@ -259,8 +243,7 @@ where
259243
Ok(())
260244
}
261245

262-
/// Handle a list_webhooks request.
263-
pub fn handle_list_webhooks(
246+
fn handle_list_webhooks(
264247
&self, counterparty_node_id: PublicKey, request_id: LSPSRequestId,
265248
_params: ListWebhooksRequest,
266249
) -> Result<(), LightningError> {
@@ -290,8 +273,7 @@ where
290273
Ok(())
291274
}
292275

293-
/// Handle a remove_webhook request.
294-
pub fn handle_remove_webhook(
276+
fn handle_remove_webhook(
295277
&self, counterparty_node_id: PublicKey, request_id: LSPSRequestId,
296278
params: RemoveWebhookRequest,
297279
) -> Result<(), LightningError> {

lightning-liquidity/tests/common/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,11 @@ fn advance_chain(node: &mut Node, num_blocks: u32) {
685685
}
686686
}
687687

688+
/// Default maximum number of webhooks allowed per client.
689+
pub(crate) const DEFAULT_MAX_WEBHOOKS_PER_CLIENT: u32 = 10;
690+
/// Default notification cooldown time in hours.
691+
pub(crate) const DEFAULT_NOTIFICATION_COOLDOWN_HOURS: Duration = Duration::from_secs(24 * 60 * 60);
692+
688693
pub(crate) fn get_client_and_service(
689694
time_provider: Option<Arc<dyn TimeProvider>>,
690695
) -> (
@@ -696,7 +701,11 @@ pub(crate) fn get_client_and_service(
696701
&'static Node,
697702
) {
698703
let signing_key = SecretKey::from_slice(&[42; 32]).unwrap();
699-
let mut lsps5_service_config = LSPS5ServiceConfig::default();
704+
let mut lsps5_service_config = LSPS5ServiceConfig {
705+
max_webhooks_per_client: DEFAULT_MAX_WEBHOOKS_PER_CLIENT,
706+
signing_key,
707+
notification_cooldown_hours: DEFAULT_NOTIFICATION_COOLDOWN_HOURS,
708+
};
700709
lsps5_service_config.signing_key = signing_key;
701710
let service_config = LiquidityServiceConfig {
702711
#[cfg(lsps1_service)]

lightning-liquidity/tests/lsps5_integration_tests.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
mod common;
44

5-
use common::{get_client_and_service, get_lsps_message};
5+
use common::{get_client_and_service, get_lsps_message, DEFAULT_MAX_WEBHOOKS_PER_CLIENT};
66
use lightning::ln::msgs::LightningError;
77
use lightning::ln::peer_handler::CustomMessageHandler;
88
use lightning::util::hash_tables::HashSet;
@@ -11,7 +11,7 @@ use lightning_liquidity::lsps5::event::{LSPS5ClientEvent, LSPS5ServiceEvent};
1111
use lightning_liquidity::lsps5::msgs::{
1212
LSPS5AppName, LSPS5Error, LSPS5WebhookUrl, WebhookNotification, WebhookNotificationMethod,
1313
};
14-
use lightning_liquidity::lsps5::service::{LSPS5ServiceConfig, TimeProvider};
14+
use lightning_liquidity::lsps5::service::TimeProvider;
1515
use lightning_liquidity::lsps5::service::{
1616
MIN_WEBHOOK_RETENTION_DAYS, PRUNE_STALE_WEBHOOKS_INTERVAL_DAYS,
1717
};
@@ -103,7 +103,6 @@ fn webhook_registration_flow() {
103103
},
104104
_ => panic!("Expected SendWebhookNotifications event"),
105105
}
106-
107106
let set_webhook_response = get_lsps_message!(service_node, client_node_id);
108107

109108
client_node
@@ -123,7 +122,7 @@ fn webhook_registration_flow() {
123122
request_id: req_id,
124123
}) => {
125124
assert_eq!(num_webhooks, 1);
126-
assert_eq!(max_webhooks, LSPS5ServiceConfig::default().max_webhooks_per_client);
125+
assert_eq!(max_webhooks, DEFAULT_MAX_WEBHOOKS_PER_CLIENT);
127126
assert_eq!(no_change, false);
128127
assert_eq!(lsp, service_node_id);
129128
assert_eq!(an, app_name.clone());
@@ -154,7 +153,7 @@ fn webhook_registration_flow() {
154153
}) => {
155154
assert_eq!(app_names, vec![app_name.clone()]);
156155
assert_eq!(counterparty_node_id, client_node_id);
157-
assert_eq!(max_webhooks, LSPS5ServiceConfig::default().max_webhooks_per_client);
156+
assert_eq!(max_webhooks, DEFAULT_MAX_WEBHOOKS_PER_CLIENT);
158157
assert_eq!(req_id, list_request_id);
159158
},
160159
_ => panic!("Unexpected event"),
@@ -177,7 +176,7 @@ fn webhook_registration_flow() {
177176
}) => {
178177
assert_eq!(lsp, service_node_id);
179178
assert_eq!(app_names, vec![app_name.clone()]);
180-
assert_eq!(max_webhooks, LSPS5ServiceConfig::default().max_webhooks_per_client);
179+
assert_eq!(max_webhooks, DEFAULT_MAX_WEBHOOKS_PER_CLIENT);
181180
assert_eq!(request_id, list_request_id);
182181
},
183182
_ => panic!("Unexpected event"),
@@ -352,8 +351,7 @@ fn webhook_error_handling_test() {
352351
// TEST 5: Too many webhooks - register the max number and then try one more
353352
let valid_app_name_base = "Valid App";
354353
let valid_url = "https://example.org/webhook";
355-
356-
for i in 0..LSPS5ServiceConfig::default().max_webhooks_per_client {
354+
for i in 0..DEFAULT_MAX_WEBHOOKS_PER_CLIENT {
357355
let app_name = format!("{} {}", valid_app_name_base, i);
358356
let _ = client_handler
359357
.set_webhook(service_node_id, app_name, valid_url.to_string())
@@ -369,11 +367,7 @@ fn webhook_error_handling_test() {
369367
}
370368

371369
// Now try to add one more webhook - should fail with too many webhooks error
372-
let raw_one_too_many = format!(
373-
"{} {}",
374-
valid_app_name_base,
375-
LSPS5ServiceConfig::default().max_webhooks_per_client
376-
);
370+
let raw_one_too_many = format!("{} {}", valid_app_name_base, DEFAULT_MAX_WEBHOOKS_PER_CLIENT);
377371
let one_too_many = LSPS5AppName::from_string(raw_one_too_many.to_string()).unwrap();
378372
let _ = client_handler
379373
.set_webhook(service_node_id, raw_one_too_many.clone(), valid_url.to_string())
@@ -396,7 +390,7 @@ fn webhook_error_handling_test() {
396390
}) => {
397391
let error_to_check = LSPS5Error::TooManyWebhooks(format!(
398392
"Maximum of {} webhooks allowed per client",
399-
LSPS5ServiceConfig::default().max_webhooks_per_client
393+
DEFAULT_MAX_WEBHOOKS_PER_CLIENT
400394
));
401395
assert_eq!(error, error_to_check);
402396
assert_eq!(app_name, one_too_many);

0 commit comments

Comments
 (0)