@@ -64,6 +64,7 @@ use lightning::util::persist::{
6464 SCORER_PERSISTENCE_PRIMARY_NAMESPACE , SCORER_PERSISTENCE_SECONDARY_NAMESPACE ,
6565} ;
6666use lightning:: util:: sweep:: { OutputSweeper , OutputSweeperSync } ;
67+ use lightning:: util:: wakers:: Future ;
6768#[ cfg( feature = "std" ) ]
6869use lightning:: util:: wakers:: Sleeper ;
6970use lightning_rapid_gossip_sync:: RapidGossipSync ;
@@ -245,6 +246,14 @@ where
245246 GossipSync :: None => None ,
246247 }
247248 }
249+
250+ fn validation_completion_future ( & self ) -> Option < Future > {
251+ match self {
252+ GossipSync :: P2P ( gossip_sync) => Some ( gossip_sync. validation_completion_future ( ) ) ,
253+ GossipSync :: Rapid ( _) => None ,
254+ GossipSync :: None => None ,
255+ }
256+ }
248257}
249258
250259/// This is not exported to bindings users as the bindings concretize everything and have constructors for us
@@ -530,12 +539,14 @@ pub(crate) mod futures_util {
530539 C : Future < Output = ( ) > + Unpin ,
531540 D : Future < Output = ( ) > + Unpin ,
532541 E : Future < Output = ( ) > + Unpin ,
542+ F : Future < Output = ( ) > + Unpin ,
533543 > {
534544 pub a : A ,
535545 pub b : B ,
536546 pub c : C ,
537547 pub d : D ,
538548 pub e : E ,
549+ pub f : F ,
539550 }
540551
541552 pub ( crate ) enum SelectorOutput {
@@ -544,6 +555,7 @@ pub(crate) mod futures_util {
544555 C ,
545556 D ,
546557 E ,
558+ F ,
547559 }
548560
549561 impl <
@@ -552,7 +564,8 @@ pub(crate) mod futures_util {
552564 C : Future < Output = ( ) > + Unpin ,
553565 D : Future < Output = ( ) > + Unpin ,
554566 E : Future < Output = ( ) > + Unpin ,
555- > Future for Selector < A , B , C , D , E >
567+ F : Future < Output = ( ) > + Unpin ,
568+ > Future for Selector < A , B , C , D , E , F >
556569 {
557570 type Output = SelectorOutput ;
558571 fn poll (
@@ -590,6 +603,12 @@ pub(crate) mod futures_util {
590603 } ,
591604 Poll :: Pending => { } ,
592605 }
606+ match Pin :: new ( & mut self . f ) . poll ( ctx) {
607+ Poll :: Ready ( ( ) ) => {
608+ return Poll :: Ready ( SelectorOutput :: F ) ;
609+ } ,
610+ Poll :: Pending => { } ,
611+ }
593612 Poll :: Pending
594613 }
595614 }
@@ -616,6 +635,12 @@ pub(crate) mod futures_util {
616635 }
617636 }
618637
638+ impl < F : Future < Output = ( ) > + Unpin > From < Option < F > > for OptionalSelector < F > {
639+ fn from ( optional_future : Option < F > ) -> Self {
640+ Self { optional_future }
641+ }
642+ }
643+
619644 // If we want to poll a future without an async context to figure out if it has completed or
620645 // not without awaiting, we need a Waker, which needs a vtable...we fill it with dummy values
621646 // but sadly there's a good bit of boilerplate here.
@@ -1070,18 +1095,13 @@ where
10701095 if mobile_interruptable_platform {
10711096 await_start = Some ( sleeper ( Duration :: from_secs ( 1 ) ) ) ;
10721097 }
1073- let om_fut = if let Some ( om) = onion_messenger. as_ref ( ) {
1074- let fut = om. get_om ( ) . get_update_future ( ) ;
1075- OptionalSelector { optional_future : Some ( fut) }
1076- } else {
1077- OptionalSelector { optional_future : None }
1078- } ;
1079- let lm_fut = if let Some ( lm) = liquidity_manager. as_ref ( ) {
1080- let fut = lm. get_lm ( ) . get_pending_msgs_or_needs_persist_future ( ) ;
1081- OptionalSelector { optional_future : Some ( fut) }
1082- } else {
1083- OptionalSelector { optional_future : None }
1084- } ;
1098+ let om_fut: OptionalSelector < _ > =
1099+ onion_messenger. as_ref ( ) . map ( |om| om. get_om ( ) . get_update_future ( ) ) . into ( ) ;
1100+ let lm_fut: OptionalSelector < _ > = liquidity_manager
1101+ . as_ref ( )
1102+ . map ( |lm| lm. get_lm ( ) . get_pending_msgs_or_needs_persist_future ( ) )
1103+ . into ( ) ;
1104+ let gv_fut: OptionalSelector < _ > = gossip_sync. validation_completion_future ( ) . into ( ) ;
10851105 let needs_processing = channel_manager. get_cm ( ) . needs_pending_htlc_processing ( ) ;
10861106 let sleep_delay = match ( needs_processing, mobile_interruptable_platform) {
10871107 ( true , true ) => batch_delay. get ( ) . min ( Duration :: from_millis ( 100 ) ) ,
@@ -1095,9 +1115,14 @@ where
10951115 c : chain_monitor. get_update_future ( ) ,
10961116 d : om_fut,
10971117 e : lm_fut,
1118+ f : gv_fut,
10981119 } ;
10991120 match fut. await {
1100- SelectorOutput :: B | SelectorOutput :: C | SelectorOutput :: D | SelectorOutput :: E => { } ,
1121+ SelectorOutput :: B
1122+ | SelectorOutput :: C
1123+ | SelectorOutput :: D
1124+ | SelectorOutput :: E
1125+ | SelectorOutput :: F => { } ,
11011126 SelectorOutput :: A ( exit) => {
11021127 if exit {
11031128 break ;
@@ -1669,28 +1694,18 @@ impl BackgroundProcessor {
16691694 log_trace ! ( logger, "Terminating background processor." ) ;
16701695 break ;
16711696 }
1672- let sleeper = match ( onion_messenger. as_ref ( ) , liquidity_manager. as_ref ( ) ) {
1673- ( Some ( om) , Some ( lm) ) => Sleeper :: from_four_futures (
1674- & channel_manager. get_cm ( ) . get_event_or_persistence_needed_future ( ) ,
1675- & chain_monitor. get_update_future ( ) ,
1676- & om. get_om ( ) . get_update_future ( ) ,
1677- & lm. get_lm ( ) . get_pending_msgs_or_needs_persist_future ( ) ,
1678- ) ,
1679- ( Some ( om) , None ) => Sleeper :: from_three_futures (
1680- & channel_manager. get_cm ( ) . get_event_or_persistence_needed_future ( ) ,
1681- & chain_monitor. get_update_future ( ) ,
1682- & om. get_om ( ) . get_update_future ( ) ,
1683- ) ,
1684- ( None , Some ( lm) ) => Sleeper :: from_three_futures (
1685- & channel_manager. get_cm ( ) . get_event_or_persistence_needed_future ( ) ,
1686- & chain_monitor. get_update_future ( ) ,
1687- & lm. get_lm ( ) . get_pending_msgs_or_needs_persist_future ( ) ,
1688- ) ,
1689- ( None , None ) => Sleeper :: from_two_futures (
1690- & channel_manager. get_cm ( ) . get_event_or_persistence_needed_future ( ) ,
1691- & chain_monitor. get_update_future ( ) ,
1692- ) ,
1693- } ;
1697+ let om_fut = onion_messenger. as_ref ( ) . map ( |om| om. get_om ( ) . get_update_future ( ) ) ;
1698+ let lm_fut = liquidity_manager
1699+ . as_ref ( )
1700+ . map ( |lm| lm. get_lm ( ) . get_pending_msgs_or_needs_persist_future ( ) ) ;
1701+ let gv_fut = gossip_sync. validation_completion_future ( ) ;
1702+ let always_futures = [
1703+ channel_manager. get_cm ( ) . get_event_or_persistence_needed_future ( ) ,
1704+ chain_monitor. get_update_future ( ) ,
1705+ ] ;
1706+ let futures = always_futures. into_iter ( ) . chain ( om_fut) . chain ( lm_fut) . chain ( gv_fut) ;
1707+ let sleeper = Sleeper :: from_futures ( futures) ;
1708+
16941709 let batch_delay = if channel_manager. get_cm ( ) . needs_pending_htlc_processing ( ) {
16951710 batch_delay. get ( )
16961711 } else {
0 commit comments