@@ -218,24 +218,23 @@ impl BackgroundProcessor {
218
218
let mut last_prune_call = Instant :: now ( ) ;
219
219
let mut have_pruned = false ;
220
220
221
- // When considering how long its taken since the last timer tick, we don't want to
222
- // count any time spent in user code, especially since event processing can block on
223
- // disk writes. Thus, we track how long we spent in event handling here.
224
- let mut ev_handle_time_since_last_ping = Duration :: from_millis ( 0 ) ;
225
221
loop {
226
- let ev_handle_start = Instant :: now ( ) ;
227
222
peer_manager. process_events ( ) ; // Note that this may block on ChannelManager's locking
228
223
channel_manager. process_pending_events ( & event_handler) ;
229
224
chain_monitor. process_pending_events ( & event_handler) ;
230
- ev_handle_time_since_last_ping += ev_handle_start. elapsed ( ) ;
225
+
226
+ // We wait up to 100ms, but on a mobile device without a ton of activity, if we get
227
+ // put in the background and paused, this is likely where it will happen, causing
228
+ // the wait time to be substantially longer.
229
+ let await_start = Instant :: now ( ) ;
231
230
let updates_available =
232
231
channel_manager. await_persistable_update_timeout ( Duration :: from_millis ( 100 ) ) ;
232
+ let await_time = await_start. elapsed ( ) ;
233
+
233
234
if updates_available {
234
- let persist_start = Instant :: now ( ) ;
235
235
log_trace ! ( logger, "Persisting ChannelManager..." ) ;
236
236
persister. persist_manager ( & * channel_manager) ?;
237
237
log_trace ! ( logger, "Done persisting ChannelManager." ) ;
238
- ev_handle_time_since_last_ping += persist_start. elapsed ( ) ;
239
238
}
240
239
// Exit the loop if the background processor was requested to stop.
241
240
if stop_thread. load ( Ordering :: Acquire ) == true {
@@ -247,7 +246,7 @@ impl BackgroundProcessor {
247
246
channel_manager. timer_tick_occurred ( ) ;
248
247
last_freshness_call = Instant :: now ( ) ;
249
248
}
250
- if ( last_ping_call . elapsed ( ) - ev_handle_time_since_last_ping ) . as_secs ( ) > PING_TIMER * 2 {
249
+ if await_time > Duration :: from_secs ( 1 ) {
251
250
// On various platforms, we may be starved of CPU cycles for several reasons.
252
251
// E.g. on iOS, if we've been in the background, we will be entirely paused.
253
252
// Similarly, if we're on a desktop platform and the device has been asleep, we
@@ -263,12 +262,10 @@ impl BackgroundProcessor {
263
262
log_trace ! ( logger, "Awoke after more than double our ping timer, disconnecting peers." ) ;
264
263
peer_manager. disconnect_all_peers ( ) ;
265
264
last_ping_call = Instant :: now ( ) ;
266
- ev_handle_time_since_last_ping = Duration :: from_millis ( 0 ) ;
267
265
} else if last_ping_call. elapsed ( ) . as_secs ( ) > PING_TIMER {
268
266
log_trace ! ( logger, "Calling PeerManager's timer_tick_occurred" ) ;
269
267
peer_manager. timer_tick_occurred ( ) ;
270
268
last_ping_call = Instant :: now ( ) ;
271
- ev_handle_time_since_last_ping = Duration :: from_millis ( 0 ) ;
272
269
}
273
270
274
271
// Note that we want to run a graph prune once not long after startup before
0 commit comments