From c7694f41cbd54e672063320e00e5e8f5f1579229 Mon Sep 17 00:00:00 2001 From: Martin Saposnic Date: Thu, 7 Aug 2025 11:27:18 -0300 Subject: [PATCH] [LSPS5] Change notification cooldown time to 1 minute, also update docs. --- lightning-liquidity/src/lsps5/msgs.rs | 4 ++-- lightning-liquidity/src/lsps5/service.rs | 22 +++++++++---------- .../tests/lsps5_integration_tests.rs | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lightning-liquidity/src/lsps5/msgs.rs b/lightning-liquidity/src/lsps5/msgs.rs index c61bc2b982d..ada1f263e03 100644 --- a/lightning-liquidity/src/lsps5/msgs.rs +++ b/lightning-liquidity/src/lsps5/msgs.rs @@ -109,9 +109,9 @@ pub enum LSPS5ProtocolError { /// A notification was sent too frequently. /// /// This error indicates that the LSP is sending notifications - /// too quickly, violating the notification cooldown [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`] + /// too quickly, violating the notification cooldown [`NOTIFICATION_COOLDOWN_TIME`] /// - /// [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`]: super::service::DEFAULT_NOTIFICATION_COOLDOWN_HOURS + /// [`NOTIFICATION_COOLDOWN_TIME`]: super::service::NOTIFICATION_COOLDOWN_TIME SlowDownError, } diff --git a/lightning-liquidity/src/lsps5/service.rs b/lightning-liquidity/src/lsps5/service.rs index e0fb3ab442a..2b86ad3ac08 100644 --- a/lightning-liquidity/src/lsps5/service.rs +++ b/lightning-liquidity/src/lsps5/service.rs @@ -68,8 +68,8 @@ pub struct LSPS5ServiceConfig { /// Default maximum number of webhooks allowed per client. pub const DEFAULT_MAX_WEBHOOKS_PER_CLIENT: u32 = 10; -/// Default notification cooldown time in hours. -pub const DEFAULT_NOTIFICATION_COOLDOWN_HOURS: Duration = Duration::from_secs(60 * 60); // 1 hour +/// Default notification cooldown time in minutes. +pub const NOTIFICATION_COOLDOWN_TIME: Duration = Duration::from_secs(60); // 1 minute // Default configuration for LSPS5 service. impl Default for LSPS5ServiceConfig { @@ -330,13 +330,13 @@ where /// node key, and enqueues HTTP POSTs to all registered webhook URLs for that client. /// /// This may fail if a similar notification was sent too recently, - /// violating the notification cooldown period defined in [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`]. + /// violating the notification cooldown period defined in [`NOTIFICATION_COOLDOWN_TIME`]. /// /// # Parameters /// - `client_id`: the client's node-ID whose webhooks should be invoked. /// /// [`WebhookNotificationMethod::LSPS5PaymentIncoming`]: super::msgs::WebhookNotificationMethod::LSPS5PaymentIncoming - /// [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`]: super::service::DEFAULT_NOTIFICATION_COOLDOWN_HOURS + /// [`NOTIFICATION_COOLDOWN_TIME`]: super::service::NOTIFICATION_COOLDOWN_TIME pub fn notify_payment_incoming(&self, client_id: PublicKey) -> Result<(), LSPS5ProtocolError> { let notification = WebhookNotification::payment_incoming(); self.send_notifications_to_client_webhooks(client_id, notification) @@ -351,14 +351,14 @@ where /// registered webhooks. /// /// This may fail if a similar notification was sent too recently, - /// violating the notification cooldown period defined in [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`]. + /// violating the notification cooldown period defined in [`NOTIFICATION_COOLDOWN_TIME`]. /// /// # Parameters /// - `client_id`: the client's node-ID whose webhooks should be invoked. /// - `timeout`: the block height at which the channel contract will expire. /// /// [`WebhookNotificationMethod::LSPS5ExpirySoon`]: super::msgs::WebhookNotificationMethod::LSPS5ExpirySoon - /// [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`]: super::service::DEFAULT_NOTIFICATION_COOLDOWN_HOURS + /// [`NOTIFICATION_COOLDOWN_TIME`]: super::service::NOTIFICATION_COOLDOWN_TIME pub fn notify_expiry_soon( &self, client_id: PublicKey, timeout: u32, ) -> Result<(), LSPS5ProtocolError> { @@ -373,13 +373,13 @@ where /// signs it, and sends it to all of the client's registered webhook URLs. /// /// This may fail if a similar notification was sent too recently, - /// violating the notification cooldown period defined in [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`]. + /// violating the notification cooldown period defined in [`NOTIFICATION_COOLDOWN_TIME`]. /// /// # Parameters /// - `client_id`: the client's node-ID whose webhooks should be invoked. /// /// [`WebhookNotificationMethod::LSPS5LiquidityManagementRequest`]: super::msgs::WebhookNotificationMethod::LSPS5LiquidityManagementRequest - /// [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`]: super::service::DEFAULT_NOTIFICATION_COOLDOWN_HOURS + /// [`NOTIFICATION_COOLDOWN_TIME`]: super::service::NOTIFICATION_COOLDOWN_TIME pub fn notify_liquidity_management_request( &self, client_id: PublicKey, ) -> Result<(), LSPS5ProtocolError> { @@ -394,13 +394,13 @@ where /// notification, signs it, and enqueues HTTP POSTs to each registered webhook. /// /// This may fail if a similar notification was sent too recently, - /// violating the notification cooldown period defined in [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`]. + /// violating the notification cooldown period defined in [`NOTIFICATION_COOLDOWN_TIME`]. /// /// # Parameters /// - `client_id`: the client's node-ID whose webhooks should be invoked. /// /// [`WebhookNotificationMethod::LSPS5OnionMessageIncoming`]: super::msgs::WebhookNotificationMethod::LSPS5OnionMessageIncoming - /// [`DEFAULT_NOTIFICATION_COOLDOWN_HOURS`]: super::service::DEFAULT_NOTIFICATION_COOLDOWN_HOURS + /// [`NOTIFICATION_COOLDOWN_TIME`]: super::service::NOTIFICATION_COOLDOWN_TIME pub fn notify_onion_message_incoming( &self, client_id: PublicKey, ) -> Result<(), LSPS5ProtocolError> { @@ -429,7 +429,7 @@ where .last_notification_sent .get(¬ification.method) .map(|last_sent| now.duration_since(&last_sent)) - .map_or(false, |duration| duration < DEFAULT_NOTIFICATION_COOLDOWN_HOURS) + .map_or(false, |duration| duration < NOTIFICATION_COOLDOWN_TIME) }); if rate_limit_applies { diff --git a/lightning-liquidity/tests/lsps5_integration_tests.rs b/lightning-liquidity/tests/lsps5_integration_tests.rs index 61e7c12f95b..9035755e89a 100644 --- a/lightning-liquidity/tests/lsps5_integration_tests.rs +++ b/lightning-liquidity/tests/lsps5_integration_tests.rs @@ -19,7 +19,7 @@ use lightning_liquidity::lsps5::msgs::{ WebhookNotificationMethod, }; use lightning_liquidity::lsps5::service::{ - LSPS5ServiceConfig, DEFAULT_MAX_WEBHOOKS_PER_CLIENT, DEFAULT_NOTIFICATION_COOLDOWN_HOURS, + LSPS5ServiceConfig, DEFAULT_MAX_WEBHOOKS_PER_CLIENT, NOTIFICATION_COOLDOWN_TIME, }; use lightning_liquidity::lsps5::service::{ MIN_WEBHOOK_RETENTION_DAYS, PRUNE_STALE_WEBHOOKS_INTERVAL_DAYS, @@ -1119,7 +1119,7 @@ fn test_send_notifications_and_peer_connected_resets_cooldown() { } // 4. Advance time past cooldown and ensure payment_incoming can be sent again - mock_time_provider.advance_time(DEFAULT_NOTIFICATION_COOLDOWN_HOURS.as_secs() + 1); + mock_time_provider.advance_time(NOTIFICATION_COOLDOWN_TIME.as_secs() + 1); let _ = service_handler.notify_payment_incoming(client_node_id); let event = service_node.liquidity_manager.next_event().unwrap();