@@ -832,8 +832,7 @@ where
832
832
let mut have_pruned = false ;
833
833
let mut have_decayed_scorer = false ;
834
834
835
- let mut cur_batch_delay = batch_delay. get ( ) ;
836
- let mut last_forwards_processing_call = sleeper ( cur_batch_delay) ;
835
+ let mut last_forwards_processing_call = sleeper ( batch_delay. get ( ) ) ;
837
836
838
837
loop {
839
838
channel_manager. get_cm ( ) . process_pending_events_async ( async_event_handler) . await ;
@@ -854,11 +853,11 @@ where
854
853
// generally, and as a fallback place such blocking only immediately before
855
854
// persistence.
856
855
peer_manager. as_ref ( ) . process_events ( ) ;
857
- match check_sleeper ( & mut last_forwards_processing_call) {
856
+ match check_and_reset_sleeper ( & mut last_forwards_processing_call, || {
857
+ sleeper ( batch_delay. next ( ) )
858
+ } ) {
858
859
Some ( false ) => {
859
860
channel_manager. get_cm ( ) . process_pending_htlc_forwards ( ) ;
860
- cur_batch_delay = batch_delay. next ( ) ;
861
- last_forwards_processing_call = sleeper ( cur_batch_delay) ;
862
861
} ,
863
862
Some ( true ) => break ,
864
863
None => { } ,
@@ -906,19 +905,20 @@ where
906
905
}
907
906
908
907
let await_slow = if mobile_interruptable_platform {
909
- match check_sleeper ( & mut await_start. unwrap ( ) ) {
908
+ // Specify a zero new sleeper timeout because we won't use the new sleeper. It is re-initialized in the next
909
+ // loop iteration.
910
+ match check_and_reset_sleeper ( & mut await_start. unwrap ( ) , || sleeper ( Duration :: ZERO ) ) {
910
911
Some ( true ) => break ,
911
912
Some ( false ) => true ,
912
913
None => false ,
913
914
}
914
915
} else {
915
916
false
916
917
} ;
917
- match check_sleeper ( & mut last_freshness_call) {
918
+ match check_and_reset_sleeper ( & mut last_freshness_call, || sleeper ( FRESHNESS_TIMER ) ) {
918
919
Some ( false ) => {
919
920
log_trace ! ( logger, "Calling ChannelManager's timer_tick_occurred" ) ;
920
921
channel_manager. get_cm ( ) . timer_tick_occurred ( ) ;
921
- last_freshness_call = sleeper ( FRESHNESS_TIMER ) ;
922
922
} ,
923
923
Some ( true ) => break ,
924
924
None => { } ,
@@ -963,8 +963,13 @@ where
963
963
// pruning their network graph. We run once 60 seconds after startup before
964
964
// continuing our normal cadence. For RGS, since 60 seconds is likely too long,
965
965
// we prune after an initial sync completes.
966
+ let prune_timer = if gossip_sync. prunable_network_graph ( ) . is_some ( ) {
967
+ NETWORK_PRUNE_TIMER
968
+ } else {
969
+ FIRST_NETWORK_PRUNE_TIMER
970
+ } ;
966
971
let prune_timer_elapsed = {
967
- match check_sleeper ( & mut last_prune_call) {
972
+ match check_and_reset_sleeper ( & mut last_prune_call, || sleeper ( prune_timer ) ) {
968
973
Some ( false ) => true ,
969
974
Some ( true ) => break ,
970
975
None => false ,
@@ -1008,9 +1013,6 @@ where
1008
1013
1009
1014
have_pruned = true ;
1010
1015
}
1011
- let prune_timer =
1012
- if have_pruned { NETWORK_PRUNE_TIMER } else { FIRST_NETWORK_PRUNE_TIMER } ;
1013
- last_prune_call = sleeper ( prune_timer) ;
1014
1016
}
1015
1017
if !have_decayed_scorer {
1016
1018
if let Some ( ref scorer) = scorer {
@@ -1021,7 +1023,9 @@ where
1021
1023
}
1022
1024
have_decayed_scorer = true ;
1023
1025
}
1024
- match check_sleeper ( & mut last_scorer_persist_call) {
1026
+ match check_and_reset_sleeper ( & mut last_scorer_persist_call, || {
1027
+ sleeper ( SCORER_PERSIST_TIMER )
1028
+ } ) {
1025
1029
Some ( false ) => {
1026
1030
if let Some ( ref scorer) = scorer {
1027
1031
if let Some ( duration_since_epoch) = fetch_time ( ) {
@@ -1053,12 +1057,11 @@ where
1053
1057
// TODO: Once our MSRV is 1.68 we should be able to drop the Box
1054
1058
futures. set_c ( Box :: pin ( fut) ) ;
1055
1059
}
1056
- last_scorer_persist_call = sleeper ( SCORER_PERSIST_TIMER ) ;
1057
1060
} ,
1058
1061
Some ( true ) => break ,
1059
1062
None => { } ,
1060
1063
}
1061
- match check_sleeper ( & mut last_sweeper_call) {
1064
+ match check_and_reset_sleeper ( & mut last_sweeper_call, || sleeper ( SWEEPER_TIMER ) ) {
1062
1065
Some ( false ) => {
1063
1066
log_trace ! ( logger, "Regenerating sweeper spends if necessary" ) ;
1064
1067
if let Some ( ref sweeper) = sweeper {
@@ -1071,7 +1074,6 @@ where
1071
1074
// TODO: Once our MSRV is 1.68 we should be able to drop the Box
1072
1075
futures. set_d ( Box :: pin ( fut) ) ;
1073
1076
}
1074
- last_sweeper_call = sleeper ( SWEEPER_TIMER ) ;
1075
1077
} ,
1076
1078
Some ( true ) => break ,
1077
1079
None => { } ,
@@ -1082,13 +1084,14 @@ where
1082
1084
res?;
1083
1085
}
1084
1086
1085
- match check_sleeper ( & mut last_onion_message_handler_call) {
1087
+ match check_and_reset_sleeper ( & mut last_onion_message_handler_call, || {
1088
+ sleeper ( ONION_MESSAGE_HANDLER_TIMER )
1089
+ } ) {
1086
1090
Some ( false ) => {
1087
1091
if let Some ( om) = & onion_messenger {
1088
1092
log_trace ! ( logger, "Calling OnionMessageHandler's timer_tick_occurred" ) ;
1089
1093
om. get_om ( ) . timer_tick_occurred ( ) ;
1090
1094
}
1091
- last_onion_message_handler_call = sleeper ( ONION_MESSAGE_HANDLER_TIMER ) ;
1092
1095
} ,
1093
1096
Some ( true ) => break ,
1094
1097
None => { } ,
@@ -1112,23 +1115,21 @@ where
1112
1115
peer_manager. as_ref ( ) . disconnect_all_peers ( ) ;
1113
1116
last_ping_call = sleeper ( PING_TIMER ) ;
1114
1117
} else {
1115
- match check_sleeper ( & mut last_ping_call) {
1118
+ match check_and_reset_sleeper ( & mut last_ping_call, || sleeper ( PING_TIMER ) ) {
1116
1119
Some ( false ) => {
1117
1120
log_trace ! ( logger, "Calling PeerManager's timer_tick_occurred" ) ;
1118
1121
peer_manager. as_ref ( ) . timer_tick_occurred ( ) ;
1119
- last_ping_call = sleeper ( PING_TIMER ) ;
1120
1122
} ,
1121
1123
Some ( true ) => break ,
1122
1124
_ => { } ,
1123
1125
}
1124
1126
}
1125
1127
1126
1128
// Rebroadcast pending claims.
1127
- match check_sleeper ( & mut last_rebroadcast_call) {
1129
+ match check_and_reset_sleeper ( & mut last_rebroadcast_call, || sleeper ( REBROADCAST_TIMER ) ) {
1128
1130
Some ( false ) => {
1129
1131
log_trace ! ( logger, "Rebroadcasting monitor's pending claims" ) ;
1130
1132
chain_monitor. rebroadcast_pending_claims ( ) ;
1131
- last_rebroadcast_call = sleeper ( REBROADCAST_TIMER ) ;
1132
1133
} ,
1133
1134
Some ( true ) => break ,
1134
1135
None => { } ,
@@ -1170,13 +1171,18 @@ where
1170
1171
Ok ( ( ) )
1171
1172
}
1172
1173
1173
- fn check_sleeper < SleepFuture : core:: future:: Future < Output = bool > + core:: marker:: Unpin > (
1174
- fut : & mut SleepFuture ,
1174
+ fn check_and_reset_sleeper <
1175
+ SleepFuture : core:: future:: Future < Output = bool > + core:: marker:: Unpin ,
1176
+ > (
1177
+ fut : & mut SleepFuture , mut new_sleeper : impl FnMut ( ) -> SleepFuture ,
1175
1178
) -> Option < bool > {
1176
1179
let mut waker = dummy_waker ( ) ;
1177
1180
let mut ctx = task:: Context :: from_waker ( & mut waker) ;
1178
- match core:: pin:: Pin :: new ( fut) . poll ( & mut ctx) {
1179
- task:: Poll :: Ready ( exit) => Some ( exit) ,
1181
+ match core:: pin:: Pin :: new ( & mut * fut) . poll ( & mut ctx) {
1182
+ task:: Poll :: Ready ( exit) => {
1183
+ * fut = new_sleeper ( ) ;
1184
+ Some ( exit)
1185
+ } ,
1180
1186
task:: Poll :: Pending => None ,
1181
1187
}
1182
1188
}
@@ -1502,7 +1508,7 @@ impl BackgroundProcessor {
1502
1508
NETWORK_GRAPH_PERSISTENCE_KEY ,
1503
1509
& network_graph. encode ( ) ,
1504
1510
) {
1505
- log_error ! ( logger, "Error: Failed to persist network graph, check your disk and permissions {}" , e) ;
1511
+ log_error ! ( logger, "Error: Failed to persist network graph, check your disk and permissions {}" , e) ;
1506
1512
}
1507
1513
have_pruned = true ;
1508
1514
}
@@ -1531,10 +1537,7 @@ impl BackgroundProcessor {
1531
1537
SCORER_PERSISTENCE_KEY ,
1532
1538
& scorer. encode ( ) ,
1533
1539
) {
1534
- log_error ! ( logger,
1535
- "Error: Failed to persist scorer, check your disk and permissions {}" ,
1536
- e,
1537
- ) ;
1540
+ log_error ! ( logger, "Error: Failed to persist scorer, check your disk and permissions {}" , e) ;
1538
1541
}
1539
1542
}
1540
1543
last_scorer_persist_call = Instant :: now ( ) ;
0 commit comments