Skip to content

Commit 74a53a5

Browse files
committed
Call OnionMessageHandler::timer_tick_occurred
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.
1 parent c82c08d commit 74a53a5

File tree

1 file changed

+9
-0
lines changed
  • lightning-background-processor/src

1 file changed

+9
-0
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use lightning::events::{Event, PathFailure};
3030
#[cfg(feature = "std")]
3131
use lightning::events::{EventHandler, EventsProvider};
3232
use lightning::ln::channelmanager::ChannelManager;
33+
use lightning::ln::msgs::OnionMessageHandler;
3334
use lightning::ln::peer_handler::APeerManager;
3435
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
3536
use lightning::routing::utxo::UtxoLookup;
@@ -104,6 +105,8 @@ const PING_TIMER: u64 = 30;
104105
#[cfg(test)]
105106
const PING_TIMER: u64 = 1;
106107

108+
const ONION_MESSAGE_HANDLER_TIMER: u64 = 10;
109+
107110
/// Prune the network graph of stale entries hourly.
108111
const NETWORK_PRUNE_TIMER: u64 = 60 * 60;
109112

@@ -283,6 +286,7 @@ macro_rules! define_run_body {
283286
$chain_monitor.rebroadcast_pending_claims();
284287

285288
let mut last_freshness_call = $get_timer(FRESHNESS_TIMER);
289+
let mut last_onion_message_handler_call = $get_timer(ONION_MESSAGE_HANDLER_TIMER);
286290
let mut last_ping_call = $get_timer(PING_TIMER);
287291
let mut last_prune_call = $get_timer(FIRST_NETWORK_PRUNE_TIMER);
288292
let mut last_scorer_persist_call = $get_timer(SCORER_PERSIST_TIMER);
@@ -336,6 +340,11 @@ macro_rules! define_run_body {
336340
$channel_manager.timer_tick_occurred();
337341
last_freshness_call = $get_timer(FRESHNESS_TIMER);
338342
}
343+
if $timer_elapsed(&mut last_onion_message_handler_call, ONION_MESSAGE_HANDLER_TIMER) {
344+
log_trace!($logger, "Calling OnionMessageHandler's timer_tick_occurred");
345+
$peer_manager.onion_message_handler().timer_tick_occurred();
346+
last_onion_message_handler_call = $get_timer(ONION_MESSAGE_HANDLER_TIMER);
347+
}
339348
if await_slow {
340349
// On various platforms, we may be starved of CPU cycles for several reasons.
341350
// E.g. on iOS, if we've been in the background, we will be entirely paused.

0 commit comments

Comments
 (0)