Skip to content

Commit

Permalink
feat: add config for swap parameters such as finality arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
h4sh3d committed Dec 6, 2022
1 parent 772d18e commit 4e90e98
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
17 changes: 17 additions & 0 deletions farcasterd.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ bitcoin_cookie_path = "~/.bitcoin/testnet3/.cookie"
# the wallet should have spendable funds
monero_rpc_wallet = "http://localhost:38084"

# Swap parameter for the Bitcoin blockchain
[swap.bitcoin]
# Avoid broadcasting a transaction if a race can happen in # blocks
#
# E.g. if the safety margin is set to 3 and the the cancel transaction becomes
# broadcastable in 4 blocks we are safe and we do publish buy, if it becomes
# broadcastable in 3 blocks or less we do not publish the buy as the safety
# margin is not respected.
safety_margin = 3
# Number of confirmations required to consider a transaction final
finality = 1

# Swap parameter for the Monero blockchain
[swap.monero]
# Number of confirmations required to consider a transaction final
finality = 5

# Defines grpc options
[grpc]
# Set this to true to enable the grpc daemon
Expand Down
28 changes: 28 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub const GRPC_BIND_IP_ADDRESS: &str = "127.0.0.1";
pub struct Config {
/// Farcasterd configuration
pub farcasterd: Option<FarcasterdConfig>,
/// Swap configuration, applies to all swaps launched by this node
pub swap: Option<SwapConfig>,
/// Sets the grpc server port, if none is given, no grpc server is run
pub grpc: Option<GrpcConfig>,
/// Syncer configuration
Expand Down Expand Up @@ -142,6 +144,7 @@ impl Default for Config {
fn default() -> Self {
Config {
farcasterd: Some(FarcasterdConfig::default()),
swap: None,
grpc: None,
syncers: Some(SyncersConfig::default()),
}
Expand All @@ -161,6 +164,31 @@ pub struct FarcasterdConfig {
pub auto_restore: Option<bool>,
}

#[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 safety_margin: u8,
/// Number of confirmations required to consider a transaction final
pub finality: u8,
}

#[derive(Deserialize, Serialize, Debug, Clone, Default)]
#[serde(crate = "serde_crate")]
pub struct MoneroConfig {
/// Number of confirmations required to consider a transaction final
pub finality: u8,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(crate = "serde_crate")]
pub struct GrpcConfig {
Expand Down
4 changes: 2 additions & 2 deletions src/swapd/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()?;
Expand Down

0 comments on commit 4e90e98

Please sign in to comment.