Correct async `lightning-background-processor` exit check docs
[rust-lightning] / lightning-background-processor / src / lib.rs
index 38f8fd40144ee18ef377594c8ebb9f0031937d90..10bcc9bd6e28dc0cb80c12f25853b160d6be89d6 100644 (file)
@@ -35,7 +35,7 @@ use std::time::{Duration, Instant};
 use std::ops::Deref;
 
 #[cfg(feature = "futures")]
-use futures::{select, future::FutureExt};
+use futures_util::{select_biased, future::FutureExt};
 
 /// `BackgroundProcessor` takes care of tasks that (1) need to happen periodically to keep
 /// Rust-Lightning running properly, and (2) either can or should be run in the background. Its
@@ -46,8 +46,8 @@ use futures::{select, future::FutureExt};
 ///   [`ChannelManager`] persistence should be done in the background.
 /// * Calling [`ChannelManager::timer_tick_occurred`] and [`PeerManager::timer_tick_occurred`]
 ///   at the appropriate intervals.
-/// * Calling [`NetworkGraph::remove_stale_channels`] (if a [`GossipSync`] with a [`NetworkGraph`]
-///   is provided to [`BackgroundProcessor::start`]).
+/// * Calling [`NetworkGraph::remove_stale_channels_and_tracking`] (if a [`GossipSync`] with a
+///   [`NetworkGraph`] is provided to [`BackgroundProcessor::start`]).
 ///
 /// It will also call [`PeerManager::process_events`] periodically though this shouldn't be relied
 /// upon as doing so may result in high latency.
@@ -312,7 +312,7 @@ macro_rules! define_run_body {
                                // The network graph must not be pruned while rapid sync completion is pending
                                log_trace!($logger, "Assessing prunability of network graph");
                                if let Some(network_graph) = $gossip_sync.prunable_network_graph() {
-                                       network_graph.remove_stale_channels();
+                                       network_graph.remove_stale_channels_and_tracking();
 
                                        if let Err(e) = $persister.persist_graph(network_graph) {
                                                log_error!($logger, "Error: Failed to persist network graph, check your disk and permissions {}", e)
@@ -358,8 +358,8 @@ macro_rules! define_run_body {
 /// Processes background events in a future.
 ///
 /// `sleeper` should return a future which completes in the given amount of time and returns a
-/// boolean indicating whether the background processing should continue. Once `sleeper` returns a
-/// future which outputs false, the loop will exit and this function's future will complete.
+/// boolean indicating whether the background processing should exit. Once `sleeper` returns a
+/// future which outputs true, the loop will exit and this function's future will complete.
 ///
 /// See [`BackgroundProcessor::start`] for information on which actions this handles.
 #[cfg(feature = "futures")]
@@ -378,6 +378,7 @@ pub async fn process_events_async<
        Descriptor: 'static + SocketDescriptor + Send + Sync,
        CMH: 'static + Deref + Send + Sync,
        RMH: 'static + Deref + Send + Sync,
+       OMH: 'static + Deref + Send + Sync,
        EH: 'static + EventHandler + Send,
        PS: 'static + Deref + Send,
        M: 'static + Deref<Target = ChainMonitor<Signer, CF, T, F, L, P>> + Send + Sync,
@@ -385,7 +386,7 @@ pub async fn process_events_async<
        PGS: 'static + Deref<Target = P2PGossipSync<G, CA, L>> + Send + Sync,
        RGS: 'static + Deref<Target = RapidGossipSync<G, L>> + Send,
        UMH: 'static + Deref + Send + Sync,
-       PM: 'static + Deref<Target = PeerManager<Descriptor, CMH, RMH, L, UMH>> + Send + Sync,
+       PM: 'static + Deref<Target = PeerManager<Descriptor, CMH, RMH, OMH, L, UMH>> + Send + Sync,
        S: 'static + Deref<Target = SC> + Send + Sync,
        SC: WriteableScore<'a>,
        SleepFuture: core::future::Future<Output = bool>,
@@ -405,17 +406,18 @@ where
        L::Target: 'static + Logger,
        P::Target: 'static + Persist<Signer>,
        CMH::Target: 'static + ChannelMessageHandler,
+       OMH::Target: 'static + OnionMessageHandler,
        RMH::Target: 'static + RoutingMessageHandler,
        UMH::Target: 'static + CustomMessageHandler,
        PS::Target: 'static + Persister<'a, Signer, CW, T, K, F, L, SC>,
 {
-       let mut should_continue = true;
+       let mut should_break = true;
        define_run_body!(persister, event_handler, chain_monitor, channel_manager,
-               gossip_sync, peer_manager, logger, scorer, should_continue, {
-                       select! {
+               gossip_sync, peer_manager, logger, scorer, should_break, {
+                       select_biased! {
                                _ = channel_manager.get_persistable_update_future().fuse() => true,
-                               cont = sleeper(Duration::from_millis(100)).fuse() => {
-                                       should_continue = cont;
+                               exit = sleeper(Duration::from_millis(100)).fuse() => {
+                                       should_break = exit;
                                        false
                                }
                        }
@@ -607,7 +609,7 @@ mod tests {
 
        const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
 
-       #[derive(Clone, Eq, Hash, PartialEq)]
+       #[derive(Clone, Hash, PartialEq, Eq)]
        struct TestDescriptor{}
        impl SocketDescriptor for TestDescriptor {
                fn send_data(&mut self, _data: &[u8], _resume_read: bool) -> usize {