From: Matt Corallo Date: Thu, 30 Mar 2023 21:52:03 +0000 (+0000) Subject: Replace `futures` `select` with our own select enum to fix MSRV X-Git-Tag: v0.0.115~44^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=54a51f8554c9e6c47285eabcfe5a8115d0e3dc98;p=rust-lightning Replace `futures` `select` with our own select enum to fix MSRV `futures` recently broke our MSRV by bumping the `syn` major version in a patch release. This makes it impractical for us to use, instead here we replace the usage of its `select_biased` macro with a trivial enum. Given its simplicity we likely should have done this without ever taking the dependency. --- diff --git a/lightning-background-processor/Cargo.toml b/lightning-background-processor/Cargo.toml index 6a4925a0b..fe4f27238 100644 --- a/lightning-background-processor/Cargo.toml +++ b/lightning-background-processor/Cargo.toml @@ -23,7 +23,7 @@ default = ["std"] bitcoin = { version = "0.29.0", default-features = false } lightning = { version = "0.0.114", path = "../lightning", default-features = false } lightning-rapid-gossip-sync = { version = "0.0.114", path = "../lightning-rapid-gossip-sync", default-features = false } -futures-util = { version = "0.3", default-features = false, features = ["async-await-macro"], optional = true } +futures-util = { version = "0.3", default-features = false, optional = true } [dev-dependencies] lightning = { version = "0.0.114", path = "../lightning", features = ["_test_utils"] } diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 665bdf543..e15458d54 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -53,7 +53,7 @@ use std::thread::{self, JoinHandle}; use std::time::Instant; #[cfg(feature = "futures")] -use futures_util::{select_biased, future::FutureExt, task}; +use futures_util::task; #[cfg(not(feature = "std"))] use alloc::vec::Vec; @@ -384,6 +384,40 @@ macro_rules! define_run_body { } } } +#[cfg(feature = "futures")] +use core::future::Future; +#[cfg(feature = "futures")] +use core::task::Poll; +#[cfg(feature = "futures")] +use core::pin::Pin; +#[cfg(feature = "futures")] +use core::marker::Unpin; +#[cfg(feature = "futures")] +struct Selector + Unpin, B: Future + Unpin> { + a: A, + b: B, +} +#[cfg(feature = "futures")] +enum SelectorOutput { + A, B(bool), +} + +#[cfg(feature = "futures")] +impl + Unpin, B: Future + Unpin> Future for Selector { + type Output = SelectorOutput; + fn poll(mut self: Pin<&mut Self>, ctx: &mut core::task::Context<'_>) -> Poll { + match Pin::new(&mut self.a).poll(ctx) { + Poll::Ready(()) => { return Poll::Ready(SelectorOutput::A); }, + Poll::Pending => {}, + } + match Pin::new(&mut self.b).poll(ctx) { + Poll::Ready(res) => { return Poll::Ready(SelectorOutput::B(res)); }, + Poll::Pending => {}, + } + Poll::Pending + } +} + /// Processes background events in a future. /// /// `sleeper` should return a future which completes in the given amount of time and returns a @@ -470,9 +504,13 @@ where chain_monitor, chain_monitor.process_pending_events_async(async_event_handler).await, channel_manager, channel_manager.process_pending_events_async(async_event_handler).await, gossip_sync, peer_manager, logger, scorer, should_break, { - select_biased! { - _ = channel_manager.get_persistable_update_future().fuse() => true, - exit = sleeper(Duration::from_millis(100)).fuse() => { + let fut = Selector { + a: channel_manager.get_persistable_update_future(), + b: sleeper(Duration::from_millis(100)), + }; + match fut.await { + SelectorOutput::A => true, + SelectorOutput::B(exit) => { should_break = exit; false }