Skip to content

Commit d519609

Browse files
committed
Update lightning-background-processor to ping every five seconds
This updates lightning-background-processor calls to PeerManager::timer_tick_occurred to match the new suggested rate in the documentation.
1 parent 7217c5a commit d519609

File tree

1 file changed

+15
-6
lines changed
  • lightning-background-processor/src

1 file changed

+15
-6
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const FRESHNESS_TIMER: u64 = 60;
4949
#[cfg(test)]
5050
const FRESHNESS_TIMER: u64 = 1;
5151

52+
const PING_TIMER: u64 = 5;
53+
5254
/// Trait which handles persisting a [`ChannelManager`] to disk.
5355
///
5456
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
@@ -137,7 +139,8 @@ impl BackgroundProcessor {
137139
let stop_thread = Arc::new(AtomicBool::new(false));
138140
let stop_thread_clone = stop_thread.clone();
139141
let handle = thread::spawn(move || -> Result<(), std::io::Error> {
140-
let mut current_time = Instant::now();
142+
let mut last_freshness_call = Instant::now();
143+
let mut last_ping_call = Instant::now();
141144
loop {
142145
peer_manager.process_events();
143146
channel_manager.process_pending_events(&event_handler);
@@ -152,11 +155,15 @@ impl BackgroundProcessor {
152155
log_trace!(logger, "Terminating background processor.");
153156
return Ok(());
154157
}
155-
if current_time.elapsed().as_secs() > FRESHNESS_TIMER {
156-
log_trace!(logger, "Calling ChannelManager's and PeerManager's timer_tick_occurred");
158+
if last_freshness_call.elapsed().as_secs() > FRESHNESS_TIMER {
159+
log_trace!(logger, "Calling ChannelManager's timer_tick_occurred");
157160
channel_manager.timer_tick_occurred();
161+
last_freshness_call = Instant::now();
162+
}
163+
if last_ping_call.elapsed().as_secs() > PING_TIMER {
164+
log_trace!(logger, "Calling PeerManager's timer_tick_occurred");
158165
peer_manager.timer_tick_occurred();
159-
current_time = Instant::now();
166+
last_ping_call = Instant::now();
160167
}
161168
}
162169
});
@@ -440,8 +447,10 @@ mod tests {
440447
let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone());
441448
loop {
442449
let log_entries = nodes[0].logger.lines.lock().unwrap();
443-
let desired_log = "Calling ChannelManager's and PeerManager's timer_tick_occurred".to_string();
444-
if log_entries.get(&("lightning_background_processor".to_string(), desired_log)).is_some() {
450+
let desired_log = "Calling ChannelManager's timer_tick_occurred".to_string();
451+
let second_desired_log = "Calling PeerManager's timer_tick_occurred".to_string();
452+
if log_entries.get(&("lightning_background_processor".to_string(), desired_log)).is_some() &&
453+
log_entries.get(&("lightning_background_processor".to_string(), second_desired_log)).is_some() {
445454
break
446455
}
447456
}

0 commit comments

Comments
 (0)