@@ -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 {
99+ // LSPS1 service's (node_id, address, token)
100+ lsps1_service : Option < ( PublicKey , SocketAddress , Option < String > ) > ,
102101 // LSPS2 service's (node_id, address, token)
103102 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
@@ -302,13 +301,34 @@ impl NodeBuilder {
302301 self
303302 }
304303
305- /// Configures the [`Node`] instance to source its inbound liquidity from the given
306- /// [LSPS2](https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md)
307- /// service.
304+ /// Configures the [`Node`] instance to source inbound liquidity from the given
305+ /// [bLIP-51 / LSPS1] service.
308306 ///
309307 /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
310308 ///
311309 /// The given `token` will be used by the LSP to authenticate the user.
310+ ///
311+ /// [bLIP-51 / LSPS1]: https://github.com/lightning/blips/blob/master/blip-0051.md
312+ pub fn set_liquidity_source_lsps1 (
313+ & mut self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
314+ ) -> & mut Self {
315+ // Mark the LSP as trusted for 0conf
316+ self . config . trusted_peers_0conf . push ( node_id. clone ( ) ) ;
317+
318+ let liquidity_source_config =
319+ self . liquidity_source_config . get_or_insert ( LiquiditySourceConfig :: default ( ) ) ;
320+ liquidity_source_config. lsps1_service = Some ( ( node_id, address, token) ) ;
321+ self
322+ }
323+
324+ /// Configures the [`Node`] instance to source just-in-time inbound liquidity from the given
325+ /// [bLIP-52 / LSPS2] service.
326+ ///
327+ /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
328+ ///
329+ /// The given `token` will be used by the LSP to authenticate the user.
330+ ///
331+ /// [bLIP-52 / LSPS2]: https://github.com/lightning/blips/blob/master/blip-0052.md
312332 pub fn set_liquidity_source_lsps2 (
313333 & mut self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
314334 ) -> & mut Self {
@@ -636,13 +656,28 @@ impl ArcedNodeBuilder {
636656 self . inner . write ( ) . unwrap ( ) . set_gossip_source_rgs ( rgs_server_url) ;
637657 }
638658
639- /// Configures the [`Node`] instance to source its inbound liquidity from the given
640- /// [LSPS2](https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md)
641- /// service.
659+ /// Configures the [`Node`] instance to source inbound liquidity from the given
660+ /// [bLIP-51 / LSPS1] service.
642661 ///
643662 /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
644663 ///
645664 /// The given `token` will be used by the LSP to authenticate the user.
665+ ///
666+ /// [bLIP-51 / LSPS1]: https://github.com/lightning/blips/blob/master/blip-0051.md
667+ pub fn set_liquidity_source_lsps1 (
668+ & self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
669+ ) {
670+ self . inner . write ( ) . unwrap ( ) . set_liquidity_source_lsps1 ( node_id, address, token) ;
671+ }
672+
673+ /// Configures the [`Node`] instance to source just-in-time inbound liquidity from the given
674+ /// [bLIP-52 / LSPS2] service.
675+ ///
676+ /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
677+ ///
678+ /// The given `token` will be used by the LSP to authenticate the user.
679+ ///
680+ /// [bLIP-52 / LSPS2]: https://github.com/lightning/blips/blob/master/blip-0052.md
646681 pub fn set_liquidity_source_lsps2 (
647682 & self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
648683 ) {
@@ -1124,30 +1159,24 @@ fn build_with_store_internal(
11241159 } ,
11251160 } ;
11261161
1127- let liquidity_source = liquidity_source_config. as_ref ( ) . and_then ( |lsc| {
1162+ let liquidity_source = liquidity_source_config. as_ref ( ) . map ( |lsc| {
1163+ let mut liquidity_source_builder = LiquiditySourceBuilder :: new (
1164+ Arc :: clone ( & channel_manager) ,
1165+ Arc :: clone ( & keys_manager) ,
1166+ Arc :: clone ( & chain_source) ,
1167+ Arc :: clone ( & config) ,
1168+ Arc :: clone ( & logger) ,
1169+ ) ;
1170+
1171+ lsc. lsps1_service . as_ref ( ) . map ( |( node_id, address, token) | {
1172+ liquidity_source_builder. lsps1_service ( * node_id, address. clone ( ) , token. clone ( ) )
1173+ } ) ;
1174+
11281175 lsc. lsps2_service . as_ref ( ) . map ( |( node_id, address, token) | {
1129- let lsps2_client_config = Some ( LSPS2ClientConfig { } ) ;
1130- let liquidity_client_config =
1131- Some ( LiquidityClientConfig { lsps1_client_config : None , lsps2_client_config } ) ;
1132- let liquidity_manager = Arc :: new ( LiquidityManager :: new (
1133- Arc :: clone ( & keys_manager) ,
1134- Arc :: clone ( & channel_manager) ,
1135- Some ( Arc :: clone ( & chain_source) ) ,
1136- None ,
1137- None ,
1138- liquidity_client_config,
1139- ) ) ;
1140- Arc :: new ( LiquiditySource :: new_lsps2 (
1141- * node_id,
1142- address. clone ( ) ,
1143- token. clone ( ) ,
1144- Arc :: clone ( & channel_manager) ,
1145- Arc :: clone ( & keys_manager) ,
1146- liquidity_manager,
1147- Arc :: clone ( & config) ,
1148- Arc :: clone ( & logger) ,
1149- ) )
1150- } )
1176+ liquidity_source_builder. lsps2_service ( * node_id, address. clone ( ) , token. clone ( ) )
1177+ } ) ;
1178+
1179+ Arc :: new ( liquidity_source_builder. build ( ) )
11511180 } ) ;
11521181
11531182 let custom_message_handler = if let Some ( liquidity_source) = liquidity_source. as_ref ( ) {
0 commit comments