Remove empty match arm during prefix check
[rust-lightning] / lightning-background-processor / src / lib.rs
index 704398af2aa76b2318765b9d312504b741243068..76b17ffddd3f9b492968c9583a975186adaade03 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
@@ -377,13 +377,12 @@ pub async fn process_events_async<
        P: 'static + Deref + Send + Sync,
        Descriptor: 'static + SocketDescriptor + Send + Sync,
        CMH: 'static + Deref + Send + Sync,
-       CUMH: '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,
-       CM: 'static + Deref<Target = ChannelManager<Signer, CW, T, K, F, L>> + Send + Sync,
+       CM: 'static + Deref<Target = ChannelManager<CW, T, K, F, L>> + Send + Sync,
        PGS: 'static + Deref<Target = P2PGossipSync<G, CA, L>> + Send + Sync,
        RGS: 'static + Deref<Target = RapidGossipSync<G, L>> + Send,
        UMH: 'static + Deref + Send + Sync,
@@ -415,7 +414,7 @@ where
        let mut should_continue = true;
        define_run_body!(persister, event_handler, chain_monitor, channel_manager,
                gossip_sync, peer_manager, logger, scorer, should_continue, {
-                       select! {
+                       select_biased! {
                                _ = channel_manager.get_persistable_update_future().fuse() => true,
                                cont = sleeper(Duration::from_millis(100)).fuse() => {
                                        should_continue = cont;
@@ -489,7 +488,7 @@ impl BackgroundProcessor {
                EH: 'static + EventHandler + Send,
                PS: 'static + Deref + Send,
                M: 'static + Deref<Target = ChainMonitor<Signer, CF, T, F, L, P>> + Send + Sync,
-               CM: 'static + Deref<Target = ChannelManager<Signer, CW, T, K, F, L>> + Send + Sync,
+               CM: 'static + Deref<Target = ChannelManager<CW, T, K, F, L>> + Send + Sync,
                PGS: 'static + Deref<Target = P2PGossipSync<G, CA, L>> + Send + Sync,
                RGS: 'static + Deref<Target = RapidGossipSync<G, L>> + Send,
                UMH: 'static + Deref + Send + Sync,
@@ -610,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 {
@@ -989,9 +988,12 @@ mod tests {
 
                // Set up a background event handler for FundingGenerationReady events.
                let (sender, receiver) = std::sync::mpsc::sync_channel(1);
-               let event_handler = move |event: &Event| {
-                       sender.send(handle_funding_generation_ready!(event, channel_value)).unwrap();
+               let event_handler = move |event: &Event| match event {
+                       Event::FundingGenerationReady { .. } => sender.send(handle_funding_generation_ready!(event, channel_value)).unwrap(),
+                       Event::ChannelReady { .. } => {},
+                       _ => panic!("Unexpected event: {:?}", event),
                };
+
                let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].no_gossip_sync(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()));
 
                // Open a channel and check that the FundingGenerationReady event was handled.
@@ -1015,7 +1017,12 @@ mod tests {
 
                // Set up a background event handler for SpendableOutputs events.
                let (sender, receiver) = std::sync::mpsc::sync_channel(1);
-               let event_handler = move |event: &Event| sender.send(event.clone()).unwrap();
+               let event_handler = move |event: &Event| match event {
+                       Event::SpendableOutputs { .. } => sender.send(event.clone()).unwrap(),
+                       Event::ChannelReady { .. } => {},
+                       Event::ChannelClosed { .. } => {},
+                       _ => panic!("Unexpected event: {:?}", event),
+               };
                let persister = Arc::new(Persister::new(data_dir));
                let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].no_gossip_sync(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()));
 
@@ -1023,12 +1030,12 @@ mod tests {
                nodes[0].node.force_close_broadcasting_latest_txn(&nodes[0].node.list_channels()[0].channel_id, &nodes[1].node.get_our_node_id()).unwrap();
                let commitment_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
                confirm_transaction_depth(&mut nodes[0], &commitment_tx, BREAKDOWN_TIMEOUT as u32);
+
                let event = receiver
                        .recv_timeout(Duration::from_secs(EVENT_DEADLINE))
-                       .expect("SpendableOutputs not handled within deadline");
+                       .expect("Events not handled within deadline");
                match event {
                        Event::SpendableOutputs { .. } => {},
-                       Event::ChannelClosed { .. } => {},
                        _ => panic!("Unexpected event: {:?}", event),
                }