Skip to content

Commit ca57087

Browse files
Call peer_manager.timer_tick_occurred() in background processor
1 parent 379a8e5 commit ca57087

File tree

1 file changed

+9
-7
lines changed
  • background-processor/src

1 file changed

+9
-7
lines changed

background-processor/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ use std::time::{Duration, Instant};
2727
/// * Monitoring whether the ChannelManager needs to be re-persisted to disk, and if so,
2828
/// writing it to disk/backups by invoking the callback given to it at startup.
2929
/// ChannelManager persistence should be done in the background.
30-
/// * Calling `ChannelManager::timer_tick_occurred()` every minute (can be done in the
30+
/// * Calling `ChannelManager::timer_tick_occurred()` and
31+
/// `PeerManager::timer_tick_occurred()` every minute (can be done in the
3132
/// background).
3233
///
3334
/// Note that if ChannelManager persistence fails and the persisted manager becomes out-of-date,
@@ -42,9 +43,9 @@ pub struct BackgroundProcessor {
4243
}
4344

4445
#[cfg(not(test))]
45-
const CHAN_FRESHNESS_TIMER: u64 = 60;
46+
const FRESHNESS_TIMER: u64 = 60;
4647
#[cfg(test)]
47-
const CHAN_FRESHNESS_TIMER: u64 = 1;
48+
const FRESHNESS_TIMER: u64 = 1;
4849

4950
impl BackgroundProcessor {
5051
/// Start a background thread that takes care of responsibilities enumerated in the top-level
@@ -101,9 +102,10 @@ impl BackgroundProcessor {
101102
log_trace!(logger, "Terminating background processor.");
102103
return Ok(());
103104
}
104-
if current_time.elapsed().as_secs() > CHAN_FRESHNESS_TIMER {
105-
log_trace!(logger, "Calling manager's timer_tick_occurred");
105+
if current_time.elapsed().as_secs() > FRESHNESS_TIMER {
106+
log_trace!(logger, "Calling ChannelManager's and PeerManager's timer_tick_occurred");
106107
channel_manager.timer_tick_occurred();
108+
peer_manager.timer_tick_occurred();
107109
current_time = Instant::now();
108110
}
109111
}
@@ -298,13 +300,13 @@ mod tests {
298300
fn test_timer_tick_called() {
299301
// Test that ChannelManager's `timer_tick_occurred` is called every
300302
// `CHAN_FRESHNESS_TIMER`.
301-
let nodes = create_nodes(1, "test_chan_freshness_called".to_string());
303+
let nodes = create_nodes(1, "test_timer_tick_called".to_string());
302304
let data_dir = nodes[0].persister.get_data_dir();
303305
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);
304306
let bg_processor = BackgroundProcessor::start(callback, nodes[0].node.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone());
305307
loop {
306308
let log_entries = nodes[0].logger.lines.lock().unwrap();
307-
let desired_log = "Calling manager's timer_tick_occurred".to_string();
309+
let desired_log = "Calling ChannelManager's and PeerManager's timer_tick_occurred".to_string();
308310
if log_entries.get(&("lightning_background_processor".to_string(), desired_log)).is_some() {
309311
break
310312
}

0 commit comments

Comments
 (0)