diff --git a/.gitignore b/.gitignore index 6c245b277..32c16236f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,3 @@ data/** # env file .env - -# coordinator settings -coordinator-settings.toml diff --git a/coordinator/src/bin/coordinator.rs b/coordinator/src/bin/coordinator.rs index 815b6a503..4ca70ef3c 100644 --- a/coordinator/src/bin/coordinator.rs +++ b/coordinator/src/bin/coordinator.rs @@ -69,7 +69,7 @@ async fn main() -> Result<()> { let seed_path = data_dir.join("seed"); let seed = Bip39Seed::initialize(&seed_path)?; - let settings = Settings::new().await; + let settings = Settings::new(&data_dir).await; let node = Arc::new( ln_dlc_node::node::Node::new_coordinator( diff --git a/coordinator/src/settings.rs b/coordinator/src/settings.rs index 405ffd06a..1a0cdc560 100644 --- a/coordinator/src/settings.rs +++ b/coordinator/src/settings.rs @@ -5,10 +5,11 @@ use ln_dlc_node::node::LnDlcNodeSettings; use serde::Deserialize; use serde::Serialize; use std::path::Path; +use std::path::PathBuf; use tokio::fs; use tokio::io::AsyncWriteExt; -const SETTINGS_FILE_PATH: &str = "coordinator-settings.toml"; +const SETTINGS_FILE_NAME: &str = "coordinator-settings.toml"; /// Top level settings #[derive(Debug, Clone, Deserialize, Serialize)] @@ -28,6 +29,8 @@ pub struct Settings { pub max_allowed_tx_fee_rate_when_opening_channel: Option, pub ln_dlc: LnDlcNodeSettings, + // Special parameter, where the settings file is located + pub path: Option, } impl Default for Settings { @@ -40,25 +43,31 @@ impl Default for Settings { fallback_tx_fee_rate_high_priority: 5000, max_allowed_tx_fee_rate_when_opening_channel: None, ln_dlc: LnDlcNodeSettings::default(), + path: None, } } } -async fn read_settings() -> Result { - let settings_path = Path::new(SETTINGS_FILE_PATH); +async fn read_settings(data_dir: &Path) -> Result { + let settings_path = data_dir.join(SETTINGS_FILE_NAME); let data = fs::read_to_string(settings_path).await?; toml::from_str(&data).context("Unable to parse settings file") } impl Settings { - pub async fn new() -> Self { - match read_settings().await { + pub async fn new(data_dir: &Path) -> Self { + match read_settings(data_dir).await { Ok(settings) => settings, Err(e) => { - tracing::warn!("Unable to read {SETTINGS_FILE_PATH} file, using defaults: {e}"); - let new = Settings::default(); + tracing::warn!("Unable to read {SETTINGS_FILE_NAME} file, using defaults: {e}"); + let new = Settings { + path: Some(data_dir.join(SETTINGS_FILE_NAME)), + ..Settings::default() + }; if let Err(e) = new.write_to_file().await { tracing::error!("Unable to write default settings to file: {e}"); + } else { + tracing::info!("Default settings written to file"); } new } @@ -69,7 +78,7 @@ impl Settings { let data = toml::to_string_pretty(&self).context("Unable to serialize settings to TOML format")?; - let settings_path = Path::new(SETTINGS_FILE_PATH); + let settings_path = self.path.as_ref().context("Settings path not set")?.clone(); let mut file = fs::File::create(settings_path).await?; file.write_all(data.as_bytes()).await?; file.flush().await?; diff --git a/crates/ln-dlc-node/src/ln_dlc_wallet.rs b/crates/ln-dlc-node/src/ln_dlc_wallet.rs index fed81d251..3b50c5427 100644 --- a/crates/ln-dlc-node/src/ln_dlc_wallet.rs +++ b/crates/ln-dlc-node/src/ln_dlc_wallet.rs @@ -31,14 +31,6 @@ use rust_bitcoin_coin_selection::select_coins; use simple_wallet::WalletStorage; use std::sync::Arc; -/// The 'stop gap' parameter used by BDK's wallet sync. This seems to configure the threshold -/// number of blocks after which BDK stops looking for scripts belonging to the wallet. -/// Note: This constant and value was copied from ldk_node -const BDK_CLIENT_STOP_GAP: usize = 20; -/// The number of concurrent requests made against the API provider. -/// Note: This constant and value was copied from ldk_node -const BDK_CLIENT_CONCURRENCY: u8 = 1; - /// This is a wrapper type introduced to be able to implement traits from `rust-dlc` on the /// `ldk_node::LightningWallet`. pub struct LnDlcWallet { @@ -56,10 +48,12 @@ impl LnDlcWallet { storage: Arc, seed: Bip39Seed, runtime_handle: tokio::runtime::Handle, + bdk_client_stop_gap: usize, + bdk_client_concurrency: u8, ) -> Self { let blockchain = - EsploraBlockchain::from_client(esplora_client.client().clone(), BDK_CLIENT_STOP_GAP) - .with_concurrency(BDK_CLIENT_CONCURRENCY); + EsploraBlockchain::from_client(esplora_client.client().clone(), bdk_client_stop_gap) + .with_concurrency(bdk_client_concurrency); let wallet = Arc::new(ldk_node_wallet::Wallet::new( blockchain, diff --git a/crates/ln-dlc-node/src/node/mod.rs b/crates/ln-dlc-node/src/node/mod.rs index d44ab71fc..91fa0811a 100644 --- a/crates/ln-dlc-node/src/node/mod.rs +++ b/crates/ln-dlc-node/src/node/mod.rs @@ -135,6 +135,16 @@ pub struct LnDlcNodeSettings { pub on_chain_sync_interval: Duration, /// How often we update the fee rate pub fee_rate_sync_interval: Duration, + + /// The 'stop gap' parameter used by BDK's wallet sync. This seems to configure the threshold + /// number of blocks after which BDK stops looking for scripts belonging to the wallet. + /// Note: This constant and value was copied from ldk_node + /// XXX: Requires restart of the node to take effect + pub bdk_client_stop_gap: usize, + /// The number of concurrent requests made against the API provider. + /// Note: This constant and value was copied from ldk_node + /// XXX: Requires restart of the node to take effect + pub bdk_client_concurrency: u8, } impl Default for LnDlcNodeSettings { @@ -143,6 +153,8 @@ impl Default for LnDlcNodeSettings { off_chain_sync_interval: Duration::from_secs(5), on_chain_sync_interval: Duration::from_secs(300), fee_rate_sync_interval: Duration::from_secs(20), + bdk_client_stop_gap: 20, + bdk_client_concurrency: 1, } } } @@ -278,6 +290,8 @@ where storage.clone(), seed.clone(), runtime_handle.clone(), + settings.bdk_client_stop_gap, + settings.bdk_client_concurrency, )) };