@@ -42,6 +42,8 @@ use lightning::util::persist::Persister;
42
42
use lightning:: util:: wakers:: Sleeper ;
43
43
use lightning_rapid_gossip_sync:: RapidGossipSync ;
44
44
45
+ use lightning_liquidity:: ALiquidityManager ;
46
+
45
47
use core:: ops:: Deref ;
46
48
use core:: time:: Duration ;
47
49
@@ -492,27 +494,31 @@ pub(crate) mod futures_util {
492
494
A : Future < Output = ( ) > + Unpin ,
493
495
B : Future < Output = ( ) > + Unpin ,
494
496
C : Future < Output = ( ) > + Unpin ,
495
- D : Future < Output = bool > + Unpin ,
497
+ D : Future < Output = ( ) > + Unpin ,
498
+ E : Future < Output = bool > + Unpin ,
496
499
> {
497
500
pub a : A ,
498
501
pub b : B ,
499
502
pub c : C ,
500
503
pub d : D ,
504
+ pub e : E ,
501
505
}
502
506
503
507
pub ( crate ) enum SelectorOutput {
504
508
A ,
505
509
B ,
506
510
C ,
507
- D ( bool ) ,
511
+ D ,
512
+ E ( bool ) ,
508
513
}
509
514
510
515
impl <
511
516
A : Future < Output = ( ) > + Unpin ,
512
517
B : Future < Output = ( ) > + Unpin ,
513
518
C : Future < Output = ( ) > + Unpin ,
514
- D : Future < Output = bool > + Unpin ,
515
- > Future for Selector < A , B , C , D >
519
+ D : Future < Output = ( ) > + Unpin ,
520
+ E : Future < Output = bool > + Unpin ,
521
+ > Future for Selector < A , B , C , D , E >
516
522
{
517
523
type Output = SelectorOutput ;
518
524
fn poll (
@@ -537,8 +543,14 @@ pub(crate) mod futures_util {
537
543
Poll :: Pending => { } ,
538
544
}
539
545
match Pin :: new ( & mut self . d ) . poll ( ctx) {
546
+ Poll :: Ready ( ( ) ) => {
547
+ return Poll :: Ready ( SelectorOutput :: D ) ;
548
+ } ,
549
+ Poll :: Pending => { } ,
550
+ }
551
+ match Pin :: new ( & mut self . e ) . poll ( ctx) {
540
552
Poll :: Ready ( res) => {
541
- return Poll :: Ready ( SelectorOutput :: D ( res) ) ;
553
+ return Poll :: Ready ( SelectorOutput :: E ( res) ) ;
542
554
} ,
543
555
Poll :: Pending => { } ,
544
556
}
@@ -648,6 +660,7 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
648
660
/// # type P2PGossipSync<UL> = lightning::routing::gossip::P2PGossipSync<Arc<NetworkGraph>, Arc<UL>, Arc<Logger>>;
649
661
/// # type ChannelManager<B, F, FE> = lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor<B, F, FE>, B, FE, Logger>;
650
662
/// # type OnionMessenger<B, F, FE> = lightning::onion_message::messenger::OnionMessenger<Arc<lightning::sign::KeysManager>, Arc<lightning::sign::KeysManager>, Arc<Logger>, Arc<ChannelManager<B, F, FE>>, Arc<lightning::onion_message::messenger::DefaultMessageRouter<Arc<NetworkGraph>, Arc<Logger>, Arc<lightning::sign::KeysManager>>>, Arc<ChannelManager<B, F, FE>>, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler>;
663
+ /// # type LiquidityManager<B, F, FE> = lightning_liquidity::LiquidityManager<Arc<lightning::sign::KeysManager>, Arc<ChannelManager<B, F, FE>>, Arc<F>>;
651
664
/// # type Scorer = RwLock<lightning::routing::scoring::ProbabilisticScorer<Arc<NetworkGraph>, Arc<Logger>>>;
652
665
/// # type PeerManager<B, F, FE, UL> = lightning::ln::peer_handler::SimpleArcPeerManager<SocketDescriptor, ChainMonitor<B, F, FE>, B, FE, Arc<UL>, Logger>;
653
666
/// #
@@ -661,6 +674,7 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
661
674
/// # event_handler: Arc<EventHandler>,
662
675
/// # channel_manager: Arc<ChannelManager<B, F, FE>>,
663
676
/// # onion_messenger: Arc<OnionMessenger<B, F, FE>>,
677
+ /// # liquidity_manager: Arc<LiquidityManager<B, F, FE>>,
664
678
/// # chain_monitor: Arc<ChainMonitor<B, F, FE>>,
665
679
/// # gossip_sync: Arc<P2PGossipSync<UL>>,
666
680
/// # persister: Arc<Store>,
@@ -681,6 +695,7 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
681
695
/// let background_gossip_sync = GossipSync::p2p(Arc::clone(&node.gossip_sync));
682
696
/// let background_peer_man = Arc::clone(&node.peer_manager);
683
697
/// let background_onion_messenger = Arc::clone(&node.onion_messenger);
698
+ /// let background_liquidity_manager = Arc::clone(&node.liquidity_manager);
684
699
/// let background_logger = Arc::clone(&node.logger);
685
700
/// let background_scorer = Arc::clone(&node.scorer);
686
701
///
@@ -708,6 +723,7 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
708
723
/// Some(background_onion_messenger),
709
724
/// background_gossip_sync,
710
725
/// background_peer_man,
726
+ /// Some(background_liquidity_manager),
711
727
/// background_logger,
712
728
/// Some(background_scorer),
713
729
/// sleeper,
@@ -745,6 +761,7 @@ pub async fn process_events_async<
745
761
PGS : ' static + Deref < Target = P2PGossipSync < G , UL , L > > + Send + Sync ,
746
762
RGS : ' static + Deref < Target = RapidGossipSync < G , L > > + Send ,
747
763
PM : ' static + Deref + Send + Sync ,
764
+ LM : ' static + Deref + Send + Sync ,
748
765
S : ' static + Deref < Target = SC > + Send + Sync ,
749
766
SC : for < ' b > WriteableScore < ' b > ,
750
767
SleepFuture : core:: future:: Future < Output = bool > + core:: marker:: Unpin ,
@@ -753,8 +770,8 @@ pub async fn process_events_async<
753
770
> (
754
771
persister : PS , event_handler : EventHandler , chain_monitor : M , channel_manager : CM ,
755
772
onion_messenger : Option < OM > , gossip_sync : GossipSync < PGS , RGS , G , UL , L > , peer_manager : PM ,
756
- logger : L , scorer : Option < S > , sleeper : Sleeper , mobile_interruptable_platform : bool ,
757
- fetch_time : FetchTime ,
773
+ liquidity_manager : Option < LM > , logger : L , scorer : Option < S > , sleeper : Sleeper ,
774
+ mobile_interruptable_platform : bool , fetch_time : FetchTime ,
758
775
) -> Result < ( ) , lightning:: io:: Error >
759
776
where
760
777
UL :: Target : ' static + UtxoLookup ,
@@ -767,6 +784,7 @@ where
767
784
CM :: Target : AChannelManager + Send + Sync ,
768
785
OM :: Target : AOnionMessenger + Send + Sync ,
769
786
PM :: Target : APeerManager + Send + Sync ,
787
+ LM :: Target : ALiquidityManager + Send + Sync ,
770
788
{
771
789
let mut should_break = false ;
772
790
let async_event_handler = |event| {
@@ -820,19 +838,26 @@ where
820
838
} else {
821
839
OptionalSelector { optional_future: None }
822
840
} ;
841
+ let lm_fut = if let Some ( lm) = liquidity_manager. as_ref( ) {
842
+ let fut = lm. get_lm( ) . get_pending_msgs_future( ) ;
843
+ OptionalSelector { optional_future: Some ( fut) }
844
+ } else {
845
+ OptionalSelector { optional_future: None }
846
+ } ;
823
847
let fut = Selector {
824
848
a: channel_manager. get_cm( ) . get_event_or_persistence_needed_future( ) ,
825
849
b: chain_monitor. get_update_future( ) ,
826
850
c: om_fut,
827
- d: sleeper( if mobile_interruptable_platform {
851
+ d: lm_fut,
852
+ e: sleeper( if mobile_interruptable_platform {
828
853
Duration :: from_millis( 100 )
829
854
} else {
830
855
Duration :: from_secs( FASTEST_TIMER )
831
856
} ) ,
832
857
} ;
833
858
match fut. await {
834
- SelectorOutput :: A | SelectorOutput :: B | SelectorOutput :: C => { } ,
835
- SelectorOutput :: D ( exit) => {
859
+ SelectorOutput :: A | SelectorOutput :: B | SelectorOutput :: C | SelectorOutput :: D => { } ,
860
+ SelectorOutput :: E ( exit) => {
836
861
should_break = exit;
837
862
} ,
838
863
}
@@ -920,12 +945,13 @@ impl BackgroundProcessor {
920
945
PGS : ' static + Deref < Target = P2PGossipSync < G , UL , L > > + Send + Sync ,
921
946
RGS : ' static + Deref < Target = RapidGossipSync < G , L > > + Send ,
922
947
PM : ' static + Deref + Send + Sync ,
948
+ LM : ' static + Deref + Send + Sync ,
923
949
S : ' static + Deref < Target = SC > + Send + Sync ,
924
950
SC : for < ' b > WriteableScore < ' b > ,
925
951
> (
926
952
persister : PS , event_handler : EH , chain_monitor : M , channel_manager : CM ,
927
953
onion_messenger : Option < OM > , gossip_sync : GossipSync < PGS , RGS , G , UL , L > , peer_manager : PM ,
928
- logger : L , scorer : Option < S > ,
954
+ liquidity_manager : Option < LM > , logger : L , scorer : Option < S > ,
929
955
) -> Self
930
956
where
931
957
UL :: Target : ' static + UtxoLookup ,
@@ -938,6 +964,7 @@ impl BackgroundProcessor {
938
964
CM :: Target : AChannelManager + Send + Sync ,
939
965
OM :: Target : AOnionMessenger + Send + Sync ,
940
966
PM :: Target : APeerManager + Send + Sync ,
967
+ LM :: Target : ALiquidityManager + Send + Sync ,
941
968
{
942
969
let stop_thread = Arc :: new ( AtomicBool :: new ( false ) ) ;
943
970
let stop_thread_clone = stop_thread. clone ( ) ;
@@ -977,17 +1004,27 @@ impl BackgroundProcessor {
977
1004
scorer,
978
1005
stop_thread. load( Ordering :: Acquire ) ,
979
1006
{
980
- let sleeper = if let Some ( om ) = onion_messenger . as_ref( ) {
981
- Sleeper :: from_three_futures (
1007
+ let sleeper = match ( onion_messenger . as_ref ( ) , liquidity_manager . as_ref( ) ) {
1008
+ ( Some ( om ) , Some ( lm ) ) => Sleeper :: from_four_futures (
982
1009
& channel_manager. get_cm( ) . get_event_or_persistence_needed_future( ) ,
983
1010
& chain_monitor. get_update_future( ) ,
984
1011
& om. get_om( ) . get_update_future( ) ,
985
- )
986
- } else {
987
- Sleeper :: from_two_futures (
1012
+ & lm . get_lm ( ) . get_pending_msgs_future ( ) ,
1013
+ ) ,
1014
+ ( Some ( om ) , None ) => Sleeper :: from_three_futures (
988
1015
& channel_manager. get_cm( ) . get_event_or_persistence_needed_future( ) ,
989
1016
& chain_monitor. get_update_future( ) ,
990
- )
1017
+ & om. get_om( ) . get_update_future( ) ,
1018
+ ) ,
1019
+ ( None , Some ( lm) ) => Sleeper :: from_three_futures(
1020
+ & channel_manager. get_cm( ) . get_event_or_persistence_needed_future( ) ,
1021
+ & chain_monitor. get_update_future( ) ,
1022
+ & lm. get_lm( ) . get_pending_msgs_future( ) ,
1023
+ ) ,
1024
+ ( None , None ) => Sleeper :: from_two_futures(
1025
+ & channel_manager. get_cm( ) . get_event_or_persistence_needed_future( ) ,
1026
+ & chain_monitor. get_update_future( ) ,
1027
+ ) ,
991
1028
} ;
992
1029
sleeper. wait_timeout( Duration :: from_millis( 100 ) ) ;
993
1030
} ,
@@ -1102,6 +1139,7 @@ mod tests {
1102
1139
use lightning:: util:: sweep:: { OutputSpendStatus , OutputSweeper , PRUNE_DELAY_BLOCKS } ;
1103
1140
use lightning:: util:: test_utils;
1104
1141
use lightning:: { get_event, get_event_msg} ;
1142
+ use lightning_liquidity:: LiquidityManager ;
1105
1143
use lightning_persister:: fs_store:: FilesystemStore ;
1106
1144
use lightning_rapid_gossip_sync:: RapidGossipSync ;
1107
1145
use std:: collections:: VecDeque ;
@@ -1196,6 +1234,9 @@ mod tests {
1196
1234
IgnoringMessageHandler ,
1197
1235
> ;
1198
1236
1237
+ type LM =
1238
+ LiquidityManager < Arc < KeysManager > , Arc < ChannelManager > , Arc < dyn Filter + Sync + Send > > ;
1239
+
1199
1240
struct Node {
1200
1241
node : Arc < ChannelManager > ,
1201
1242
messenger : Arc < OM > ,
@@ -1212,6 +1253,7 @@ mod tests {
1212
1253
Arc < KeysManager > ,
1213
1254
> ,
1214
1255
> ,
1256
+ liquidity_manager : Arc < LM > ,
1215
1257
chain_monitor : Arc < ChainMonitor > ,
1216
1258
kv_store : Arc < FilesystemStore > ,
1217
1259
tx_broadcaster : Arc < test_utils:: TestBroadcaster > ,
@@ -1631,11 +1673,20 @@ mod tests {
1631
1673
logger. clone ( ) ,
1632
1674
keys_manager. clone ( ) ,
1633
1675
) ) ;
1676
+ let liquidity_manager = Arc :: new ( LiquidityManager :: new (
1677
+ Arc :: clone ( & keys_manager) ,
1678
+ Arc :: clone ( & manager) ,
1679
+ None ,
1680
+ None ,
1681
+ None ,
1682
+ None ,
1683
+ ) ) ;
1634
1684
let node = Node {
1635
1685
node : manager,
1636
1686
p2p_gossip_sync,
1637
1687
rapid_gossip_sync,
1638
1688
peer_manager,
1689
+ liquidity_manager,
1639
1690
chain_monitor,
1640
1691
kv_store,
1641
1692
tx_broadcaster,
@@ -1833,6 +1884,7 @@ mod tests {
1833
1884
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
1834
1885
nodes[ 0 ] . p2p_gossip_sync ( ) ,
1835
1886
nodes[ 0 ] . peer_manager . clone ( ) ,
1887
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
1836
1888
nodes[ 0 ] . logger . clone ( ) ,
1837
1889
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
1838
1890
) ;
@@ -1926,6 +1978,7 @@ mod tests {
1926
1978
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
1927
1979
nodes[ 0 ] . no_gossip_sync ( ) ,
1928
1980
nodes[ 0 ] . peer_manager . clone ( ) ,
1981
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
1929
1982
nodes[ 0 ] . logger . clone ( ) ,
1930
1983
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
1931
1984
) ;
@@ -1968,6 +2021,7 @@ mod tests {
1968
2021
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
1969
2022
nodes[ 0 ] . no_gossip_sync ( ) ,
1970
2023
nodes[ 0 ] . peer_manager . clone ( ) ,
2024
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
1971
2025
nodes[ 0 ] . logger . clone ( ) ,
1972
2026
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
1973
2027
) ;
@@ -2000,6 +2054,7 @@ mod tests {
2000
2054
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2001
2055
nodes[ 0 ] . rapid_gossip_sync ( ) ,
2002
2056
nodes[ 0 ] . peer_manager . clone ( ) ,
2057
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2003
2058
nodes[ 0 ] . logger . clone ( ) ,
2004
2059
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2005
2060
move |dur : Duration | {
@@ -2036,6 +2091,7 @@ mod tests {
2036
2091
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2037
2092
nodes[ 0 ] . p2p_gossip_sync ( ) ,
2038
2093
nodes[ 0 ] . peer_manager . clone ( ) ,
2094
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2039
2095
nodes[ 0 ] . logger . clone ( ) ,
2040
2096
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2041
2097
) ;
@@ -2065,6 +2121,7 @@ mod tests {
2065
2121
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2066
2122
nodes[ 0 ] . no_gossip_sync ( ) ,
2067
2123
nodes[ 0 ] . peer_manager . clone ( ) ,
2124
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2068
2125
nodes[ 0 ] . logger . clone ( ) ,
2069
2126
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2070
2127
) ;
@@ -2111,6 +2168,7 @@ mod tests {
2111
2168
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2112
2169
nodes[ 0 ] . no_gossip_sync ( ) ,
2113
2170
nodes[ 0 ] . peer_manager . clone ( ) ,
2171
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2114
2172
nodes[ 0 ] . logger . clone ( ) ,
2115
2173
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2116
2174
) ;
@@ -2173,6 +2231,7 @@ mod tests {
2173
2231
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2174
2232
nodes[ 0 ] . no_gossip_sync ( ) ,
2175
2233
nodes[ 0 ] . peer_manager . clone ( ) ,
2234
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2176
2235
nodes[ 0 ] . logger . clone ( ) ,
2177
2236
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2178
2237
) ;
@@ -2324,6 +2383,7 @@ mod tests {
2324
2383
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2325
2384
nodes[ 0 ] . no_gossip_sync ( ) ,
2326
2385
nodes[ 0 ] . peer_manager . clone ( ) ,
2386
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2327
2387
nodes[ 0 ] . logger . clone ( ) ,
2328
2388
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2329
2389
) ;
@@ -2353,6 +2413,7 @@ mod tests {
2353
2413
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2354
2414
nodes[ 0 ] . no_gossip_sync ( ) ,
2355
2415
nodes[ 0 ] . peer_manager . clone ( ) ,
2416
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2356
2417
nodes[ 0 ] . logger . clone ( ) ,
2357
2418
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2358
2419
) ;
@@ -2448,6 +2509,7 @@ mod tests {
2448
2509
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2449
2510
nodes[ 0 ] . rapid_gossip_sync ( ) ,
2450
2511
nodes[ 0 ] . peer_manager . clone ( ) ,
2512
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2451
2513
nodes[ 0 ] . logger . clone ( ) ,
2452
2514
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2453
2515
) ;
@@ -2480,6 +2542,7 @@ mod tests {
2480
2542
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2481
2543
nodes[ 0 ] . rapid_gossip_sync ( ) ,
2482
2544
nodes[ 0 ] . peer_manager . clone ( ) ,
2545
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2483
2546
nodes[ 0 ] . logger . clone ( ) ,
2484
2547
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2485
2548
move |dur : Duration | {
@@ -2638,6 +2701,7 @@ mod tests {
2638
2701
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2639
2702
nodes[ 0 ] . no_gossip_sync ( ) ,
2640
2703
nodes[ 0 ] . peer_manager . clone ( ) ,
2704
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2641
2705
nodes[ 0 ] . logger . clone ( ) ,
2642
2706
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2643
2707
) ;
@@ -2688,6 +2752,7 @@ mod tests {
2688
2752
Some ( nodes[ 0 ] . messenger . clone ( ) ) ,
2689
2753
nodes[ 0 ] . no_gossip_sync ( ) ,
2690
2754
nodes[ 0 ] . peer_manager . clone ( ) ,
2755
+ Some ( Arc :: clone ( & nodes[ 0 ] . liquidity_manager ) ) ,
2691
2756
nodes[ 0 ] . logger . clone ( ) ,
2692
2757
Some ( nodes[ 0 ] . scorer . clone ( ) ) ,
2693
2758
move |dur : Duration | {
0 commit comments