Skip to content

Commit 7c4dd75

Browse files
committed
Introduce retry_tick_occrred in ln_background_processor.
This function introduces the retry timer in the background processor and the RETRY_TIMER to 5, which is around 5 sec. This provides a good balance between timely retries, while not overflowing the system with too many InvoiceRequest Messages.
1 parent 9d6f2d1 commit 7c4dd75

File tree

1 file changed

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

1 file changed

+20
-4
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ use alloc::vec::Vec;
6464
/// * Monitoring whether the [`ChannelManager`] needs to be re-persisted to disk, and if so,
6565
/// writing it to disk/backups by invoking the callback given to it at startup.
6666
/// [`ChannelManager`] persistence should be done in the background.
67-
/// * Calling [`ChannelManager::timer_tick_occurred`], [`ChainMonitor::rebroadcast_pending_claims`]
68-
/// and [`PeerManager::timer_tick_occurred`] at the appropriate intervals.
67+
/// * Calling [`ChannelManager::timer_tick_occurred`], [`ChannelManager::retry_tick_occurred`]
68+
/// [`ChainMonitor::rebroadcast_pending_claims`] and [`PeerManager::timer_tick_occurred`]
69+
/// at the appropriate intervals.
6970
/// * Calling [`NetworkGraph::remove_stale_channels_and_tracking`] (if a [`GossipSync`] with a
7071
/// [`NetworkGraph`] is provided to [`BackgroundProcessor::start`]).
7172
///
@@ -81,6 +82,7 @@ use alloc::vec::Vec;
8182
///
8283
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
8384
/// [`ChannelManager::timer_tick_occurred`]: lightning::ln::channelmanager::ChannelManager::timer_tick_occurred
85+
/// [`ChannelManager::retry_tick_occurred`]: lightning::ln::channelmanager::ChannelManager::retry_tick_occurred
8486
/// [`ChannelMonitor`]: lightning::chain::channelmonitor::ChannelMonitor
8587
/// [`Event`]: lightning::events::Event
8688
/// [`PeerManager::timer_tick_occurred`]: lightning::ln::peer_handler::PeerManager::timer_tick_occurred
@@ -97,6 +99,11 @@ const FRESHNESS_TIMER: u64 = 60;
9799
#[cfg(test)]
98100
const FRESHNESS_TIMER: u64 = 1;
99101

102+
#[cfg(not(test))]
103+
const RETRY_TIMER: u64 = 5;
104+
#[cfg(test)]
105+
const RETRY_TIMER: u64 = 1;
106+
100107
#[cfg(all(not(test), not(debug_assertions)))]
101108
const PING_TIMER: u64 = 10;
102109
/// Signature operations take a lot longer without compiler optimisations.
@@ -134,7 +141,7 @@ const REBROADCAST_TIMER: u64 = 1;
134141
/// core::cmp::min is not currently const, so we define a trivial (and equivalent) replacement
135142
const fn min_u64(a: u64, b: u64) -> u64 { if a < b { a } else { b } }
136143
#[cfg(feature = "futures")]
137-
const FASTEST_TIMER: u64 = min_u64(min_u64(FRESHNESS_TIMER, PING_TIMER),
144+
const FASTEST_TIMER: u64 = min_u64(min_u64(RETRY_TIMER, min_u64(FRESHNESS_TIMER, PING_TIMER)),
138145
min_u64(SCORER_PERSIST_TIMER, min_u64(FIRST_NETWORK_PRUNE_TIMER, REBROADCAST_TIMER)));
139146

140147
/// Either [`P2PGossipSync`] or [`RapidGossipSync`].
@@ -291,6 +298,7 @@ macro_rules! define_run_body {
291298
$chain_monitor.rebroadcast_pending_claims();
292299

293300
let mut last_freshness_call = $get_timer(FRESHNESS_TIMER);
301+
let mut last_retry_call = $get_timer(RETRY_TIMER);
294302
let mut last_onion_message_handler_call = $get_timer(ONION_MESSAGE_HANDLER_TIMER);
295303
let mut last_ping_call = $get_timer(PING_TIMER);
296304
let mut last_prune_call = $get_timer(FIRST_NETWORK_PRUNE_TIMER);
@@ -346,6 +354,11 @@ macro_rules! define_run_body {
346354
$channel_manager.get_cm().timer_tick_occurred();
347355
last_freshness_call = $get_timer(FRESHNESS_TIMER);
348356
}
357+
if $timer_elapsed(&mut last_retry_call, RETRY_TIMER) {
358+
log_trace!($logger, "Calling ChannelManager's retry_tick_occurred");
359+
$channel_manager.get_cm().retry_tick_occurred();
360+
last_retry_call = $get_timer(RETRY_TIMER);
361+
}
349362
if $timer_elapsed(&mut last_onion_message_handler_call, ONION_MESSAGE_HANDLER_TIMER) {
350363
log_trace!($logger, "Calling OnionMessageHandler's timer_tick_occurred");
351364
$peer_manager.onion_message_handler().timer_tick_occurred();
@@ -1488,6 +1501,7 @@ mod tests {
14881501
// - `ChainMonitor::rebroadcast_pending_claims` is called every `REBROADCAST_TIMER`,
14891502
// - `PeerManager::timer_tick_occurred` is called every `PING_TIMER`, and
14901503
// - `OnionMessageHandler::timer_tick_occurred` is called every `ONION_MESSAGE_HANDLER_TIMER`.
1504+
// - `ChannelManager::retry_tick_occurred` is called every `RETRY_TIMER`.
14911505
let (_, nodes) = create_nodes(1, "test_timer_tick_called");
14921506
let data_dir = nodes[0].kv_store.get_data_dir();
14931507
let persister = Arc::new(Persister::new(data_dir));
@@ -1499,10 +1513,12 @@ mod tests {
14991513
let desired_log_2 = "Calling PeerManager's timer_tick_occurred".to_string();
15001514
let desired_log_3 = "Rebroadcasting monitor's pending claims".to_string();
15011515
let desired_log_4 = "Calling OnionMessageHandler's timer_tick_occurred".to_string();
1516+
let desired_log_5 = "Calling ChannelManager's retry_tick_occurred".to_string();
15021517
if log_entries.get(&("lightning_background_processor", desired_log_1)).is_some() &&
15031518
log_entries.get(&("lightning_background_processor", desired_log_2)).is_some() &&
15041519
log_entries.get(&("lightning_background_processor", desired_log_3)).is_some() &&
1505-
log_entries.get(&("lightning_background_processor", desired_log_4)).is_some() {
1520+
log_entries.get(&("lightning_background_processor", desired_log_4)).is_some() &&
1521+
log_entries.get(&("lightning_background_processor", desired_log_5)).is_some() {
15061522
break
15071523
}
15081524
}

0 commit comments

Comments
 (0)