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:
bors[bot] 2021-03-30 01:43:38 +00:00 committed by GitHub
commit 3f56fe93e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 11 deletions

View File

@ -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),

View File

@ -69,14 +69,26 @@ 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())
match timeout(
env_config.bitcoin_lock_confirmed_timeout,
tx_lock_status.wait_until_final(),
)
.await
.context("Failed to find lock Bitcoin tx")??;
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
// block 0 for scenarios where we create a refund wallet.