@@ -88,7 +88,7 @@ pub(crate) struct LSPS2ClientConfig {
8888}
8989
9090struct LSPS2Service {
91- service_config : LSPS2ServiceConfig ,
91+ service_config : Arc < RwLock < LSPS2ServiceConfig > > ,
9292 ldk_service_config : LdkLSPS2ServiceConfig ,
9393}
9494
@@ -130,6 +130,65 @@ pub struct LSPS2ServiceConfig {
130130 pub max_payment_size_msat : u64 ,
131131}
132132
133+ /// Represents a partial update to the LSPS2 service configuration.
134+ ///
135+ /// Only fields set to `Some` will be updated; fields set to `None` will be ignored.
136+ #[ derive( Debug , Clone , Default ) ]
137+ pub struct LSPS2ServiceConfigUpdate {
138+ /// Update the required token (None to remove, Some to set).
139+ pub require_token : Option < Option < String > > ,
140+ /// Update whether the service should be advertised.
141+ pub advertise_service : Option < bool > ,
142+ /// Update the channel opening fee in parts-per-million.
143+ pub channel_opening_fee_ppm : Option < u32 > ,
144+ /// Update the proportional overprovisioning for the channel.
145+ pub channel_over_provisioning_ppm : Option < u32 > ,
146+ /// Update the minimum fee required for opening a channel.
147+ pub min_channel_opening_fee_msat : Option < u64 > ,
148+ /// Update the minimum number of blocks to keep the channel open.
149+ pub min_channel_lifetime : Option < u32 > ,
150+ /// Update the maximum client to_self_delay.
151+ pub max_client_to_self_delay : Option < u32 > ,
152+ /// Update the minimum payment size.
153+ pub min_payment_size_msat : Option < u64 > ,
154+ /// Update the maximum payment size.
155+ pub max_payment_size_msat : Option < u64 > ,
156+ }
157+
158+ impl LSPS2ServiceConfig {
159+ /// Applies a partial update to the configuration.
160+ /// Only fields present in `update` (i.e., `Some`) will be changed.
161+ pub fn apply_update ( & mut self , update : LSPS2ServiceConfigUpdate ) {
162+ if let Some ( require_token) = update. require_token {
163+ self . require_token = require_token;
164+ }
165+ if let Some ( advertise_service) = update. advertise_service {
166+ self . advertise_service = advertise_service;
167+ }
168+ if let Some ( channel_opening_fee_ppm) = update. channel_opening_fee_ppm {
169+ self . channel_opening_fee_ppm = channel_opening_fee_ppm;
170+ }
171+ if let Some ( channel_over_provisioning_ppm) = update. channel_over_provisioning_ppm {
172+ self . channel_over_provisioning_ppm = channel_over_provisioning_ppm;
173+ }
174+ if let Some ( min_channel_opening_fee_msat) = update. min_channel_opening_fee_msat {
175+ self . min_channel_opening_fee_msat = min_channel_opening_fee_msat;
176+ }
177+ if let Some ( min_channel_lifetime) = update. min_channel_lifetime {
178+ self . min_channel_lifetime = min_channel_lifetime;
179+ }
180+ if let Some ( max_client_to_self_delay) = update. max_client_to_self_delay {
181+ self . max_client_to_self_delay = max_client_to_self_delay;
182+ }
183+ if let Some ( min_payment_size_msat) = update. min_payment_size_msat {
184+ self . min_payment_size_msat = min_payment_size_msat;
185+ }
186+ if let Some ( max_payment_size_msat) = update. max_payment_size_msat {
187+ self . max_payment_size_msat = max_payment_size_msat;
188+ }
189+ }
190+ }
191+
133192pub ( crate ) struct LiquiditySourceBuilder < L : Deref >
134193where
135194 L :: Target : LdkLogger ,
@@ -212,16 +271,29 @@ where
212271 & mut self , promise_secret : [ u8 ; 32 ] , service_config : LSPS2ServiceConfig ,
213272 ) -> & mut Self {
214273 let ldk_service_config = LdkLSPS2ServiceConfig { promise_secret } ;
215- self . lsps2_service = Some ( LSPS2Service { service_config, ldk_service_config } ) ;
274+ self . lsps2_service = Some ( LSPS2Service {
275+ service_config : Arc :: new ( RwLock :: new ( service_config) ) ,
276+ ldk_service_config,
277+ } ) ;
216278 self
217279 }
218280
219281 pub ( crate ) async fn build ( self ) -> Result < LiquiditySource < L > , BuildError > {
220- let liquidity_service_config = self . lsps2_service . as_ref ( ) . map ( |s| {
282+ let liquidity_service_config = self . lsps2_service . as_ref ( ) . and_then ( |s| {
221283 let lsps2_service_config = Some ( s. ldk_service_config . clone ( ) ) ;
222284 let lsps5_service_config = None ;
223- let advertise_service = s. service_config . advertise_service ;
224- LiquidityServiceConfig { lsps2_service_config, lsps5_service_config, advertise_service }
285+ let advertise_service = match s. service_config . read ( ) {
286+ Ok ( cfg) => cfg. advertise_service ,
287+ Err ( e) => {
288+ log_error ! ( self . logger, "Failed to acquire LSPS2 service config lock: {:?}" , e) ;
289+ return None ;
290+ } ,
291+ } ;
292+ Some ( LiquidityServiceConfig {
293+ lsps2_service_config,
294+ lsps5_service_config,
295+ advertise_service,
296+ } )
225297 } ) ;
226298
227299 let lsps1_client_config = self . lsps1_client . as_ref ( ) . map ( |s| s. ldk_client_config . clone ( ) ) ;
@@ -299,6 +371,34 @@ where
299371 self . lsps2_client . as_ref ( ) . map ( |s| ( s. lsp_node_id , s. lsp_address . clone ( ) ) )
300372 }
301373
374+ pub ( crate ) fn update_lsps2_service_config_partial (
375+ & self , update : LSPS2ServiceConfigUpdate ,
376+ ) -> Result < ( ) , Error > {
377+ if let Some ( lsps2_service) = self . lsps2_service . as_ref ( ) {
378+ if let Ok ( mut config) = lsps2_service. service_config . write ( ) {
379+ config. apply_update ( update) ;
380+ log_info ! ( self . logger, "Partially updated LSPS2 service configuration." ) ;
381+ Ok ( ( ) )
382+ } else {
383+ log_error ! ( self . logger, "Failed to acquire LSPS2 service config lock." ) ;
384+ Err ( Error :: InvalidLSP2Config )
385+ }
386+ } else {
387+ log_error ! (
388+ self . logger,
389+ "Failed to update LSPS2 service config as LSPS2 service was not configured."
390+ ) ;
391+ Err ( Error :: LSP2ServiceNotConfigured )
392+ }
393+ }
394+
395+ fn get_lsps2_service_config ( & self ) -> Option < LSPS2ServiceConfig > {
396+ self . lsps2_service
397+ . as_ref ( )
398+ . and_then ( |s| s. service_config . read ( ) . ok ( ) )
399+ . map ( |cfg| cfg. clone ( ) ) // Clone to release lock
400+ }
401+
302402 pub ( crate ) async fn handle_next_event ( & self ) {
303403 match self . liquidity_manager . next_event_async ( ) . await {
304404 LiquidityEvent :: LSPS1Client ( LSPS1ClientEvent :: SupportedOptionsReady {
@@ -479,7 +579,7 @@ where
479579 self . liquidity_manager . lsps2_service_handler ( ) . as_ref ( )
480580 {
481581 let service_config = if let Some ( service_config) =
482- self . lsps2_service . as_ref ( ) . map ( |s| s . service_config . clone ( ) )
582+ self . get_lsps2_service_config ( )
483583 {
484584 service_config
485585 } else {
@@ -548,7 +648,7 @@ where
548648 self . liquidity_manager . lsps2_service_handler ( ) . as_ref ( )
549649 {
550650 let service_config = if let Some ( service_config) =
551- self . lsps2_service . as_ref ( ) . map ( |s| s . service_config . clone ( ) )
651+ self . get_lsps2_service_config ( )
552652 {
553653 service_config
554654 } else {
@@ -620,9 +720,7 @@ where
620720 return ;
621721 } ;
622722
623- let service_config = if let Some ( service_config) =
624- self . lsps2_service . as_ref ( ) . map ( |s| s. service_config . clone ( ) )
625- {
723+ let service_config = if let Some ( service_config) = self . get_lsps2_service_config ( ) {
626724 service_config
627725 } else {
628726 log_error ! ( self . logger, "Failed to handle LSPS2ServiceEvent as LSPS2 liquidity service was not configured." , ) ;
0 commit comments