Skip to content

Commit 17b08bc

Browse files
committed
Drop dummy_waker in favor of core::task::Waker::noop
.. now that we can.
1 parent 7b65747 commit 17b08bc

File tree

4 files changed

+14
-53
lines changed

4 files changed

+14
-53
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ pub(crate) mod futures_util {
337337
use core::future::Future;
338338
use core::marker::Unpin;
339339
use core::pin::Pin;
340-
use core::task::{Poll, RawWaker, RawWakerVTable, Waker};
340+
use core::task::Poll;
341341
pub(crate) struct Selector<
342342
A: Future<Output = ()> + Unpin,
343343
B: Future<Output = ()> + Unpin,
@@ -428,24 +428,6 @@ pub(crate) mod futures_util {
428428
}
429429
}
430430

431-
// If we want to poll a future without an async context to figure out if it has completed or
432-
// not without awaiting, we need a Waker, which needs a vtable...we fill it with dummy values
433-
// but sadly there's a good bit of boilerplate here.
434-
fn dummy_waker_clone(_: *const ()) -> RawWaker {
435-
RawWaker::new(core::ptr::null(), &DUMMY_WAKER_VTABLE)
436-
}
437-
fn dummy_waker_action(_: *const ()) {}
438-
439-
const DUMMY_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
440-
dummy_waker_clone,
441-
dummy_waker_action,
442-
dummy_waker_action,
443-
dummy_waker_action,
444-
);
445-
pub(crate) fn dummy_waker() -> Waker {
446-
unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &DUMMY_WAKER_VTABLE)) }
447-
}
448-
449431
enum JoinerResult<E, F: Future<Output = Result<(), E>> + Unpin> {
450432
Pending(Option<F>),
451433
Ready(Result<(), E>),
@@ -558,7 +540,7 @@ pub(crate) mod futures_util {
558540
}
559541
}
560542
use core::task;
561-
use futures_util::{dummy_waker, Joiner, OptionalSelector, Selector, SelectorOutput};
543+
use futures_util::{Joiner, OptionalSelector, Selector, SelectorOutput};
562544

563545
/// Processes background events in a future.
564546
///
@@ -950,7 +932,7 @@ where
950932
// below. This will get it moving but won't block us for too long if the underlying
951933
// future is actually async.
952934
use core::future::Future;
953-
let mut waker = dummy_waker();
935+
let mut waker = task::Waker::noop();
954936
let mut ctx = task::Context::from_waker(&mut waker);
955937
match core::pin::Pin::new(&mut fut).poll(&mut ctx) {
956938
task::Poll::Ready(res) => futures.set_a_res(res),
@@ -1168,7 +1150,7 @@ where
11681150
NETWORK_GRAPH_PERSISTENCE_KEY,
11691151
network_graph.encode(),
11701152
)
1171-
.await?;
1153+
.await?
11721154
}
11731155
Ok(())
11741156
}
@@ -1178,7 +1160,7 @@ fn check_and_reset_sleeper<
11781160
>(
11791161
fut: &mut SleepFuture, mut new_sleeper: impl FnMut() -> SleepFuture,
11801162
) -> Option<bool> {
1181-
let mut waker = dummy_waker();
1163+
let mut waker = task::Waker::noop();
11821164
let mut ctx = task::Context::from_waker(&mut waker);
11831165
match core::pin::Pin::new(&mut *fut).poll(&mut ctx) {
11841166
task::Poll::Ready(exit) => {

lightning/src/events/bump_transaction/sync.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
use core::future::Future;
1313
use core::ops::Deref;
1414
use core::task;
15+
use core::task::Waker;
1516

1617
use crate::chain::chaininterface::BroadcasterInterface;
1718
use crate::chain::ClaimId;
1819
use crate::prelude::*;
1920
use crate::sign::SignerProvider;
20-
use crate::util::async_poll::{dummy_waker, AsyncResult, MaybeSend, MaybeSync};
21+
use crate::util::async_poll::{AsyncResult, MaybeSend, MaybeSync};
2122
use crate::util::logger::Logger;
2223

2324
use bitcoin::{Psbt, ScriptBuf, Transaction, TxOut};
@@ -110,7 +111,7 @@ where
110111
must_pay_to,
111112
target_feerate_sat_per_1000_weight,
112113
);
113-
let mut waker = dummy_waker();
114+
let mut waker = Waker::noop();
114115
let mut ctx = task::Context::from_waker(&mut waker);
115116
match fut.as_mut().poll(&mut ctx) {
116117
task::Poll::Ready(result) => result,
@@ -124,7 +125,7 @@ where
124125

125126
fn sign_psbt(&self, psbt: Psbt) -> Result<Transaction, ()> {
126127
let mut fut = self.wallet.sign_psbt(psbt);
127-
let mut waker = dummy_waker();
128+
let mut waker = Waker::noop();
128129
let mut ctx = task::Context::from_waker(&mut waker);
129130
match fut.as_mut().poll(&mut ctx) {
130131
task::Poll::Ready(result) => result,
@@ -219,7 +220,7 @@ where
219220
/// Handles all variants of [`BumpTransactionEvent`].
220221
pub fn handle_event(&self, event: &BumpTransactionEvent) {
221222
let mut fut = Box::pin(self.bump_transaction_event_handler.handle_event(event));
222-
let mut waker = dummy_waker();
223+
let mut waker = Waker::noop();
223224
let mut ctx = task::Context::from_waker(&mut waker);
224225
match fut.as_mut().poll(&mut ctx) {
225226
task::Poll::Ready(result) => result,

lightning/src/util/async_poll.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::prelude::*;
1313
use core::future::Future;
1414
use core::marker::Unpin;
1515
use core::pin::Pin;
16-
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
16+
use core::task::{Context, Poll};
1717

1818
pub(crate) enum ResultFuture<F: Future<Output = Result<(), E>>, E: Unpin> {
1919
Pending(F),
@@ -70,27 +70,6 @@ impl<F: Future<Output = Result<(), E>> + Unpin, E: Unpin> Future for MultiResult
7070
}
7171
}
7272

73-
// If we want to poll a future without an async context to figure out if it has completed or
74-
// not without awaiting, we need a Waker, which needs a vtable...we fill it with dummy values
75-
// but sadly there's a good bit of boilerplate here.
76-
//
77-
// Waker::noop() would be preferable, but requires an MSRV of 1.85.
78-
fn dummy_waker_clone(_: *const ()) -> RawWaker {
79-
RawWaker::new(core::ptr::null(), &DUMMY_WAKER_VTABLE)
80-
}
81-
fn dummy_waker_action(_: *const ()) {}
82-
83-
const DUMMY_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
84-
dummy_waker_clone,
85-
dummy_waker_action,
86-
dummy_waker_action,
87-
dummy_waker_action,
88-
);
89-
90-
pub(crate) fn dummy_waker() -> Waker {
91-
unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &DUMMY_WAKER_VTABLE)) }
92-
}
93-
9473
/// A type alias for a future that returns a result of type T.
9574
#[cfg(feature = "std")]
9675
pub type AsyncResult<'a, T> = Pin<Box<dyn Future<Output = Result<T, ()>> + 'a + Send>>;

lightning/src/util/sweep.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ use core::ops::Deref;
3939
use core::pin::Pin;
4040
use core::sync::atomic::{AtomicBool, Ordering};
4141
use core::task;
42-
43-
use super::async_poll::dummy_waker;
42+
use core::task::Waker;
4443

4544
/// The number of blocks we wait before we prune the tracked spendable outputs.
4645
pub const PRUNE_DELAY_BLOCKS: u32 = ARCHIVAL_DELAY_BLOCKS + ANTI_REORG_DELAY;
@@ -1042,7 +1041,7 @@ where
10421041
/// [`OutputSweeper::regenerate_and_broadcast_spend_if_necessary`].
10431042
pub fn regenerate_and_broadcast_spend_if_necessary(&self) -> Result<(), ()> {
10441043
let mut fut = Box::pin(self.sweeper.regenerate_and_broadcast_spend_if_necessary());
1045-
let mut waker = dummy_waker();
1044+
let mut waker = Waker::noop();
10461045
let mut ctx = task::Context::from_waker(&mut waker);
10471046
match fut.as_mut().poll(&mut ctx) {
10481047
task::Poll::Ready(result) => result,
@@ -1064,7 +1063,7 @@ where
10641063
exclude_static_outputs,
10651064
delay_until_height,
10661065
));
1067-
let mut waker = dummy_waker();
1066+
let mut waker = Waker::noop();
10681067
let mut ctx = task::Context::from_waker(&mut waker);
10691068
match fut.as_mut().poll(&mut ctx) {
10701069
task::Poll::Ready(result) => result,

0 commit comments

Comments
 (0)