Skip to content

Commit 152ac15

Browse files
committed
Remove futures dependency in lightning-background-processor
As `futures` apparently makes no guarantees on MSRVs even in patch releases we really can't rely on it at all, and while it currently has an acceptable MSRV without the macros feature, its best to just remove it wholesale. Luckily, removing it is relatively trivial, even if it requires the most trivial of unsafe tags.
1 parent 900b73d commit 152ac15

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

lightning-background-processor/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ all-features = true
1414
rustdoc-args = ["--cfg", "docsrs"]
1515

1616
[features]
17-
futures = [ "futures-util" ]
17+
futures = [ ]
1818
std = ["lightning/std", "lightning-rapid-gossip-sync/std"]
1919

2020
default = ["std"]
@@ -23,7 +23,6 @@ default = ["std"]
2323
bitcoin = { version = "0.29.0", default-features = false }
2424
lightning = { version = "0.0.114", path = "../lightning", default-features = false }
2525
lightning-rapid-gossip-sync = { version = "0.0.114", path = "../lightning-rapid-gossip-sync", default-features = false }
26-
futures-util = { version = "0.3", default-features = false, optional = true }
2726

2827
[dev-dependencies]
2928
lightning = { version = "0.0.114", path = "../lightning", features = ["_test_utils"] }

lightning-background-processor/src/lib.rs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![deny(private_intra_doc_links)]
88

99
#![deny(missing_docs)]
10-
#![deny(unsafe_code)]
10+
#![cfg_attr(not(feature = "futures"), deny(unsafe_code))]
1111

1212
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
1313

@@ -52,8 +52,6 @@ use std::thread::{self, JoinHandle};
5252
#[cfg(feature = "std")]
5353
use std::time::Instant;
5454

55-
#[cfg(feature = "futures")]
56-
use futures_util::task;
5755
#[cfg(not(feature = "std"))]
5856
use alloc::vec::Vec;
5957

@@ -385,38 +383,45 @@ macro_rules! define_run_body {
385383
}
386384

387385
#[cfg(feature = "futures")]
388-
use core::future::Future;
389-
#[cfg(feature = "futures")]
390-
use core::task::Poll;
391-
#[cfg(feature = "futures")]
392-
use core::pin::Pin;
393-
#[cfg(feature = "futures")]
394-
use core::marker::Unpin;
395-
#[cfg(feature = "futures")]
396-
struct Selecter<A: Future<Output=()> + Unpin, B: Future<Output=bool> + Unpin> {
397-
a: A,
398-
b: B,
399-
}
400-
#[cfg(feature = "futures")]
401-
enum SelecterOutput {
402-
A, B(bool),
403-
}
386+
pub(crate) mod futures_util {
387+
use core::future::Future;
388+
use core::task::{Poll, Waker, RawWaker, RawWakerVTable};
389+
use core::pin::Pin;
390+
use core::marker::Unpin;
391+
pub(crate) struct Selecter<A: Future<Output=()> + Unpin, B: Future<Output=bool> + Unpin> {
392+
pub a: A,
393+
pub b: B,
394+
}
395+
pub(crate) enum SelecterOutput {
396+
A, B(bool),
397+
}
404398

405-
#[cfg(feature = "futures")]
406-
impl<A: Future<Output=()> + Unpin, B: Future<Output=bool> + Unpin> Future for Selecter<A, B> {
407-
type Output = SelecterOutput;
408-
fn poll(mut self: Pin<&mut Self>, ctx: &mut core::task::Context<'_>) -> Poll<SelecterOutput> {
409-
match Pin::new(&mut self.a).poll(ctx) {
410-
Poll::Ready(()) => { return Poll::Ready(SelecterOutput::A); },
411-
Poll::Pending => {},
412-
}
413-
match Pin::new(&mut self.b).poll(ctx) {
414-
Poll::Ready(res) => { return Poll::Ready(SelecterOutput::B(res)); },
415-
Poll::Pending => {},
399+
impl<A: Future<Output=()> + Unpin, B: Future<Output=bool> + Unpin> Future for Selecter<A, B> {
400+
type Output = SelecterOutput;
401+
fn poll(mut self: Pin<&mut Self>, ctx: &mut core::task::Context<'_>) -> Poll<SelecterOutput> {
402+
match Pin::new(&mut self.a).poll(ctx) {
403+
Poll::Ready(()) => { return Poll::Ready(SelecterOutput::A); },
404+
Poll::Pending => {},
405+
}
406+
match Pin::new(&mut self.b).poll(ctx) {
407+
Poll::Ready(res) => { return Poll::Ready(SelecterOutput::B(res)); },
408+
Poll::Pending => {},
409+
}
410+
Poll::Pending
416411
}
417-
Poll::Pending
418412
}
413+
414+
fn dummy_waker_clone(_: *const ()) -> RawWaker { RawWaker::new(core::ptr::null(), &DUMMY_WAKER_VTABLE) }
415+
fn dummy_waker_action(_: *const ()) { }
416+
417+
const DUMMY_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
418+
dummy_waker_clone, dummy_waker_action, dummy_waker_action, dummy_waker_action);
419+
pub(crate) fn dummy_waker() -> Waker { unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &DUMMY_WAKER_VTABLE)) } }
419420
}
421+
#[cfg(feature = "futures")]
422+
use futures_util::{Selecter, SelecterOutput, dummy_waker};
423+
#[cfg(feature = "futures")]
424+
use core::task;
420425

421426
/// Processes background events in a future.
422427
///
@@ -517,7 +522,7 @@ where
517522
}
518523
}, |t| sleeper(Duration::from_secs(t)),
519524
|fut: &mut SleepFuture, _| {
520-
let mut waker = task::noop_waker();
525+
let mut waker = dummy_waker();
521526
let mut ctx = task::Context::from_waker(&mut waker);
522527
core::pin::Pin::new(fut).poll(&mut ctx).is_ready()
523528
})

0 commit comments

Comments
 (0)