From ba4d741fdb8a4d13a27b660681a81e1af4bbcade Mon Sep 17 00:00:00 2001 From: h4sh3d Date: Fri, 2 Dec 2022 17:51:07 +0100 Subject: [PATCH] feat: add config for swap parameters such as finality arguments --- farcasterd.toml | 7 +++++++ src/config.rs | 28 ++++++++++++++++++++++++++++ src/swapd/runtime.rs | 4 ++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/farcasterd.toml b/farcasterd.toml index aaf5d5a49..d85e38968 100644 --- a/farcasterd.toml +++ b/farcasterd.toml @@ -26,6 +26,13 @@ bitcoin_cookie_path = "~/.bitcoin/testnet3/.cookie" # the wallet should have spendable funds monero_rpc_wallet = "http://localhost:38084" +[swap.bitcoin] +race_threshold = 3 +confirmations_required = 1 + +[swap.monero] +confirmations_required = 1 + # Defines grpc options [grpc] # Set this to true to enable the grpc daemon diff --git a/src/config.rs b/src/config.rs index ddc7dfe88..759a6bbb8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,6 +35,8 @@ pub const GRPC_BIND_IP_ADDRESS: &str = "127.0.0.1"; pub struct Config { /// Farcasterd configuration pub farcasterd: Option, + /// Swap configuration, applies to all swaps launched by this node + pub swap: Option, /// Sets the grpc server port, if none is given, no grpc server is run pub grpc: Option, /// Syncer configuration @@ -107,6 +109,7 @@ impl Default for Config { fn default() -> Self { Config { farcasterd: None, + swap: None, grpc: None, syncers: Some(SyncersConfig::default()), } @@ -120,6 +123,31 @@ pub struct FarcasterdConfig { pub auto_funding: Option, } +#[derive(Deserialize, Serialize, Debug, Clone, Default)] +#[serde(crate = "serde_crate")] +pub struct SwapConfig { + /// Swap parameters for the Bitcoin blockchain + pub bitcoin: BitcoinConfig, + /// Swap parameters for the Monero blockchain + pub monero: MoneroConfig, +} + +#[derive(Deserialize, Serialize, Debug, Clone, Default)] +#[serde(crate = "serde_crate")] +pub struct BitcoinConfig { + /// Avoid broadcasting a transaction if a race can happen in # blocks + pub race_threshold: u8, + /// Number of confirmations required to consider a transaction final + pub confirmations_required: u8, +} + +#[derive(Deserialize, Serialize, Debug, Clone, Default)] +#[serde(crate = "serde_crate")] +pub struct MoneroConfig { + /// Number of confirmations required to consider a transaction final + pub confirmations_required: u8, +} + #[derive(Deserialize, Serialize, Debug, Clone)] #[serde(crate = "serde_crate")] pub struct GrpcConfig { diff --git a/src/swapd/runtime.rs b/src/swapd/runtime.rs index 94e242c5a..fac381aea 100644 --- a/src/swapd/runtime.rs +++ b/src/swapd/runtime.rs @@ -87,7 +87,6 @@ pub fn run( SwapRole::Alice => State::Alice(AliceState::StartA { local_trade_role }), SwapRole::Bob => State::Bob(BobState::StartB { local_trade_role }), }; - let sweep_monero_thr = 10; info!( "{}: {}", "Starting swap".to_string().bright_green_bold(), @@ -105,7 +104,8 @@ pub fn run( btc_finality_thr: 1, race_thr: 3, xmr_finality_thr: 1, - sweep_monero_thr, + // this is a constant + sweep_monero_thr: 10, }; temporal_safety.valid_params()?;