@@ -18,7 +18,9 @@ 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:: { LSPS1ClientConfig , LSPS2ClientConfig , LiquiditySourceBuilder } ;
21+ use crate :: liquidity:: {
22+ LSPS1ClientConfig , LSPS2ClientConfig , LSPS2ServiceConfig , LiquiditySourceBuilder ,
23+ } ;
2224use crate :: logger:: { log_error, log_info, LdkLogger , LogLevel , LogWriter , Logger } ;
2325use crate :: message_handler:: NodeCustomMessageHandler ;
2426use crate :: payment:: store:: PaymentStore ;
@@ -77,6 +79,7 @@ use vss_client::headers::{FixedHeaders, LnurlAuthToJwtProvider, VssHeaderProvide
7779
7880const VSS_HARDENED_CHILD_INDEX : u32 = 877 ;
7981const VSS_LNURL_AUTH_HARDENED_CHILD_INDEX : u32 = 138 ;
82+ const LSPS_HARDENED_CHILD_INDEX : u32 = 577 ;
8083
8184#[ derive( Debug , Clone ) ]
8285enum ChainDataSourceConfig {
@@ -103,6 +106,8 @@ struct LiquiditySourceConfig {
103106 lsps1_client : Option < LSPS1ClientConfig > ,
104107 // Act as an LSPS2 client connecting to the given service.
105108 lsps2_client : Option < LSPS2ClientConfig > ,
109+ // Act as an LSPS2 service.
110+ lsps2_service : Option < LSPS2ServiceConfig > ,
106111}
107112
108113#[ derive( Clone ) ]
@@ -340,6 +345,21 @@ impl NodeBuilder {
340345 self
341346 }
342347
348+ /// Configures the [`Node`] instance to provide an [LSPS2] service, issuing just-in-time
349+ /// channels to clients.
350+ ///
351+ /// **Caution**: LSP service support is in **alpha** and is considered an experimental feature.
352+ ///
353+ /// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
354+ pub fn set_liquidity_provider_lsps2 (
355+ & mut self , service_config : LSPS2ServiceConfig ,
356+ ) -> & mut Self {
357+ let liquidity_source_config =
358+ self . liquidity_source_config . get_or_insert ( LiquiditySourceConfig :: default ( ) ) ;
359+ liquidity_source_config. lsps2_service = Some ( service_config) ;
360+ self
361+ }
362+
343363 /// Sets the used storage directory path.
344364 pub fn set_storage_dir_path ( & mut self , storage_dir_path : String ) -> & mut Self {
345365 self . config . storage_dir_path = storage_dir_path;
@@ -692,6 +712,16 @@ impl ArcedNodeBuilder {
692712 self . inner . write ( ) . unwrap ( ) . set_liquidity_source_lsps2 ( node_id, address, token) ;
693713 }
694714
715+ /// Configures the [`Node`] instance to provide an [LSPS2] service, issuing just-in-time
716+ /// channels to clients.
717+ ///
718+ /// **Caution**: LSP service support is in **alpha** and is considered an experimental feature.
719+ ///
720+ /// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
721+ pub fn set_liquidity_provider_lsps2 ( & self , service_config : LSPS2ServiceConfig ) {
722+ self . inner . write ( ) . unwrap ( ) . set_liquidity_provider_lsps2 ( service_config) ;
723+ }
724+
695725 /// Sets the used storage directory path.
696726 pub fn set_storage_dir_path ( & self , storage_dir_path : String ) {
697727 self . inner . write ( ) . unwrap ( ) . set_storage_dir_path ( storage_dir_path) ;
@@ -1167,39 +1197,52 @@ fn build_with_store_internal(
11671197 } ,
11681198 } ;
11691199
1170- let liquidity_source = liquidity_source_config. as_ref ( ) . map ( |lsc| {
1171- let mut liquidity_source_builder = LiquiditySourceBuilder :: new (
1172- Arc :: clone ( & channel_manager) ,
1173- Arc :: clone ( & keys_manager) ,
1174- Arc :: clone ( & chain_source) ,
1175- Arc :: clone ( & config) ,
1176- Arc :: clone ( & logger) ,
1177- ) ;
1178-
1179- lsc. lsps1_client . as_ref ( ) . map ( |config| {
1180- liquidity_source_builder. lsps1_client (
1181- config. node_id ,
1182- config. address . clone ( ) ,
1183- config. token . clone ( ) ,
1184- )
1185- } ) ;
1200+ let ( liquidity_source, custom_message_handler) =
1201+ if let Some ( lsc) = liquidity_source_config. as_ref ( ) {
1202+ let mut liquidity_source_builder = LiquiditySourceBuilder :: new (
1203+ Arc :: clone ( & channel_manager) ,
1204+ Arc :: clone ( & keys_manager) ,
1205+ Arc :: clone ( & chain_source) ,
1206+ Arc :: clone ( & config) ,
1207+ Arc :: clone ( & logger) ,
1208+ ) ;
11861209
1187- lsc. lsps2_client . as_ref ( ) . map ( |config| {
1188- liquidity_source_builder. lsps2_client (
1189- config. node_id ,
1190- config. address . clone ( ) ,
1191- config. token . clone ( ) ,
1192- )
1193- } ) ;
1210+ lsc. lsps1_client . as_ref ( ) . map ( |config| {
1211+ liquidity_source_builder. lsps1_client (
1212+ config. node_id ,
1213+ config. address . clone ( ) ,
1214+ config. token . clone ( ) ,
1215+ )
1216+ } ) ;
11941217
1195- Arc :: new ( liquidity_source_builder. build ( ) )
1196- } ) ;
1218+ lsc. lsps2_client . as_ref ( ) . map ( |config| {
1219+ liquidity_source_builder. lsps2_client (
1220+ config. node_id ,
1221+ config. address . clone ( ) ,
1222+ config. token . clone ( ) ,
1223+ )
1224+ } ) ;
11971225
1198- let custom_message_handler = if let Some ( liquidity_source) = liquidity_source. as_ref ( ) {
1199- Arc :: new ( NodeCustomMessageHandler :: new_liquidity ( Arc :: clone ( & liquidity_source) ) )
1200- } else {
1201- Arc :: new ( NodeCustomMessageHandler :: new_ignoring ( ) )
1202- } ;
1226+ let promise_secret = {
1227+ let lsps_xpriv = derive_xprv (
1228+ Arc :: clone ( & config) ,
1229+ & seed_bytes,
1230+ LSPS_HARDENED_CHILD_INDEX ,
1231+ Arc :: clone ( & logger) ,
1232+ ) ?;
1233+ lsps_xpriv. private_key . secret_bytes ( )
1234+ } ;
1235+ lsc. lsps2_service . as_ref ( ) . map ( |config| {
1236+ liquidity_source_builder. lsps2_service ( promise_secret, config. clone ( ) )
1237+ } ) ;
1238+
1239+ let liquidity_source = Arc :: new ( liquidity_source_builder. build ( ) ) ;
1240+ let custom_message_handler =
1241+ Arc :: new ( NodeCustomMessageHandler :: new_liquidity ( Arc :: clone ( & liquidity_source) ) ) ;
1242+ ( Some ( liquidity_source) , custom_message_handler)
1243+ } else {
1244+ ( None , Arc :: new ( NodeCustomMessageHandler :: new_ignoring ( ) ) )
1245+ } ;
12031246
12041247 let msg_handler = match gossip_source. as_gossip_sync ( ) {
12051248 GossipSync :: P2P ( p2p_gossip_sync) => MessageHandler {
0 commit comments