Skip to content

Commit 23fc049

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 23fc049

File tree

1 file changed

+11
-4
lines changed
  • lightning-background-processor/src

1 file changed

+11
-4
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 11 additions & 4 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
});

0 commit comments

Comments
 (0)