11use crate :: labels:: LabelStorage ;
22use crate :: ldkstorage:: CHANNEL_CLOSURE_PREFIX ;
33use crate :: logging:: LOGGING_KEY ;
4+ use crate :: lsp:: voltage;
45use crate :: utils:: { sleep, spawn} ;
56use crate :: MutinyInvoice ;
67use crate :: MutinyWalletConfig ;
@@ -1347,7 +1348,7 @@ impl<S: MutinyStorage> NodeManager<S> {
13471348 /// current LSP, it will fail to change the LSP.
13481349 ///
13491350 /// Requires a restart of the node manager to take effect.
1350- pub async fn change_lsp ( & self , lsp_config : Option < LspConfig > ) -> Result < ( ) , MutinyError > {
1351+ pub async fn change_lsp ( & self , mut lsp_config : Option < LspConfig > ) -> Result < ( ) , MutinyError > {
13511352 log_trace ! ( self . logger, "calling change_lsp" ) ;
13521353
13531354 // if we are in safe mode we don't load the lightning state so we can't know if it is safe to change the LSP.
@@ -1371,6 +1372,28 @@ impl<S: MutinyStorage> NodeManager<S> {
13711372 }
13721373 drop ( nodes) ;
13731374
1375+ // verify that the LSP config is valid
1376+ match lsp_config. as_mut ( ) {
1377+ Some ( LspConfig :: VoltageFlow ( config) ) => {
1378+ let http_client = Client :: new ( ) ;
1379+
1380+ // try to connect to the LSP, update the config if successful
1381+ let ( pk, str) = voltage:: LspClient :: fetch_connection_info (
1382+ & http_client,
1383+ & config. url ,
1384+ & self . logger ,
1385+ )
1386+ . await ?;
1387+ config. pubkey = Some ( pk) ;
1388+ config. connection_string = Some ( str) ;
1389+ }
1390+ Some ( LspConfig :: Lsps ( config) ) => {
1391+ // make sure a valid connection string was provided
1392+ PubkeyConnectionInfo :: new ( & config. connection_string ) ?;
1393+ }
1394+ None => { } // Nothing to verify
1395+ }
1396+
13741397 // edit node storage
13751398 let mut node_storage = self . node_storage . write ( ) . await ;
13761399 node_storage. nodes . iter_mut ( ) . for_each ( |( _, n) | {
0 commit comments