Skip to content

[LSPS5] Change notification dooldown time to 1 minute, alsp update docs #3994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning-liquidity/src/lsps5/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
22 changes: 11 additions & 11 deletions lightning-liquidity/src/lsps5/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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> {
Expand All @@ -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> {
Expand All @@ -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> {
Expand Down Expand Up @@ -429,7 +429,7 @@ where
.last_notification_sent
.get(&notification.method)
.map(|last_sent| now.duration_since(&last_sent))
.map_or(false, |duration| duration < DEFAULT_NOTIFICATION_COOLDOWN_HOURS)
.map_or(false, |duration: Duration| duration < NOTIFICATION_COOLDOWN_TIME)
});

if rate_limit_applies {
Expand Down
4 changes: 2 additions & 2 deletions lightning-liquidity/tests/lsps5_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
Loading