Skip to content

Commit 736ec06

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 8e9aa9f commit 736ec06

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
@@ -50,6 +50,8 @@ const FRESHNESS_TIMER: u64 = 60;
5050
#[cfg(test)]
5151
const FRESHNESS_TIMER: u64 = 1;
5252

53+
const PING_TIMER: u64 = 5;
54+
5355
/// Trait which handles persisting a [`ChannelManager`] to disk.
5456
///
5557
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
@@ -138,7 +140,8 @@ impl BackgroundProcessor {
138140
let stop_thread = Arc::new(AtomicBool::new(false));
139141
let stop_thread_clone = stop_thread.clone();
140142
let handle = thread::spawn(move || -> Result<(), std::io::Error> {
141-
let mut current_time = Instant::now();
143+
let mut last_freshness_call = Instant::now();
144+
let mut last_ping_call = Instant::now();
142145
loop {
143146
peer_manager.process_events();
144147
channel_manager.process_pending_events(&event_handler);
@@ -153,11 +156,15 @@ impl BackgroundProcessor {
153156
log_trace!(logger, "Terminating background processor.");
154157
return Ok(());
155158
}
156-
if current_time.elapsed().as_secs() > FRESHNESS_TIMER {
157-
log_trace!(logger, "Calling ChannelManager's and PeerManager's timer_tick_occurred");
159+
if last_freshness_call.elapsed().as_secs() > FRESHNESS_TIMER {
160+
log_trace!(logger, "Calling ChannelManager's timer_tick_occurred");
158161
channel_manager.timer_tick_occurred();
162+
last_freshness_call = Instant::now();
163+
}
164+
if last_ping_call.elapsed().as_secs() > PING_TIMER {
165+
log_trace!(logger, "Calling PeerManager's timer_tick_occurred");
159166
peer_manager.timer_tick_occurred();
160-
current_time = Instant::now();
167+
last_ping_call = Instant::now();
161168
}
162169
}
163170
});
@@ -441,8 +448,10 @@ mod tests {
441448
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());
442449
loop {
443450
let log_entries = nodes[0].logger.lines.lock().unwrap();
444-
let desired_log = "Calling ChannelManager's and PeerManager's timer_tick_occurred".to_string();
445-
if log_entries.get(&("lightning_background_processor".to_string(), desired_log)).is_some() {
451+
let desired_log = "Calling ChannelManager's timer_tick_occurred".to_string();
452+
let second_desired_log = "Calling PeerManager's timer_tick_occurred".to_string();
453+
if log_entries.get(&("lightning_background_processor".to_string(), desired_log)).is_some() &&
454+
log_entries.get(&("lightning_background_processor".to_string(), second_desired_log)).is_some() {
446455
break
447456
}
448457
}

0 commit comments

Comments
 (0)