mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-28 17:09:37 -05:00
Merge #338
338: Timeout improvements r=rishflab a=rishflab If TxLock does not confirm in a reasonable amount of time, Alice should give up on the swap rather than waiting forever. Watching for TxLock in the mempool is no longer required and causes unnecessary complexity. What if Alice does not see the transaction in mempool but it is already confirmed? She will abort the swap for no reason. Co-authored-by: rishflab <rishflab@hotmail.com>
This commit is contained in:
commit
3f56fe93e0
@ -5,7 +5,7 @@ use time::NumericalStdDurationShort;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Config {
|
||||
pub bob_time_to_act: Duration,
|
||||
pub bitcoin_lock_confirmed_timeout: Duration,
|
||||
pub bitcoin_finality_confirmations: u32,
|
||||
pub bitcoin_avg_block_time: Duration,
|
||||
pub bitcoin_cancel_timelock: CancelTimelock,
|
||||
@ -42,7 +42,7 @@ pub struct Regtest;
|
||||
impl GetConfig for Mainnet {
|
||||
fn get_config() -> Config {
|
||||
Config {
|
||||
bob_time_to_act: 10.minutes(),
|
||||
bitcoin_lock_confirmed_timeout: 24.hours(),
|
||||
bitcoin_finality_confirmations: 3,
|
||||
bitcoin_avg_block_time: 10.minutes(),
|
||||
bitcoin_cancel_timelock: CancelTimelock::new(72),
|
||||
@ -58,7 +58,7 @@ impl GetConfig for Mainnet {
|
||||
impl GetConfig for Testnet {
|
||||
fn get_config() -> Config {
|
||||
Config {
|
||||
bob_time_to_act: 60.minutes(),
|
||||
bitcoin_lock_confirmed_timeout: 12.hours(),
|
||||
bitcoin_finality_confirmations: 1,
|
||||
bitcoin_avg_block_time: 5.minutes(),
|
||||
bitcoin_cancel_timelock: CancelTimelock::new(12),
|
||||
@ -74,7 +74,7 @@ impl GetConfig for Testnet {
|
||||
impl GetConfig for Regtest {
|
||||
fn get_config() -> Config {
|
||||
Config {
|
||||
bob_time_to_act: 30.seconds(),
|
||||
bitcoin_lock_confirmed_timeout: 1.minutes(),
|
||||
bitcoin_finality_confirmations: 1,
|
||||
bitcoin_avg_block_time: 5.seconds(),
|
||||
bitcoin_cancel_timelock: CancelTimelock::new(100),
|
||||
|
@ -69,13 +69,25 @@ async fn next_state(
|
||||
Ok(match state {
|
||||
AliceState::Started { state3 } => {
|
||||
let tx_lock_status = bitcoin_wallet.subscribe_to(state3.tx_lock.clone()).await;
|
||||
timeout(env_config.bob_time_to_act, tx_lock_status.wait_until_seen())
|
||||
.await
|
||||
.context("Failed to find lock Bitcoin tx")??;
|
||||
|
||||
tx_lock_status.wait_until_final().await?;
|
||||
|
||||
AliceState::BtcLocked { state3 }
|
||||
match timeout(
|
||||
env_config.bitcoin_lock_confirmed_timeout,
|
||||
tx_lock_status.wait_until_final(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Err(_) => {
|
||||
tracing::info!(
|
||||
"TxLock lock did not get {} confirmations in {} minutes",
|
||||
env_config.bitcoin_finality_confirmations,
|
||||
env_config.bitcoin_lock_confirmed_timeout.as_secs_f64() / 60.0
|
||||
);
|
||||
AliceState::SafelyAborted
|
||||
}
|
||||
Ok(res) => {
|
||||
res?;
|
||||
AliceState::BtcLocked { state3 }
|
||||
}
|
||||
}
|
||||
}
|
||||
AliceState::BtcLocked { state3 } => {
|
||||
// Record the current monero wallet block height so we don't have to scan from
|
||||
|
Loading…
Reference in New Issue
Block a user