From e5b99c14e274945a8c35cf7836561491b07101b6 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Fri, 9 Apr 2021 16:58:31 -0400 Subject: [PATCH 1/1] Call peer_manager.timer_tick_occurred() in background processor --- background-processor/src/lib.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/background-processor/src/lib.rs b/background-processor/src/lib.rs index a670cf9c..3f11f4e3 100644 --- a/background-processor/src/lib.rs +++ b/background-processor/src/lib.rs @@ -27,7 +27,8 @@ use std::time::{Duration, Instant}; /// * Monitoring whether the ChannelManager needs to be re-persisted to disk, and if so, /// writing it to disk/backups by invoking the callback given to it at startup. /// ChannelManager persistence should be done in the background. -/// * Calling `ChannelManager::timer_tick_occurred()` every minute (can be done in the +/// * Calling `ChannelManager::timer_tick_occurred()` and +/// `PeerManager::timer_tick_occurred()` every minute (can be done in the /// background). /// /// Note that if ChannelManager persistence fails and the persisted manager becomes out-of-date, @@ -42,9 +43,9 @@ pub struct BackgroundProcessor { } #[cfg(not(test))] -const CHAN_FRESHNESS_TIMER: u64 = 60; +const FRESHNESS_TIMER: u64 = 60; #[cfg(test)] -const CHAN_FRESHNESS_TIMER: u64 = 1; +const FRESHNESS_TIMER: u64 = 1; impl BackgroundProcessor { /// Start a background thread that takes care of responsibilities enumerated in the top-level @@ -101,9 +102,10 @@ impl BackgroundProcessor { log_trace!(logger, "Terminating background processor."); return Ok(()); } - if current_time.elapsed().as_secs() > CHAN_FRESHNESS_TIMER { - log_trace!(logger, "Calling manager's timer_tick_occurred"); + if current_time.elapsed().as_secs() > FRESHNESS_TIMER { + log_trace!(logger, "Calling ChannelManager's and PeerManager's timer_tick_occurred"); channel_manager.timer_tick_occurred(); + peer_manager.timer_tick_occurred(); current_time = Instant::now(); } } @@ -295,15 +297,15 @@ mod tests { #[test] fn test_timer_tick_called() { - // Test that ChannelManager's `timer_tick_occurred` is called every - // `CHAN_FRESHNESS_TIMER`. - let nodes = create_nodes(1, "test_chan_freshness_called".to_string()); + // Test that ChannelManager's and PeerManager's `timer_tick_occurred` is called every + // `FRESHNESS_TIMER`. + let nodes = create_nodes(1, "test_timer_tick_called".to_string()); let data_dir = nodes[0].persister.get_data_dir(); let callback = move |node: &ChannelManager, Arc, Arc, Arc, Arc>| FilesystemPersister::persist_manager(data_dir.clone(), node); let bg_processor = BackgroundProcessor::start(callback, nodes[0].node.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone()); loop { let log_entries = nodes[0].logger.lines.lock().unwrap(); - let desired_log = "Calling manager's timer_tick_occurred".to_string(); + let desired_log = "Calling ChannelManager's and PeerManager's timer_tick_occurred".to_string(); if log_entries.get(&("lightning_background_processor".to_string(), desired_log)).is_some() { break } -- 2.30.2