]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Call peer_manager.timer_tick_occurred() in background processor
authorValentine Wallace <vwallace@protonmail.com>
Fri, 9 Apr 2021 20:58:31 +0000 (16:58 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 13 Apr 2021 00:42:09 +0000 (20:42 -0400)
background-processor/src/lib.rs

index a670cf9ccd6afc0e2ba3a15d25b66bfe424bd32b..3f11f4e381656a2529e2828e6913abda678f1688 100644 (file)
@@ -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<InMemorySigner, Arc<ChainMonitor>, Arc<test_utils::TestBroadcaster>, Arc<KeysManager>, Arc<test_utils::TestFeeEstimator>, Arc<test_utils::TestLogger>>| 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
                        }