mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-11-19 09:25:33 +00:00
Do not guard waiting for encrypted signature with arbitrary timeout
We already select waiting for this message with the cancellation expiry, we do not need add another guard that tries to guess how long it would for the Monero transaction to be finalised.
This commit is contained in:
parent
95ecb02e7a
commit
17356eaff9
@ -7,7 +7,6 @@ pub struct Config {
|
||||
pub bob_time_to_act: Duration,
|
||||
pub bitcoin_finality_confirmations: u32,
|
||||
pub bitcoin_avg_block_time: Duration,
|
||||
pub monero_max_finality_time: Duration,
|
||||
pub monero_finality_confirmations: u32,
|
||||
pub bitcoin_cancel_timelock: Timelock,
|
||||
pub bitcoin_punish_timelock: Timelock,
|
||||
@ -21,10 +20,6 @@ impl Config {
|
||||
bob_time_to_act: *mainnet::BOB_TIME_TO_ACT,
|
||||
bitcoin_finality_confirmations: mainnet::BITCOIN_FINALITY_CONFIRMATIONS,
|
||||
bitcoin_avg_block_time: *mainnet::BITCOIN_AVG_BLOCK_TIME,
|
||||
// We apply a scaling factor (1.5) so that the swap is not aborted when the
|
||||
// blockchain is slow
|
||||
monero_max_finality_time: (*mainnet::MONERO_AVG_BLOCK_TIME).mul_f64(1.5)
|
||||
* mainnet::MONERO_FINALITY_CONFIRMATIONS,
|
||||
monero_finality_confirmations: mainnet::MONERO_FINALITY_CONFIRMATIONS,
|
||||
bitcoin_cancel_timelock: mainnet::BITCOIN_CANCEL_TIMELOCK,
|
||||
bitcoin_punish_timelock: mainnet::BITCOIN_PUNISH_TIMELOCK,
|
||||
@ -38,10 +33,6 @@ impl Config {
|
||||
bob_time_to_act: *testnet::BOB_TIME_TO_ACT,
|
||||
bitcoin_finality_confirmations: testnet::BITCOIN_FINALITY_CONFIRMATIONS,
|
||||
bitcoin_avg_block_time: *testnet::BITCOIN_AVG_BLOCK_TIME,
|
||||
// We apply a scaling factor (1.5) so that the swap is not aborted when the
|
||||
// blockchain is slow
|
||||
monero_max_finality_time: (*testnet::MONERO_AVG_BLOCK_TIME).mul_f64(1.5)
|
||||
* testnet::MONERO_FINALITY_CONFIRMATIONS,
|
||||
monero_finality_confirmations: testnet::MONERO_FINALITY_CONFIRMATIONS,
|
||||
bitcoin_cancel_timelock: testnet::BITCOIN_CANCEL_TIMELOCK,
|
||||
bitcoin_punish_timelock: testnet::BITCOIN_PUNISH_TIMELOCK,
|
||||
@ -55,10 +46,6 @@ impl Config {
|
||||
bob_time_to_act: *regtest::BOB_TIME_TO_ACT,
|
||||
bitcoin_finality_confirmations: regtest::BITCOIN_FINALITY_CONFIRMATIONS,
|
||||
bitcoin_avg_block_time: *regtest::BITCOIN_AVG_BLOCK_TIME,
|
||||
// We apply a scaling factor (1.5) so that the swap is not aborted when the
|
||||
// blockchain is slow
|
||||
monero_max_finality_time: (*regtest::MONERO_AVG_BLOCK_TIME).mul_f64(1.5)
|
||||
* regtest::MONERO_FINALITY_CONFIRMATIONS,
|
||||
monero_finality_confirmations: regtest::MONERO_FINALITY_CONFIRMATIONS,
|
||||
bitcoin_cancel_timelock: regtest::BITCOIN_CANCEL_TIMELOCK,
|
||||
bitcoin_punish_timelock: regtest::BITCOIN_PUNISH_TIMELOCK,
|
||||
@ -80,8 +67,6 @@ mod mainnet {
|
||||
|
||||
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 15;
|
||||
|
||||
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_CANCEL_TIMELOCK: Timelock = Timelock::new(72);
|
||||
pub static BITCOIN_PUNISH_TIMELOCK: Timelock = Timelock::new(72);
|
||||
@ -100,10 +85,6 @@ mod testnet {
|
||||
// This does not reflect recommended values for mainnet!
|
||||
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 5;
|
||||
|
||||
// The average blocktime on Monero stagenet is not as constant as on mainnet,
|
||||
// hence 4 minutes it set
|
||||
pub static MONERO_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(4 * 60));
|
||||
|
||||
// This does not reflect recommended values for mainnet!
|
||||
pub static BITCOIN_CANCEL_TIMELOCK: Timelock = Timelock::new(6);
|
||||
pub static BITCOIN_PUNISH_TIMELOCK: Timelock = Timelock::new(6);
|
||||
@ -121,8 +102,6 @@ mod regtest {
|
||||
|
||||
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 1;
|
||||
|
||||
pub static MONERO_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(60));
|
||||
|
||||
pub static BITCOIN_CANCEL_TIMELOCK: Timelock = Timelock::new(50);
|
||||
|
||||
pub static BITCOIN_PUNISH_TIMELOCK: Timelock = Timelock::new(50);
|
||||
|
@ -7,7 +7,7 @@ use futures::{
|
||||
use libp2p::request_response::ResponseChannel;
|
||||
use rand::rngs::OsRng;
|
||||
use sha2::Sha256;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use std::sync::Arc;
|
||||
use tokio::time::timeout;
|
||||
use tracing::{info, trace};
|
||||
|
||||
@ -147,11 +147,11 @@ where
|
||||
|
||||
pub async fn wait_for_bitcoin_encrypted_signature(
|
||||
event_loop_handle: &mut EventLoopHandle,
|
||||
timeout_duration: Duration,
|
||||
) -> Result<EncryptedSignature> {
|
||||
let msg3 = timeout(timeout_duration, event_loop_handle.recv_message3())
|
||||
let msg3 = event_loop_handle
|
||||
.recv_message3()
|
||||
.await
|
||||
.context("Failed to receive Bitcoin encrypted signature from Bob")??;
|
||||
.context("Failed to receive Bitcoin encrypted signature from Bob")?;
|
||||
Ok(msg3.tx_redeem_encsig)
|
||||
}
|
||||
|
||||
|
@ -214,10 +214,8 @@ pub async fn run_until(
|
||||
// expressed more cleanly
|
||||
let state = match state3.expired_timelocks(bitcoin_wallet.as_ref()).await? {
|
||||
ExpiredTimelocks::None => {
|
||||
let wait_for_enc_sig = wait_for_bitcoin_encrypted_signature(
|
||||
&mut event_loop_handle,
|
||||
config.monero_max_finality_time,
|
||||
);
|
||||
let wait_for_enc_sig =
|
||||
wait_for_bitcoin_encrypted_signature(&mut event_loop_handle);
|
||||
let state3_clone = state3.clone();
|
||||
let cancel_timelock_expires = state3_clone
|
||||
.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref());
|
||||
|
Loading…
Reference in New Issue
Block a user