@@ -411,11 +411,13 @@ fn webhook_error_handling_test() {
411
411
412
412
#[ test]
413
413
fn webhook_notification_delivery_test ( ) {
414
+ let mock_time_provider = Arc :: new ( MockTimeProvider :: new ( 1000 ) ) ;
415
+ let time_provider = Arc :: < MockTimeProvider > :: clone ( & mock_time_provider) ;
414
416
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
415
417
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
416
418
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
417
419
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
418
- let ( lsps_nodes, validator) = lsps5_test_setup ( nodes, Arc :: new ( DefaultTimeProvider ) ) ;
420
+ let ( lsps_nodes, validator) = lsps5_test_setup ( nodes, time_provider ) ;
419
421
let LSPSNodes { service_node, client_node } = lsps_nodes;
420
422
let service_node_id = service_node. inner . node . get_our_node_id ( ) ;
421
423
let client_node_id = client_node. inner . node . get_our_node_id ( ) ;
@@ -499,6 +501,8 @@ fn webhook_notification_delivery_test() {
499
501
"No event should be emitted due to cooldown"
500
502
) ;
501
503
504
+ mock_time_provider. advance_time ( NOTIFICATION_COOLDOWN_TIME . as_secs ( ) + 1 ) ;
505
+
502
506
let timeout_block = 700000 ; // Some future block height
503
507
let _ = service_handler. notify_expiry_soon ( client_node_id, timeout_block) ;
504
508
@@ -719,11 +723,13 @@ fn idempotency_set_webhook_test() {
719
723
720
724
#[ test]
721
725
fn replay_prevention_test ( ) {
726
+ let mock_time_provider = Arc :: new ( MockTimeProvider :: new ( 1000 ) ) ;
727
+ let time_provider = Arc :: < MockTimeProvider > :: clone ( & mock_time_provider) ;
722
728
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
723
729
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
724
730
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
725
731
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
726
- let ( lsps_nodes, validator) = lsps5_test_setup ( nodes, Arc :: new ( DefaultTimeProvider ) ) ;
732
+ let ( lsps_nodes, validator) = lsps5_test_setup ( nodes, time_provider ) ;
727
733
let LSPSNodes { service_node, client_node } = lsps_nodes;
728
734
let service_node_id = service_node. inner . node . get_our_node_id ( ) ;
729
735
let client_node_id = client_node. inner . node . get_our_node_id ( ) ;
@@ -774,6 +780,9 @@ fn replay_prevention_test() {
774
780
775
781
// Fill up the validator's signature cache to push out the original signature.
776
782
for i in 0 ..MAX_RECENT_SIGNATURES {
783
+ // Advance time, allowing for another notification
784
+ mock_time_provider. advance_time ( NOTIFICATION_COOLDOWN_TIME . as_secs ( ) + 1 ) ;
785
+
777
786
let timeout_block = 700000 + i as u32 ;
778
787
let _ = service_handler. notify_expiry_soon ( client_node_id, timeout_block) ;
779
788
let event = service_node. liquidity_manager . next_event ( ) . unwrap ( ) ;
@@ -871,11 +880,13 @@ fn stale_webhooks() {
871
880
872
881
#[ test]
873
882
fn test_all_notifications ( ) {
883
+ let mock_time_provider = Arc :: new ( MockTimeProvider :: new ( 1000 ) ) ;
884
+ let time_provider = Arc :: < MockTimeProvider > :: clone ( & mock_time_provider) ;
874
885
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
875
886
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
876
887
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
877
888
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
878
- let ( lsps_nodes, validator) = lsps5_test_setup ( nodes, Arc :: new ( DefaultTimeProvider ) ) ;
889
+ let ( lsps_nodes, validator) = lsps5_test_setup ( nodes, time_provider ) ;
879
890
let LSPSNodes { service_node, client_node } = lsps_nodes;
880
891
let service_node_id = service_node. inner . node . get_our_node_id ( ) ;
881
892
let client_node_id = client_node. inner . node . get_our_node_id ( ) ;
@@ -894,9 +905,16 @@ fn test_all_notifications() {
894
905
// consume initial SendWebhookNotification
895
906
let _ = service_node. liquidity_manager . next_event ( ) . unwrap ( ) ;
896
907
908
+ mock_time_provider. advance_time ( NOTIFICATION_COOLDOWN_TIME . as_secs ( ) + 1 ) ;
897
909
let _ = service_handler. notify_onion_message_incoming ( client_node_id) ;
910
+
911
+ mock_time_provider. advance_time ( NOTIFICATION_COOLDOWN_TIME . as_secs ( ) + 1 ) ;
898
912
let _ = service_handler. notify_payment_incoming ( client_node_id) ;
913
+
914
+ mock_time_provider. advance_time ( NOTIFICATION_COOLDOWN_TIME . as_secs ( ) + 1 ) ;
899
915
let _ = service_handler. notify_expiry_soon ( client_node_id, 1000 ) ;
916
+
917
+ mock_time_provider. advance_time ( NOTIFICATION_COOLDOWN_TIME . as_secs ( ) + 1 ) ;
900
918
let _ = service_handler. notify_liquidity_management_request ( client_node_id) ;
901
919
902
920
let expected_notifications = vec ! [
@@ -1101,24 +1119,7 @@ fn test_send_notifications_and_peer_connected_resets_cooldown() {
1101
1119
"Should not emit event due to cooldown"
1102
1120
) ;
1103
1121
1104
- // 3. Notification of a different method CAN be sent
1105
- let timeout_block = 424242 ;
1106
- let _ = service_handler. notify_expiry_soon ( client_node_id, timeout_block) ;
1107
- let event = service_node. liquidity_manager . next_event ( ) . unwrap ( ) ;
1108
- match event {
1109
- LiquidityEvent :: LSPS5Service ( LSPS5ServiceEvent :: SendWebhookNotification {
1110
- notification,
1111
- ..
1112
- } ) => {
1113
- assert ! ( matches!(
1114
- notification. method,
1115
- WebhookNotificationMethod :: LSPS5ExpirySoon { timeout } if timeout == timeout_block
1116
- ) ) ;
1117
- } ,
1118
- _ => panic ! ( "Expected SendWebhookNotification event for expiry_soon" ) ,
1119
- }
1120
-
1121
- // 4. Advance time past cooldown and ensure payment_incoming can be sent again
1122
+ // 3. Advance time past cooldown and ensure payment_incoming can be sent again
1122
1123
mock_time_provider. advance_time ( NOTIFICATION_COOLDOWN_TIME . as_secs ( ) + 1 ) ;
1123
1124
1124
1125
let _ = service_handler. notify_payment_incoming ( client_node_id) ;
@@ -1133,7 +1134,7 @@ fn test_send_notifications_and_peer_connected_resets_cooldown() {
1133
1134
_ => panic ! ( "Expected SendWebhookNotification event after cooldown" ) ,
1134
1135
}
1135
1136
1136
- // 5 . Can't send payment_incoming notification again immediately after cooldown
1137
+ // 4 . Can't send payment_incoming notification again immediately after cooldown
1137
1138
let result = service_handler. notify_payment_incoming ( client_node_id) ;
1138
1139
1139
1140
let error = result. unwrap_err ( ) ;
@@ -1144,7 +1145,7 @@ fn test_send_notifications_and_peer_connected_resets_cooldown() {
1144
1145
"Should not emit event due to cooldown"
1145
1146
) ;
1146
1147
1147
- // 6 . After peer_connected, notification should be sent again immediately
1148
+ // 5 . After peer_connected, notification should be sent again immediately
1148
1149
let init_msg = Init {
1149
1150
features : lightning_types:: features:: InitFeatures :: empty ( ) ,
1150
1151
remote_network_address : None ,
0 commit comments