Skip to content

Commit e5b99c1

Browse files
Call peer_manager.timer_tick_occurred() in background processor
1 parent 5b4c3c6 commit e5b99c1

File tree

1 file changed

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

1 file changed

+11
-9
lines changed

background-processor/src/lib.rs

Lines changed: 11 additions & 9 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
}
@@ -295,15 +297,15 @@ mod tests {
295297

296298
#[test]
297299
fn test_timer_tick_called() {
298-
// Test that ChannelManager's `timer_tick_occurred` is called every
299-
// `CHAN_FRESHNESS_TIMER`.
300-
let nodes = create_nodes(1, "test_chan_freshness_called".to_string());
300+
// Test that ChannelManager's and PeerManager's `timer_tick_occurred` is called every
301+
// `FRESHNESS_TIMER`.
302+
let nodes = create_nodes(1, "test_timer_tick_called".to_string());
301303
let data_dir = nodes[0].persister.get_data_dir();
302304
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);
303305
let bg_processor = BackgroundProcessor::start(callback, nodes[0].node.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone());
304306
loop {
305307
let log_entries = nodes[0].logger.lines.lock().unwrap();
306-
let desired_log = "Calling manager's timer_tick_occurred".to_string();
308+
let desired_log = "Calling ChannelManager's and PeerManager's timer_tick_occurred".to_string();
307309
if log_entries.get(&("lightning_background_processor".to_string(), desired_log)).is_some() {
308310
break
309311
}

0 commit comments

Comments
 (0)