@@ -829,8 +829,7 @@ where
829
829
let mut have_pruned = false ;
830
830
let mut have_decayed_scorer = false ;
831
831
832
- let mut cur_batch_delay = batch_delay. get ( ) ;
833
- let mut last_forwards_processing_call = sleeper ( cur_batch_delay) ;
832
+ let mut last_forwards_processing_call = sleeper ( batch_delay. get ( ) ) ;
834
833
835
834
loop {
836
835
channel_manager. get_cm ( ) . process_pending_events_async ( async_event_handler) . await ;
@@ -851,11 +850,11 @@ where
851
850
// generally, and as a fallback place such blocking only immediately before
852
851
// persistence.
853
852
peer_manager. as_ref ( ) . process_events ( ) ;
854
- match check_sleeper ( & mut last_forwards_processing_call) {
853
+ match check_and_reset_sleeper ( & mut last_forwards_processing_call, || {
854
+ sleeper ( batch_delay. next ( ) )
855
+ } ) {
855
856
Some ( false ) => {
856
857
channel_manager. get_cm ( ) . process_pending_htlc_forwards ( ) ;
857
- cur_batch_delay = batch_delay. next ( ) ;
858
- last_forwards_processing_call = sleeper ( cur_batch_delay) ;
859
858
} ,
860
859
Some ( true ) => break ,
861
860
None => { } ,
@@ -903,19 +902,20 @@ where
903
902
}
904
903
905
904
let await_slow = if mobile_interruptable_platform {
906
- match check_sleeper ( & mut await_start. unwrap ( ) ) {
905
+ // Specify a zero new sleeper timeout because we won't use the new sleeper. It is re-initialized in the next
906
+ // loop iteration.
907
+ match check_and_reset_sleeper ( & mut await_start. unwrap ( ) , || sleeper ( Duration :: ZERO ) ) {
907
908
Some ( true ) => break ,
908
909
Some ( false ) => true ,
909
910
None => false ,
910
911
}
911
912
} else {
912
913
false
913
914
} ;
914
- match check_sleeper ( & mut last_freshness_call) {
915
+ match check_and_reset_sleeper ( & mut last_freshness_call, || sleeper ( FRESHNESS_TIMER ) ) {
915
916
Some ( false ) => {
916
917
log_trace ! ( logger, "Calling ChannelManager's timer_tick_occurred" ) ;
917
918
channel_manager. get_cm ( ) . timer_tick_occurred ( ) ;
918
- last_freshness_call = sleeper ( FRESHNESS_TIMER ) ;
919
919
} ,
920
920
Some ( true ) => break ,
921
921
None => { } ,
@@ -947,8 +947,13 @@ where
947
947
// pruning their network graph. We run once 60 seconds after startup before
948
948
// continuing our normal cadence. For RGS, since 60 seconds is likely too long,
949
949
// we prune after an initial sync completes.
950
+ let prune_timer = if gossip_sync. prunable_network_graph ( ) . is_some ( ) {
951
+ NETWORK_PRUNE_TIMER
952
+ } else {
953
+ FIRST_NETWORK_PRUNE_TIMER
954
+ } ;
950
955
let prune_timer_elapsed = {
951
- match check_sleeper ( & mut last_prune_call) {
956
+ match check_and_reset_sleeper ( & mut last_prune_call, || sleeper ( prune_timer ) ) {
952
957
Some ( false ) => true ,
953
958
Some ( true ) => break ,
954
959
None => false ,
@@ -992,9 +997,6 @@ where
992
997
993
998
have_pruned = true ;
994
999
}
995
- let prune_timer =
996
- if have_pruned { NETWORK_PRUNE_TIMER } else { FIRST_NETWORK_PRUNE_TIMER } ;
997
- last_prune_call = sleeper ( prune_timer) ;
998
1000
}
999
1001
if !have_decayed_scorer {
1000
1002
if let Some ( ref scorer) = scorer {
@@ -1005,7 +1007,9 @@ where
1005
1007
}
1006
1008
have_decayed_scorer = true ;
1007
1009
}
1008
- match check_sleeper ( & mut last_scorer_persist_call) {
1010
+ match check_and_reset_sleeper ( & mut last_scorer_persist_call, || {
1011
+ sleeper ( SCORER_PERSIST_TIMER )
1012
+ } ) {
1009
1013
Some ( false ) => {
1010
1014
if let Some ( ref scorer) = scorer {
1011
1015
if let Some ( duration_since_epoch) = fetch_time ( ) {
@@ -1037,12 +1041,11 @@ where
1037
1041
// TODO: Once our MSRV is 1.68 we should be able to drop the Box
1038
1042
futures. set_c ( Box :: pin ( fut) ) ;
1039
1043
}
1040
- last_scorer_persist_call = sleeper ( SCORER_PERSIST_TIMER ) ;
1041
1044
} ,
1042
1045
Some ( true ) => break ,
1043
1046
None => { } ,
1044
1047
}
1045
- match check_sleeper ( & mut last_sweeper_call) {
1048
+ match check_and_reset_sleeper ( & mut last_sweeper_call, || sleeper ( SWEEPER_TIMER ) ) {
1046
1049
Some ( false ) => {
1047
1050
log_trace ! ( logger, "Regenerating sweeper spends if necessary" ) ;
1048
1051
if let Some ( ref sweeper) = sweeper {
@@ -1055,7 +1058,6 @@ where
1055
1058
// TODO: Once our MSRV is 1.68 we should be able to drop the Box
1056
1059
futures. set_d ( Box :: pin ( fut) ) ;
1057
1060
}
1058
- last_sweeper_call = sleeper ( SWEEPER_TIMER ) ;
1059
1061
} ,
1060
1062
Some ( true ) => break ,
1061
1063
None => { } ,
@@ -1066,13 +1068,14 @@ where
1066
1068
res?;
1067
1069
}
1068
1070
1069
- match check_sleeper ( & mut last_onion_message_handler_call) {
1071
+ match check_and_reset_sleeper ( & mut last_onion_message_handler_call, || {
1072
+ sleeper ( ONION_MESSAGE_HANDLER_TIMER )
1073
+ } ) {
1070
1074
Some ( false ) => {
1071
1075
if let Some ( om) = & onion_messenger {
1072
1076
log_trace ! ( logger, "Calling OnionMessageHandler's timer_tick_occurred" ) ;
1073
1077
om. get_om ( ) . timer_tick_occurred ( ) ;
1074
1078
}
1075
- last_onion_message_handler_call = sleeper ( ONION_MESSAGE_HANDLER_TIMER ) ;
1076
1079
} ,
1077
1080
Some ( true ) => break ,
1078
1081
None => { } ,
@@ -1096,23 +1099,21 @@ where
1096
1099
peer_manager. as_ref ( ) . disconnect_all_peers ( ) ;
1097
1100
last_ping_call = sleeper ( PING_TIMER ) ;
1098
1101
} else {
1099
- match check_sleeper ( & mut last_ping_call) {
1102
+ match check_and_reset_sleeper ( & mut last_ping_call, || sleeper ( PING_TIMER ) ) {
1100
1103
Some ( false ) => {
1101
1104
log_trace ! ( logger, "Calling PeerManager's timer_tick_occurred" ) ;
1102
1105
peer_manager. as_ref ( ) . timer_tick_occurred ( ) ;
1103
- last_ping_call = sleeper ( PING_TIMER ) ;
1104
1106
} ,
1105
1107
Some ( true ) => break ,
1106
1108
_ => { } ,
1107
1109
}
1108
1110
}
1109
1111
1110
1112
// Rebroadcast pending claims.
1111
- match check_sleeper ( & mut last_rebroadcast_call) {
1113
+ match check_and_reset_sleeper ( & mut last_rebroadcast_call, || sleeper ( REBROADCAST_TIMER ) ) {
1112
1114
Some ( false ) => {
1113
1115
log_trace ! ( logger, "Rebroadcasting monitor's pending claims" ) ;
1114
1116
chain_monitor. rebroadcast_pending_claims ( ) ;
1115
- last_rebroadcast_call = sleeper ( REBROADCAST_TIMER ) ;
1116
1117
} ,
1117
1118
Some ( true ) => break ,
1118
1119
None => { } ,
@@ -1154,13 +1155,18 @@ where
1154
1155
Ok ( ( ) )
1155
1156
}
1156
1157
1157
- fn check_sleeper < SleepFuture : core:: future:: Future < Output = bool > + core:: marker:: Unpin > (
1158
- fut : & mut SleepFuture ,
1158
+ fn check_and_reset_sleeper <
1159
+ SleepFuture : core:: future:: Future < Output = bool > + core:: marker:: Unpin ,
1160
+ > (
1161
+ fut : & mut SleepFuture , mut new_sleeper : impl FnMut ( ) -> SleepFuture ,
1159
1162
) -> Option < bool > {
1160
1163
let mut waker = dummy_waker ( ) ;
1161
1164
let mut ctx = task:: Context :: from_waker ( & mut waker) ;
1162
- match core:: pin:: Pin :: new ( fut) . poll ( & mut ctx) {
1163
- task:: Poll :: Ready ( exit) => Some ( exit) ,
1165
+ match core:: pin:: Pin :: new ( & mut * fut) . poll ( & mut ctx) {
1166
+ task:: Poll :: Ready ( exit) => {
1167
+ * fut = new_sleeper ( ) ;
1168
+ Some ( exit)
1169
+ } ,
1164
1170
task:: Poll :: Pending => None ,
1165
1171
}
1166
1172
}
0 commit comments