Skip to content

Commit 121dc04

Browse files
fixup: fix comment on msgs, don't check for rate_limit on webhook_registered notif
1 parent a4a560b commit 121dc04

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

lightning-liquidity/src/lsps5/msgs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub enum LSPS5ProtocolError {
116116
}
117117

118118
impl LSPS5ProtocolError {
119-
/// private code range so we never collide with the spec's codes
119+
/// The error code for the LSPS5 protocol error.
120120
pub fn code(&self) -> i32 {
121121
match self {
122122
LSPS5ProtocolError::AppNameTooLong | LSPS5ProtocolError::WebhookUrlTooLong => {

lightning-liquidity/src/lsps5/service.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,23 @@ where
221221
}
222222

223223
if !no_change {
224-
let result = self.send_webhook_registered_notification(
224+
self.send_webhook_registered_notification(
225225
counterparty_node_id,
226226
params.app_name,
227227
params.webhook,
228-
);
229-
230-
// If the send_notification failed because of a SLOW_DOWN_ERROR, it means we sent this
231-
// notification recently, and the user has not seen it yet. It's safe to continue, but we still need to handle other error types.
232-
if result.is_err() && !matches!(result, Err(LSPS5ProtocolError::SlowDownError)) {
233-
let e = result.unwrap_err();
228+
)
229+
.map_err(|e| {
234230
let msg = LSPS5Message::Response(
235231
request_id.clone(),
236232
LSPS5Response::SetWebhookError(e.clone().into()),
237233
)
238234
.into();
239235
self.pending_messages.enqueue(&counterparty_node_id, msg);
240-
return Err(LightningError {
236+
LightningError {
241237
err: e.message().into(),
242238
action: ErrorAction::IgnoreAndLog(Level::Info),
243-
});
244-
}
239+
}
240+
})?;
245241
}
246242

247243
let msg = LSPS5Message::Response(
@@ -419,16 +415,22 @@ where
419415
let now =
420416
LSPSDateTime::new_from_duration_since_epoch(self.time_provider.duration_since_epoch());
421417

422-
let rate_limit_applies = client_webhooks.iter().any(|(_, webhook)| {
423-
webhook
424-
.last_notification_sent
425-
.get(&notification.method)
426-
.map(|last_sent| now.abs_diff(&last_sent))
427-
.map_or(false, |duration| duration < DEFAULT_NOTIFICATION_COOLDOWN_HOURS.as_secs())
428-
});
429-
430-
if rate_limit_applies {
431-
return Err(LSPS5ProtocolError::SlowDownError);
418+
// We must avoid sending multiple notifications of the same method
419+
// (other than lsps5.webhook_registered) close in time.
420+
if notification.method != WebhookNotificationMethod::LSPS5WebhookRegistered {
421+
let rate_limit_applies = client_webhooks.iter().any(|(_, webhook)| {
422+
webhook
423+
.last_notification_sent
424+
.get(&notification.method)
425+
.map(|last_sent| now.abs_diff(&last_sent))
426+
.map_or(false, |duration| {
427+
duration < DEFAULT_NOTIFICATION_COOLDOWN_HOURS.as_secs()
428+
})
429+
});
430+
431+
if rate_limit_applies {
432+
return Err(LSPS5ProtocolError::SlowDownError);
433+
}
432434
}
433435

434436
for (app_name, webhook) in client_webhooks.iter_mut() {

0 commit comments

Comments
 (0)