Skip to content

Commit

Permalink
f Also support blocking BP
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Jul 19, 2024
1 parent f12c222 commit dcadadb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
18 changes: 13 additions & 5 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,11 +976,19 @@ impl BackgroundProcessor {
scorer,
stop_thread.load(Ordering::Acquire),
{
Sleeper::from_two_futures(
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
&chain_monitor.get_update_future(),
)
.wait_timeout(Duration::from_millis(100));
let sleeper = if let Some(om) = onion_messenger.as_ref() {
Sleeper::from_three_futures(
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
&chain_monitor.get_update_future(),
&om.get_om().get_update_future(),
)
} else {
Sleeper::from_two_futures(
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
&chain_monitor.get_update_future(),
)
};
sleeper.wait_timeout(Duration::from_millis(100));
},
|_| Instant::now(),
|time: &Instant, dur| time.elapsed().as_secs() > dur,
Expand Down
12 changes: 11 additions & 1 deletion lightning/src/util/wakers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,20 @@ impl Sleeper {
Self { notifiers: vec![Arc::clone(&future.state)] }
}
/// Constructs a new sleeper from two futures, allowing blocking on both at once.
// Note that this is the common case - a ChannelManager and ChainMonitor.
pub fn from_two_futures(fut_a: &Future, fut_b: &Future) -> Self {
Self { notifiers: vec![Arc::clone(&fut_a.state), Arc::clone(&fut_b.state)] }
}
/// Constructs a new sleeper from three futures, allowing blocking on both at once.
// Note that this is the common case - a ChannelManager, a ChainMonitor, and an
// OnionMessenger.
pub fn from_three_futures(fut_a: &Future, fut_b: &Future, fut_c: &Future) -> Self {
let notifiers = vec![
Arc::clone(&fut_a.state),
Arc::clone(&fut_b.state),
Arc::clone(&fut_c.state)
];
Self { notifiers }
}
/// Constructs a new sleeper on many futures, allowing blocking on all at once.
pub fn new(futures: Vec<Future>) -> Self {
Self { notifiers: futures.into_iter().map(|f| Arc::clone(&f.state)).collect() }
Expand Down

0 comments on commit dcadadb

Please sign in to comment.