ASB config may specify finality confirmations

By default the finality confirmations of the network's `env::Config` will be applied and no finality confirmations will be persisted on disk in the config file.
It is however possible to set finality confirmations in the config file for bitcoin and monero for power users at their own risk.
If set the defaults will be overwritten with the parameter from the config file upon startup.
This commit is contained in:
Daniel Karzel 2021-05-12 11:25:45 +10:00
parent 7ec323ea1f
commit 7f8af7926d
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
3 changed files with 35 additions and 6 deletions

View File

@ -293,10 +293,12 @@ pub fn query_user_for_initial_config(testnet: bool) -> Result<Config> {
bitcoin: Bitcoin {
electrum_rpc_url,
target_block,
finality_confirmations: None,
network: bitcoin_network,
},
monero: Monero {
wallet_rpc_url: monero_wallet_rpc_url,
finality_confirmations: None,
network: monero_network,
},
tor: TorConf {
@ -330,6 +332,7 @@ mod tests {
bitcoin: Bitcoin {
electrum_rpc_url: defaults.electrum_rpc_url,
target_block: defaults.bitcoin_confirmation_target,
finality_confirmations: None,
network: bitcoin::Network::Testnet,
},
network: Network {
@ -338,6 +341,7 @@ mod tests {
monero: Monero {
wallet_rpc_url: defaults.monero_wallet_rpc_url,
finality_confirmations: None,
network: monero::Network::Stagenet,
},
tor: Default::default(),
@ -368,6 +372,7 @@ mod tests {
bitcoin: Bitcoin {
electrum_rpc_url: defaults.electrum_rpc_url,
target_block: defaults.bitcoin_confirmation_target,
finality_confirmations: None,
network: bitcoin::Network::Bitcoin,
},
network: Network {
@ -376,6 +381,7 @@ mod tests {
monero: Monero {
wallet_rpc_url: defaults.monero_wallet_rpc_url,
finality_confirmations: None,
network: monero::Network::Mainnet,
},
tor: Default::default(),

View File

@ -26,7 +26,6 @@ use swap::asb::config::{
GetDefaults,
};
use swap::database::Database;
use swap::env::GetConfig;
use swap::monero::Amount;
use swap::network::swarm;
use swap::protocol::alice;
@ -69,11 +68,7 @@ async fn main() -> Result<()> {
}
};
let env_config = if testnet {
env::Testnet::get_config()
} else {
env::Mainnet::get_config()
};
let env_config = env::new(testnet, &config);
if config.monero.network != env_config.monero_network {
bail!(format!(

View File

@ -1,3 +1,4 @@
use crate::asb;
use crate::bitcoin::{CancelTimelock, PunishTimelock};
use std::cmp::max;
use std::time::Duration;
@ -91,6 +92,33 @@ fn sync_interval(avg_block_time: Duration) -> Duration {
max(avg_block_time / 10, Duration::from_secs(1))
}
pub fn new(is_testnet: bool, asb_config: &asb::config::Config) -> Config {
let env_config = if is_testnet {
Testnet::get_config()
} else {
Mainnet::get_config()
};
let env_config =
if let Some(bitcoin_finality_confirmations) = asb_config.bitcoin.finality_confirmations {
Config {
bitcoin_finality_confirmations,
..env_config
}
} else {
env_config
};
if let Some(monero_finality_confirmations) = asb_config.monero.finality_confirmations {
Config {
monero_finality_confirmations,
..env_config
}
} else {
env_config
}
}
#[cfg(test)]
mod tests {
use super::*;