From: Matt Corallo Date: Fri, 10 May 2024 21:07:08 +0000 (+0000) Subject: Switch to using the `OnionMessenger` directly in BP X-Git-Tag: v0.0.124-beta~100^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=92bf4602927ea6346e81f82ffbddda1a83b1541a;p=rust-lightning Switch to using the `OnionMessenger` directly in BP When `OnionMessenger` first developed a timer and events interface, we accessed the `OnionMessenger` indirectly via the `PeerManager`. While this is a fairly awkward interface, it avoided a large pile of generics on the background processor interfaces. However, since we now have an `AOnionMessenger` trait, this concern is no longer significant. Further, because we now want to use the built-in `OnionMessenger` async event processing method, we really need a direct referene to the `OnionMessenger` in the background processor, which we add here optionally. --- diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index ad1056ea9..b612dd96f 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -32,6 +32,7 @@ use lightning::events::EventsProvider; use lightning::ln::channelmanager::AChannelManager; use lightning::ln::msgs::OnionMessageHandler; +use lightning::onion_message::messenger::AOnionMessenger; use lightning::ln::peer_handler::APeerManager; use lightning::routing::gossip::{NetworkGraph, P2PGossipSync}; use lightning::routing::utxo::UtxoLookup; @@ -54,6 +55,8 @@ use std::thread::{self, JoinHandle}; #[cfg(feature = "std")] use std::time::Instant; +#[cfg(not(feature = "std"))] +use alloc::boxed::Box; #[cfg(not(feature = "std"))] use alloc::vec::Vec; @@ -281,7 +284,8 @@ macro_rules! define_run_body { ( $persister: ident, $chain_monitor: ident, $process_chain_monitor_events: expr, $channel_manager: ident, $process_channel_manager_events: expr, - $peer_manager: ident, $process_onion_message_handler_events: expr, $gossip_sync: ident, + $onion_messenger: ident, $process_onion_message_handler_events: expr, + $peer_manager: ident, $gossip_sync: ident, $logger: ident, $scorer: ident, $loop_exit_check: expr, $await: expr, $get_timer: expr, $timer_elapsed: expr, $check_slow_await: expr, $time_fetch: expr, ) => { { @@ -347,8 +351,10 @@ macro_rules! define_run_body { 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(); + if let Some(om) = &$onion_messenger { + log_trace!($logger, "Calling OnionMessageHandler's timer_tick_occurred"); + om.get_om().timer_tick_occurred(); + } last_onion_message_handler_call = $get_timer(ONION_MESSAGE_HANDLER_TIMER); } if await_slow { @@ -564,6 +570,7 @@ use core::task; /// # type NetworkGraph = lightning::routing::gossip::NetworkGraph>; /// # type P2PGossipSync