@@ -18,7 +18,7 @@ use crate::gossip::GossipSource;
1818use crate :: io:: sqlite_store:: SqliteStore ;
1919use crate :: io:: utils:: { read_node_metrics, write_node_metrics} ;
2020use crate :: io:: vss_store:: VssStore ;
21- use crate :: liquidity:: LiquiditySource ;
21+ use crate :: liquidity:: LiquiditySourceBuilder ;
2222use crate :: logger:: { log_error, log_info, LdkLogger , LogLevel , LogWriter , Logger } ;
2323use crate :: message_handler:: NodeCustomMessageHandler ;
2424use crate :: payment:: store:: PaymentStore ;
@@ -54,9 +54,6 @@ use lightning::util::sweep::OutputSweeper;
5454
5555use lightning_persister:: fs_store:: FilesystemStore ;
5656
57- use lightning_liquidity:: lsps2:: client:: LSPS2ClientConfig ;
58- use lightning_liquidity:: { LiquidityClientConfig , LiquidityManager } ;
59-
6057use bdk_wallet:: template:: Bip84 ;
6158use bdk_wallet:: KeychainKind ;
6259use bdk_wallet:: Wallet as BdkWallet ;
@@ -99,13 +96,15 @@ enum GossipSourceConfig {
9996
10097#[ derive( Debug , Clone ) ]
10198struct LiquiditySourceConfig {
102- // LSPS2 service's (address, node_id, token)
103- lsps2_service : Option < ( SocketAddress , PublicKey , Option < String > ) > ,
99+ // LSPS1 service's (node_id, address, token)
100+ lsps1_service : Option < ( PublicKey , SocketAddress , Option < String > ) > ,
101+ // LSPS2 service's (node_id, address, token)
102+ lsps2_service : Option < ( PublicKey , SocketAddress , Option < String > ) > ,
104103}
105104
106105impl Default for LiquiditySourceConfig {
107106 fn default ( ) -> Self {
108- Self { lsps2_service : None }
107+ Self { lsps1_service : None , lsps2_service : None }
109108 }
110109}
111110
@@ -304,22 +303,43 @@ impl NodeBuilder {
304303 self
305304 }
306305
307- /// Configures the [`Node`] instance to source its inbound liquidity from the given
308- /// [LSPS2](https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md)
309- /// service.
306+ /// Configures the [`Node`] instance to source inbound liquidity from the given
307+ /// [bLIP-51 / LSPS1] service.
308+ ///
309+ /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
310+ ///
311+ /// The given `token` will be used by the LSP to authenticate the user.
312+ ///
313+ /// [bLIP-51 / LSPS1]: https://github.com/lightning/blips/blob/master/blip-0051.md
314+ pub fn set_liquidity_source_lsps1 (
315+ & mut self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
316+ ) -> & mut Self {
317+ // Mark the LSP as trusted for 0conf
318+ self . config . trusted_peers_0conf . push ( node_id. clone ( ) ) ;
319+
320+ let liquidity_source_config =
321+ self . liquidity_source_config . get_or_insert ( LiquiditySourceConfig :: default ( ) ) ;
322+ liquidity_source_config. lsps1_service = Some ( ( node_id, address, token) ) ;
323+ self
324+ }
325+
326+ /// Configures the [`Node`] instance to source just-in-time inbound liquidity from the given
327+ /// [bLIP-52 / LSPS2] service.
310328 ///
311329 /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
312330 ///
313331 /// The given `token` will be used by the LSP to authenticate the user.
332+ ///
333+ /// [bLIP-52 / LSPS2]: https://github.com/lightning/blips/blob/master/blip-0052.md
314334 pub fn set_liquidity_source_lsps2 (
315- & mut self , address : SocketAddress , node_id : PublicKey , token : Option < String > ,
335+ & mut self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
316336 ) -> & mut Self {
317337 // Mark the LSP as trusted for 0conf
318338 self . config . trusted_peers_0conf . push ( node_id. clone ( ) ) ;
319339
320340 let liquidity_source_config =
321341 self . liquidity_source_config . get_or_insert ( LiquiditySourceConfig :: default ( ) ) ;
322- liquidity_source_config. lsps2_service = Some ( ( address , node_id , token) ) ;
342+ liquidity_source_config. lsps2_service = Some ( ( node_id , address , token) ) ;
323343 self
324344 }
325345
@@ -643,17 +663,32 @@ impl ArcedNodeBuilder {
643663 self . inner . write ( ) . unwrap ( ) . set_gossip_source_rgs ( rgs_server_url) ;
644664 }
645665
646- /// Configures the [`Node`] instance to source its inbound liquidity from the given
647- /// [LSPS2](https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md)
648- /// service.
666+ /// Configures the [`Node`] instance to source inbound liquidity from the given
667+ /// [bLIP-51 / LSPS1] service.
649668 ///
650669 /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
651670 ///
652671 /// The given `token` will be used by the LSP to authenticate the user.
672+ ///
673+ /// [bLIP-51 / LSPS1]: https://github.com/lightning/blips/blob/master/blip-0051.md
674+ pub fn set_liquidity_source_lsps1 (
675+ & self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
676+ ) {
677+ self . inner . write ( ) . unwrap ( ) . set_liquidity_source_lsps1 ( node_id, address, token) ;
678+ }
679+
680+ /// Configures the [`Node`] instance to source just-in-time inbound liquidity from the given
681+ /// [bLIP-52 / LSPS2] service.
682+ ///
683+ /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
684+ ///
685+ /// The given `token` will be used by the LSP to authenticate the user.
686+ ///
687+ /// [bLIP-52 / LSPS2]: https://github.com/lightning/blips/blob/master/blip-0052.md
653688 pub fn set_liquidity_source_lsps2 (
654- & self , address : SocketAddress , node_id : PublicKey , token : Option < String > ,
689+ & self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
655690 ) {
656- self . inner . write ( ) . unwrap ( ) . set_liquidity_source_lsps2 ( address , node_id , token) ;
691+ self . inner . write ( ) . unwrap ( ) . set_liquidity_source_lsps2 ( node_id , address , token) ;
657692 }
658693
659694 /// Sets the used storage directory path.
@@ -1136,30 +1171,24 @@ fn build_with_store_internal(
11361171 } ,
11371172 } ;
11381173
1139- let liquidity_source = liquidity_source_config. as_ref ( ) . and_then ( |lsc| {
1140- lsc. lsps2_service . as_ref ( ) . map ( |( address, node_id, token) | {
1141- let lsps2_client_config = Some ( LSPS2ClientConfig { } ) ;
1142- let liquidity_client_config =
1143- Some ( LiquidityClientConfig { lsps1_client_config : None , lsps2_client_config } ) ;
1144- let liquidity_manager = Arc :: new ( LiquidityManager :: new (
1145- Arc :: clone ( & keys_manager) ,
1146- Arc :: clone ( & channel_manager) ,
1147- Some ( Arc :: clone ( & chain_source) ) ,
1148- None ,
1149- None ,
1150- liquidity_client_config,
1151- ) ) ;
1152- Arc :: new ( LiquiditySource :: new_lsps2 (
1153- address. clone ( ) ,
1154- * node_id,
1155- token. clone ( ) ,
1156- Arc :: clone ( & channel_manager) ,
1157- Arc :: clone ( & keys_manager) ,
1158- liquidity_manager,
1159- Arc :: clone ( & config) ,
1160- Arc :: clone ( & logger) ,
1161- ) )
1162- } )
1174+ let liquidity_source = liquidity_source_config. as_ref ( ) . map ( |lsc| {
1175+ let mut liquidity_source_builder = LiquiditySourceBuilder :: new (
1176+ Arc :: clone ( & channel_manager) ,
1177+ Arc :: clone ( & keys_manager) ,
1178+ Arc :: clone ( & chain_source) ,
1179+ Arc :: clone ( & config) ,
1180+ Arc :: clone ( & logger) ,
1181+ ) ;
1182+
1183+ lsc. lsps1_service . as_ref ( ) . map ( |( node_id, address, token) | {
1184+ liquidity_source_builder. lsps1_service ( * node_id, address. clone ( ) , token. clone ( ) )
1185+ } ) ;
1186+
1187+ lsc. lsps2_service . as_ref ( ) . map ( |( node_id, address, token) | {
1188+ liquidity_source_builder. lsps2_service ( * node_id, address. clone ( ) , token. clone ( ) )
1189+ } ) ;
1190+
1191+ Arc :: new ( liquidity_source_builder. build ( ) )
11631192 } ) ;
11641193
11651194 let custom_message_handler = if let Some ( liquidity_source) = liquidity_source. as_ref ( ) {
0 commit comments