Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit eb8de4b

Browse files
committed
Try to connect to LSP before changing
1 parent 7f1a4fa commit eb8de4b

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

mutiny-core/src/lsp/voltage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl LspClient {
147147
}
148148

149149
/// Get the pubkey and connection string from the LSP from the /info endpoint
150-
async fn fetch_connection_info(
150+
pub(crate) async fn fetch_connection_info(
151151
http_client: &Client,
152152
url: &str,
153153
logger: &MutinyLogger,

mutiny-core/src/nodemanager.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::labels::LabelStorage;
22
use crate::ldkstorage::CHANNEL_CLOSURE_PREFIX;
33
use crate::logging::LOGGING_KEY;
4+
use crate::lsp::voltage;
45
use crate::utils::{sleep, spawn};
56
use crate::MutinyInvoice;
67
use 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

Comments
 (0)