@@ -221,27 +221,23 @@ where
221
221
}
222
222
223
223
if !no_change {
224
- let result = self . send_webhook_registered_notification (
224
+ self . send_webhook_registered_notification (
225
225
counterparty_node_id,
226
226
params. app_name ,
227
227
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| {
234
230
let msg = LSPS5Message :: Response (
235
231
request_id. clone ( ) ,
236
232
LSPS5Response :: SetWebhookError ( e. clone ( ) . into ( ) ) ,
237
233
)
238
234
. into ( ) ;
239
235
self . pending_messages . enqueue ( & counterparty_node_id, msg) ;
240
- return Err ( LightningError {
236
+ LightningError {
241
237
err : e. message ( ) . into ( ) ,
242
238
action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
243
- } ) ;
244
- }
239
+ }
240
+ } ) ? ;
245
241
}
246
242
247
243
let msg = LSPS5Message :: Response (
@@ -419,16 +415,22 @@ where
419
415
let now =
420
416
LSPSDateTime :: new_from_duration_since_epoch ( self . time_provider . duration_since_epoch ( ) ) ;
421
417
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
+ }
432
434
}
433
435
434
436
for ( app_name, webhook) in client_webhooks. iter_mut ( ) {
0 commit comments