Skip to content

Commit f30f85b

Browse files
fixup: addressing comments, details below:
- notification_cooldown_hours is not configurable anymore - revert duration rename to last_sent so it's clearer - add comments on last_used and last_notification_sent to clarify its purpose
1 parent 60cedd3 commit f30f85b

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lightning-liquidity/src/lsps5/service.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ struct StoredWebhook {
5151
_app_name: LSPS5AppName,
5252
url: LSPS5WebhookUrl,
5353
_counterparty_node_id: PublicKey,
54+
// Timestamp used for tracking when the webhook was created / updated, or when the last notification was sent.
55+
// This is used to determine if the webhook is stale and should be pruned.
5456
last_used: LSPSDateTime,
57+
// Map of last notification sent timestamps for each notification method.
58+
// This is used to enforce notification cooldowns.
5559
last_notification_sent: HashMap<WebhookNotificationMethod, LSPSDateTime>,
5660
}
5761

@@ -60,8 +64,6 @@ struct StoredWebhook {
6064
pub struct LSPS5ServiceConfig {
6165
/// Maximum number of webhooks allowed per client.
6266
pub max_webhooks_per_client: u32,
63-
/// Minimum time between sending the same notification type in hours (default: 24)
64-
pub notification_cooldown_hours: Duration,
6567
}
6668

6769
/// Default maximum number of webhooks allowed per client.
@@ -72,10 +74,7 @@ pub const DEFAULT_NOTIFICATION_COOLDOWN_HOURS: Duration = Duration::from_secs(60
7274
// Default configuration for LSPS5 service.
7375
impl Default for LSPS5ServiceConfig {
7476
fn default() -> Self {
75-
Self {
76-
max_webhooks_per_client: DEFAULT_MAX_WEBHOOKS_PER_CLIENT,
77-
notification_cooldown_hours: DEFAULT_NOTIFICATION_COOLDOWN_HOURS,
78-
}
77+
Self { max_webhooks_per_client: DEFAULT_MAX_WEBHOOKS_PER_CLIENT }
7978
}
8079
}
8180

@@ -408,9 +407,8 @@ where
408407
.last_notification_sent
409408
.get(&notification.method)
410409
.map(|last_sent| now.clone().abs_diff(&last_sent))
411-
.map_or(true, |last_sent| {
412-
last_sent >= self.config.notification_cooldown_hours.as_secs()
413-
}) {
410+
.map_or(true, |duration| duration >= DEFAULT_NOTIFICATION_COOLDOWN_HOURS.as_secs())
411+
{
414412
webhook.last_notification_sent.insert(notification.method.clone(), now.clone());
415413
webhook.last_used = now.clone();
416414
self.send_notification(

0 commit comments

Comments
 (0)