Skip to content

Commit e59b384

Browse files
committed
Use the user-provided SleepFuture for interval checks in BP
`background-processor` does a number of jobs on various timers. Instead of doing those by interrogating `std::time::Instant`, this change swaps to using the existing user-provided sleep future. Fixes #1864.
1 parent d308710 commit e59b384

File tree

1 file changed

+8
-3
lines changed
  • lightning-background-processor/src

1 file changed

+8
-3
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::time::{Duration, Instant};
3636
use std::ops::Deref;
3737

3838
#[cfg(feature = "futures")]
39-
use futures_util::{select_biased, future::FutureExt};
39+
use futures_util::{select_biased, future::FutureExt, task};
4040

4141
/// `BackgroundProcessor` takes care of tasks that (1) need to happen periodically to keep
4242
/// Rust-Lightning running properly, and (2) either can or should be run in the background. Its
@@ -364,7 +364,7 @@ pub async fn process_events_async<
364364
PM: 'static + Deref<Target = PeerManager<Descriptor, CMH, RMH, OMH, L, UMH>> + Send + Sync,
365365
S: 'static + Deref<Target = SC> + Send + Sync,
366366
SC: WriteableScore<'a>,
367-
SleepFuture: core::future::Future<Output = bool>,
367+
SleepFuture: core::future::Future<Output = bool> + core::marker::Unpin,
368368
Sleeper: Fn(Duration) -> SleepFuture
369369
>(
370370
persister: PS, event_handler: EventHandler, chain_monitor: M, channel_manager: CM,
@@ -411,7 +411,12 @@ where
411411
false
412412
}
413413
}
414-
}, |_| Instant::now(), |time: &Instant, dur| time.elapsed().as_secs() > dur)
414+
}, |t| sleeper(Duration::from_secs(t)),
415+
|fut: &mut SleepFuture, _| {
416+
let mut waker = task::noop_waker();
417+
let mut ctx = task::Context::from_waker(&mut waker);
418+
core::pin::Pin::new(fut).poll(&mut ctx).is_ready()
419+
})
415420
}
416421

417422
impl BackgroundProcessor {

0 commit comments

Comments
 (0)