mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Move expiries to config
So they can be different for mainnet and regtest
This commit is contained in:
parent
ef6e8fc723
commit
c0478d7191
@ -14,9 +14,6 @@ pub mod state;
|
|||||||
pub mod storage;
|
pub mod storage;
|
||||||
pub mod tor;
|
pub mod tor;
|
||||||
|
|
||||||
pub const REFUND_TIMELOCK: u32 = 50; // Relative timelock, this is number of blocks. TODO: What should it be?
|
|
||||||
pub const PUNISH_TIMELOCK: u32 = 50; // FIXME: What should this be?
|
|
||||||
|
|
||||||
pub type Never = std::convert::Infallible;
|
pub type Never = std::convert::Infallible;
|
||||||
|
|
||||||
/// Commands sent from Bob to the main task.
|
/// Commands sent from Bob to the main task.
|
||||||
|
@ -6,7 +6,7 @@ use rand::rngs::OsRng;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use swap::{
|
use swap::{
|
||||||
alice, alice::swap::AliceState, bob, bob::swap::BobState, network::transport::build,
|
alice, alice::swap::AliceState, bob, bob::swap::BobState, network::transport::build,
|
||||||
storage::Database, SwapAmounts, PUNISH_TIMELOCK, REFUND_TIMELOCK,
|
storage::Database, SwapAmounts,
|
||||||
};
|
};
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use testcontainers::clients::Cli;
|
use testcontainers::clients::Cli;
|
||||||
@ -45,6 +45,8 @@ async fn happy_path() {
|
|||||||
.parse()
|
.parse()
|
||||||
.expect("failed to parse Alice's address");
|
.expect("failed to parse Alice's address");
|
||||||
|
|
||||||
|
let config = Config::regtest();
|
||||||
|
|
||||||
let (
|
let (
|
||||||
alice_state,
|
alice_state,
|
||||||
mut alice_swarm_driver,
|
mut alice_swarm_driver,
|
||||||
@ -60,6 +62,7 @@ async fn happy_path() {
|
|||||||
xmr_to_swap,
|
xmr_to_swap,
|
||||||
xmr_alice,
|
xmr_alice,
|
||||||
alice_multiaddr.clone(),
|
alice_multiaddr.clone(),
|
||||||
|
config,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -73,6 +76,7 @@ async fn happy_path() {
|
|||||||
btc_bob,
|
btc_bob,
|
||||||
xmr_to_swap,
|
xmr_to_swap,
|
||||||
xmr_bob,
|
xmr_bob,
|
||||||
|
config,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -81,7 +85,7 @@ async fn happy_path() {
|
|||||||
alice_swarm_handle,
|
alice_swarm_handle,
|
||||||
alice_btc_wallet.clone(),
|
alice_btc_wallet.clone(),
|
||||||
alice_xmr_wallet.clone(),
|
alice_xmr_wallet.clone(),
|
||||||
Config::regtest(),
|
config,
|
||||||
);
|
);
|
||||||
|
|
||||||
let _alice_swarm_fut = tokio::spawn(async move { alice_swarm_driver.run().await });
|
let _alice_swarm_fut = tokio::spawn(async move { alice_swarm_driver.run().await });
|
||||||
@ -149,6 +153,8 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
|
|||||||
.parse()
|
.parse()
|
||||||
.expect("failed to parse Alice's address");
|
.expect("failed to parse Alice's address");
|
||||||
|
|
||||||
|
let config = Config::regtest();
|
||||||
|
|
||||||
let (
|
let (
|
||||||
alice_state,
|
alice_state,
|
||||||
mut alice_swarm,
|
mut alice_swarm,
|
||||||
@ -164,6 +170,7 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
|
|||||||
xmr_to_swap,
|
xmr_to_swap,
|
||||||
alice_xmr_starting_balance,
|
alice_xmr_starting_balance,
|
||||||
alice_multiaddr.clone(),
|
alice_multiaddr.clone(),
|
||||||
|
config,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -177,6 +184,7 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
|
|||||||
bob_btc_starting_balance,
|
bob_btc_starting_balance,
|
||||||
xmr_to_swap,
|
xmr_to_swap,
|
||||||
bob_xmr_starting_balance,
|
bob_xmr_starting_balance,
|
||||||
|
config,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -220,6 +228,7 @@ async fn init_alice(
|
|||||||
xmr_to_swap: xmr_btc::monero::Amount,
|
xmr_to_swap: xmr_btc::monero::Amount,
|
||||||
xmr_starting_balance: xmr_btc::monero::Amount,
|
xmr_starting_balance: xmr_btc::monero::Amount,
|
||||||
listen: Multiaddr,
|
listen: Multiaddr,
|
||||||
|
config: Config,
|
||||||
) -> (
|
) -> (
|
||||||
AliceState,
|
AliceState,
|
||||||
alice::event_loop::EventLoop,
|
alice::event_loop::EventLoop,
|
||||||
@ -261,8 +270,8 @@ async fn init_alice(
|
|||||||
v_a,
|
v_a,
|
||||||
amounts.btc,
|
amounts.btc,
|
||||||
amounts.xmr,
|
amounts.xmr,
|
||||||
REFUND_TIMELOCK,
|
config.bitcoin_refund_timelock,
|
||||||
PUNISH_TIMELOCK,
|
config.bitcoin_punish_timelock,
|
||||||
redeem_address,
|
redeem_address,
|
||||||
punish_address,
|
punish_address,
|
||||||
);
|
);
|
||||||
@ -303,6 +312,7 @@ async fn init_bob(
|
|||||||
btc_starting_balance: bitcoin::Amount,
|
btc_starting_balance: bitcoin::Amount,
|
||||||
xmr_to_swap: xmr_btc::monero::Amount,
|
xmr_to_swap: xmr_btc::monero::Amount,
|
||||||
xmr_stating_balance: xmr_btc::monero::Amount,
|
xmr_stating_balance: xmr_btc::monero::Amount,
|
||||||
|
config: Config,
|
||||||
) -> (
|
) -> (
|
||||||
BobState,
|
BobState,
|
||||||
bob::event_loop::EventLoop,
|
bob::event_loop::EventLoop,
|
||||||
@ -346,8 +356,8 @@ async fn init_bob(
|
|||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
btc_to_swap,
|
btc_to_swap,
|
||||||
xmr_to_swap,
|
xmr_to_swap,
|
||||||
REFUND_TIMELOCK,
|
config.bitcoin_refund_timelock,
|
||||||
PUNISH_TIMELOCK,
|
config.bitcoin_punish_timelock,
|
||||||
refund_address,
|
refund_address,
|
||||||
);
|
);
|
||||||
let bob_state = BobState::Started {
|
let bob_state = BobState::Started {
|
||||||
|
@ -7,6 +7,8 @@ pub struct Config {
|
|||||||
pub bitcoin_finality_confirmations: u32,
|
pub bitcoin_finality_confirmations: u32,
|
||||||
pub bitcoin_avg_block_time: Duration,
|
pub bitcoin_avg_block_time: Duration,
|
||||||
pub monero_max_finality_time: Duration,
|
pub monero_max_finality_time: Duration,
|
||||||
|
pub bitcoin_refund_timelock: u32,
|
||||||
|
pub bitcoin_punish_timelock: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -19,6 +21,8 @@ impl Config {
|
|||||||
// blockchain is slow
|
// blockchain is slow
|
||||||
monero_max_finality_time: (*mainnet::MONERO_AVG_BLOCK_TIME).mul_f64(1.5)
|
monero_max_finality_time: (*mainnet::MONERO_AVG_BLOCK_TIME).mul_f64(1.5)
|
||||||
* mainnet::MONERO_FINALITY_CONFIRMATIONS,
|
* mainnet::MONERO_FINALITY_CONFIRMATIONS,
|
||||||
|
bitcoin_refund_timelock: mainnet::BITCOIN_REFUND_TIMELOCK,
|
||||||
|
bitcoin_punish_timelock: mainnet::BITCOIN_PUNISH_TIMELOCK,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +35,8 @@ impl Config {
|
|||||||
// blockchain is slow
|
// blockchain is slow
|
||||||
monero_max_finality_time: (*regtest::MONERO_AVG_BLOCK_TIME).mul_f64(1.5)
|
monero_max_finality_time: (*regtest::MONERO_AVG_BLOCK_TIME).mul_f64(1.5)
|
||||||
* regtest::MONERO_FINALITY_CONFIRMATIONS,
|
* regtest::MONERO_FINALITY_CONFIRMATIONS,
|
||||||
|
bitcoin_refund_timelock: regtest::BITCOIN_REFUND_TIMELOCK,
|
||||||
|
bitcoin_punish_timelock: regtest::BITCOIN_PUNISH_TIMELOCK,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,6 +54,10 @@ mod mainnet {
|
|||||||
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 15;
|
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 15;
|
||||||
|
|
||||||
pub static MONERO_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(2 * 60));
|
pub static MONERO_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(2 * 60));
|
||||||
|
|
||||||
|
// Set to 12 hours, arbitrary value to be reviewed properly
|
||||||
|
pub static BITCOIN_REFUND_TIMELOCK: u32 = 72;
|
||||||
|
pub static BITCOIN_PUNISH_TIMELOCK: u32 = 72;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod regtest {
|
mod regtest {
|
||||||
@ -63,4 +73,8 @@ mod regtest {
|
|||||||
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 1;
|
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 1;
|
||||||
|
|
||||||
pub static MONERO_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(60));
|
pub static MONERO_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(60));
|
||||||
|
|
||||||
|
pub static BITCOIN_REFUND_TIMELOCK: u32 = 50;
|
||||||
|
|
||||||
|
pub static BITCOIN_PUNISH_TIMELOCK: u32 = 50;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user