Skip to content

Commit

Permalink
Call OnionMessageHandler::timer_tick_occurred
Browse files Browse the repository at this point in the history
lightning-background-processor processes events provided by the
PeerManager's OnionMessageHandler for when a connection is needed. If a
connection is not established in a reasonable amount of time, drop any
buffered onion messages by calling timer_tick_occurred.
  • Loading branch information
jkczyz committed Nov 16, 2023
1 parent 780e91f commit 3117b94
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use lightning::events::{Event, PathFailure};
#[cfg(feature = "std")]
use lightning::events::{EventHandler, EventsProvider};
use lightning::ln::channelmanager::ChannelManager;
use lightning::ln::msgs::OnionMessageHandler;
use lightning::ln::peer_handler::APeerManager;
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
use lightning::routing::utxo::UtxoLookup;
Expand Down Expand Up @@ -104,6 +105,8 @@ const PING_TIMER: u64 = 30;
#[cfg(test)]
const PING_TIMER: u64 = 1;

const ONION_MESSAGE_HANDLER_TIMER: u64 = 10;

/// Prune the network graph of stale entries hourly.
const NETWORK_PRUNE_TIMER: u64 = 60 * 60;

Expand Down Expand Up @@ -283,6 +286,7 @@ macro_rules! define_run_body {
$chain_monitor.rebroadcast_pending_claims();

let mut last_freshness_call = $get_timer(FRESHNESS_TIMER);
let mut last_onion_message_handler_call = $get_timer(ONION_MESSAGE_HANDLER_TIMER);
let mut last_ping_call = $get_timer(PING_TIMER);
let mut last_prune_call = $get_timer(FIRST_NETWORK_PRUNE_TIMER);
let mut last_scorer_persist_call = $get_timer(SCORER_PERSIST_TIMER);
Expand Down Expand Up @@ -336,6 +340,11 @@ macro_rules! define_run_body {
$channel_manager.timer_tick_occurred();
last_freshness_call = $get_timer(FRESHNESS_TIMER);
}
if $timer_elapsed(&mut last_onion_message_handler_call, ONION_MESSAGE_HANDLER_TIMER) {
log_trace!($logger, "Calling OnionMessageHandler's timer_tick_occurred");
$peer_manager.onion_message_handler().timer_tick_occurred();
last_onion_message_handler_call = $get_timer(ONION_MESSAGE_HANDLER_TIMER);
}
if await_slow {
// On various platforms, we may be starved of CPU cycles for several reasons.
// E.g. on iOS, if we've been in the background, we will be entirely paused.
Expand Down

0 comments on commit 3117b94

Please sign in to comment.