Skip to content

Commit dcadadb

Browse files
committed
f Also support blocking BP
1 parent f12c222 commit dcadadb

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -976,11 +976,19 @@ impl BackgroundProcessor {
976976
scorer,
977977
stop_thread.load(Ordering::Acquire),
978978
{
979-
Sleeper::from_two_futures(
980-
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
981-
&chain_monitor.get_update_future(),
982-
)
983-
.wait_timeout(Duration::from_millis(100));
979+
let sleeper = if let Some(om) = onion_messenger.as_ref() {
980+
Sleeper::from_three_futures(
981+
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
982+
&chain_monitor.get_update_future(),
983+
&om.get_om().get_update_future(),
984+
)
985+
} else {
986+
Sleeper::from_two_futures(
987+
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
988+
&chain_monitor.get_update_future(),
989+
)
990+
};
991+
sleeper.wait_timeout(Duration::from_millis(100));
984992
},
985993
|_| Instant::now(),
986994
|time: &Instant, dur| time.elapsed().as_secs() > dur,

lightning/src/util/wakers.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,20 @@ impl Sleeper {
244244
Self { notifiers: vec![Arc::clone(&future.state)] }
245245
}
246246
/// Constructs a new sleeper from two futures, allowing blocking on both at once.
247-
// Note that this is the common case - a ChannelManager and ChainMonitor.
248247
pub fn from_two_futures(fut_a: &Future, fut_b: &Future) -> Self {
249248
Self { notifiers: vec![Arc::clone(&fut_a.state), Arc::clone(&fut_b.state)] }
250249
}
250+
/// Constructs a new sleeper from three futures, allowing blocking on both at once.
251+
// Note that this is the common case - a ChannelManager, a ChainMonitor, and an
252+
// OnionMessenger.
253+
pub fn from_three_futures(fut_a: &Future, fut_b: &Future, fut_c: &Future) -> Self {
254+
let notifiers = vec![
255+
Arc::clone(&fut_a.state),
256+
Arc::clone(&fut_b.state),
257+
Arc::clone(&fut_c.state)
258+
];
259+
Self { notifiers }
260+
}
251261
/// Constructs a new sleeper on many futures, allowing blocking on all at once.
252262
pub fn new(futures: Vec<Future>) -> Self {
253263
Self { notifiers: futures.into_iter().map(|f| Arc::clone(&f.state)).collect() }

0 commit comments

Comments
 (0)