@@ -65,9 +65,7 @@ use crate::io::{
6565 PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
6666 PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
6767} ;
68- use crate :: liquidity:: {
69- LSPS1ClientConfig , LSPS2ClientConfig , LSPS2ServiceConfig , LiquiditySourceBuilder ,
70- } ;
68+ use crate :: liquidity:: { LSPS2ServiceConfig , LiquiditySourceBuilder , LspConfig } ;
7169use crate :: lnurl_auth:: LnurlAuth ;
7270use crate :: logger:: { log_error, LdkLogger , LogLevel , LogWriter , Logger } ;
7371use crate :: message_handler:: NodeCustomMessageHandler ;
@@ -120,10 +118,8 @@ struct PathfindingScoresSyncConfig {
120118
121119#[ derive( Debug , Clone , Default ) ]
122120struct LiquiditySourceConfig {
123- // Act as an LSPS1 client connecting to the given service.
124- lsps1_client : Option < LSPS1ClientConfig > ,
125- // Act as an LSPS2 client connecting to the given service.
126- lsps2_client : Option < LSPS2ClientConfig > ,
121+ // Acts for both LSPS1 and LSPS2 clients connecting to the given service.
122+ lsp_nodes : Vec < LspConfig > ,
127123 // Act as an LSPS2 service.
128124 lsps2_service : Option < LSPS2ServiceConfig > ,
129125}
@@ -440,17 +436,12 @@ impl NodeBuilder {
440436 /// The given `token` will be used by the LSP to authenticate the user.
441437 ///
442438 /// [bLIP-51 / LSPS1]: https://github.com/lightning/blips/blob/master/blip-0051.md
439+ #[ deprecated( note = "Use `add_lsp` instead" ) ]
440+ #[ allow( dead_code) ]
443441 pub fn set_liquidity_source_lsps1 (
444442 & mut self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
445443 ) -> & mut Self {
446- // Mark the LSP as trusted for 0conf
447- self . config . trusted_peers_0conf . push ( node_id. clone ( ) ) ;
448-
449- let liquidity_source_config =
450- self . liquidity_source_config . get_or_insert ( LiquiditySourceConfig :: default ( ) ) ;
451- let lsps1_client_config = LSPS1ClientConfig { node_id, address, token } ;
452- liquidity_source_config. lsps1_client = Some ( lsps1_client_config) ;
453- self
444+ self . add_lsp ( node_id, address, token)
454445 }
455446
456447 /// Configures the [`Node`] instance to source just-in-time inbound liquidity from the given
@@ -461,16 +452,32 @@ impl NodeBuilder {
461452 /// The given `token` will be used by the LSP to authenticate the user.
462453 ///
463454 /// [bLIP-52 / LSPS2]: https://github.com/lightning/blips/blob/master/blip-0052.md
455+ #[ deprecated( note = "Use `add_lsp` instead" ) ]
456+ #[ allow( dead_code) ]
464457 pub fn set_liquidity_source_lsps2 (
465458 & mut self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
459+ ) -> & mut Self {
460+ self . add_lsp ( node_id, address, token)
461+ }
462+
463+ /// Configures the [`Node`] instance to source inbound liquidity from the given LSP, without specifying
464+ /// the exact protocol used (e.g., LSPS1 or LSPS2).
465+ ///
466+ /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
467+ ///
468+ /// The given `token` will be used by the LSP to authenticate the user.
469+ /// This method is useful when the user wants to connect to an LSP but does not want to be concerned with
470+ /// the specific protocol used for liquidity provision. The node will automatically detect and use the
471+ /// appropriate protocol supported by the LSP.
472+ pub fn add_lsp (
473+ & mut self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
466474 ) -> & mut Self {
467475 // Mark the LSP as trusted for 0conf
468- self . config . trusted_peers_0conf . push ( node_id . clone ( ) ) ;
476+ self . config . trusted_peers_0conf . write ( ) . unwrap ( ) . push ( node_id ) ;
469477
470478 let liquidity_source_config =
471479 self . liquidity_source_config . get_or_insert ( LiquiditySourceConfig :: default ( ) ) ;
472- let lsps2_client_config = LSPS2ClientConfig { node_id, address, token } ;
473- liquidity_source_config. lsps2_client = Some ( lsps2_client_config) ;
480+ liquidity_source_config. lsp_nodes . push ( LspConfig { node_id, address, token } ) ;
474481 self
475482 }
476483
@@ -964,7 +971,7 @@ impl ArcedNodeBuilder {
964971 pub fn set_liquidity_source_lsps1 (
965972 & self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
966973 ) {
967- self . inner . write ( ) . unwrap ( ) . set_liquidity_source_lsps1 ( node_id, address, token) ;
974+ self . inner . write ( ) . unwrap ( ) . add_lsp ( node_id, address, token) ;
968975 }
969976
970977 /// Configures the [`Node`] instance to source just-in-time inbound liquidity from the given
@@ -978,7 +985,20 @@ impl ArcedNodeBuilder {
978985 pub fn set_liquidity_source_lsps2 (
979986 & self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
980987 ) {
981- self . inner . write ( ) . unwrap ( ) . set_liquidity_source_lsps2 ( node_id, address, token) ;
988+ self . inner . write ( ) . unwrap ( ) . add_lsp ( node_id, address, token) ;
989+ }
990+
991+ /// Configures the [`Node`] instance to source inbound liquidity from the given LSP, without specifying
992+ /// the exact protocol used (e.g., LSPS1 or LSPS2).
993+ ///
994+ /// Will mark the LSP as trusted for 0-confirmation channels, see [`Config::trusted_peers_0conf`].
995+ ///
996+ /// The given `token` will be used by the LSP to authenticate the user.
997+ /// This method is useful when the user wants to connect to an LSP but does not want to be concerned with
998+ /// the specific protocol used for liquidity provision. The node will automatically detect and use the
999+ /// appropriate protocol supported by the LSP.
1000+ pub fn add_lsp ( & self , node_id : PublicKey , address : SocketAddress , token : Option < String > ) {
1001+ self . inner . write ( ) . unwrap ( ) . add_lsp ( node_id, address, token) ;
9821002 }
9831003
9841004 /// Configures the [`Node`] instance to provide an [LSPS2] service, issuing just-in-time
@@ -1803,21 +1823,7 @@ fn build_with_store_internal(
18031823 Arc :: clone ( & logger) ,
18041824 ) ;
18051825
1806- lsc. lsps1_client . as_ref ( ) . map ( |config| {
1807- liquidity_source_builder. lsps1_client (
1808- config. node_id ,
1809- config. address . clone ( ) ,
1810- config. token . clone ( ) ,
1811- )
1812- } ) ;
1813-
1814- lsc. lsps2_client . as_ref ( ) . map ( |config| {
1815- liquidity_source_builder. lsps2_client (
1816- config. node_id ,
1817- config. address . clone ( ) ,
1818- config. token . clone ( ) ,
1819- )
1820- } ) ;
1826+ liquidity_source_builder. set_lsp_nodes ( lsc. lsp_nodes . clone ( ) ) ;
18211827
18221828 let promise_secret = {
18231829 let lsps_xpriv = derive_xprv (
@@ -1886,7 +1892,9 @@ fn build_with_store_internal(
18861892 }
18871893 } ) ) ;
18881894
1889- liquidity_source. as_ref ( ) . map ( |l| l. set_peer_manager ( Arc :: downgrade ( & peer_manager) ) ) ;
1895+ liquidity_source
1896+ . as_ref ( )
1897+ . map ( |l| l. lsps2_service ( ) . set_peer_manager ( Arc :: downgrade ( & peer_manager) ) ) ;
18901898
18911899 let connection_manager = Arc :: new ( ConnectionManager :: new (
18921900 Arc :: clone ( & peer_manager) ,
0 commit comments