From 5616683d7d82bbeeaa23889e2de279efbc52dd35 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 29 Mar 2021 12:05:20 +1100 Subject: [PATCH] Monero confirmations are a u64 Trying to deserialize the number as a u32 caused deserialization errors. --- monero-rpc/src/rpc/wallet.rs | 2 +- swap/src/env.rs | 2 +- swap/src/monero/wallet.rs | 12 ++++++------ swap/src/protocol/alice/state.rs | 2 +- swap/src/protocol/bob/state.rs | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/monero-rpc/src/rpc/wallet.rs b/monero-rpc/src/rpc/wallet.rs index 7481ee27..63f1fe3a 100644 --- a/monero-rpc/src/rpc/wallet.rs +++ b/monero-rpc/src/rpc/wallet.rs @@ -470,7 +470,7 @@ struct CheckTxKeyParams { #[derive(Clone, Copy, Debug, Deserialize)] pub struct CheckTxKey { - pub confirmations: u32, + pub confirmations: u64, pub received: u64, } diff --git a/swap/src/env.rs b/swap/src/env.rs index d60ae858..e020faea 100644 --- a/swap/src/env.rs +++ b/swap/src/env.rs @@ -12,7 +12,7 @@ pub struct Config { pub bitcoin_punish_timelock: PunishTimelock, pub bitcoin_network: bitcoin::Network, pub monero_avg_block_time: Duration, - pub monero_finality_confirmations: u32, + pub monero_finality_confirmations: u64, pub monero_network: monero::Network, } diff --git a/swap/src/monero/wallet.rs b/swap/src/monero/wallet.rs index d5076296..ddf9fdef 100644 --- a/swap/src/monero/wallet.rs +++ b/swap/src/monero/wallet.rs @@ -271,7 +271,7 @@ pub struct WatchRequest { pub public_spend_key: PublicKey, pub public_view_key: PublicViewKey, pub transfer_proof: TransferProof, - pub conf_target: u32, + pub conf_target: u64, pub expected: Amount, } @@ -280,12 +280,12 @@ async fn wait_for_confirmations( fetch_tx: impl Fn(String) -> Fut, mut check_interval: Interval, expected: Amount, - conf_target: u32, + conf_target: u64, ) -> Result<(), InsufficientFunds> where Fut: Future>, { - let mut seen_confirmations = 0u32; + let mut seen_confirmations = 0u64; while seen_confirmations < conf_target { check_interval.tick().await; // tick() at the beginning of the loop so every `continue` tick()s as well @@ -323,7 +323,7 @@ where mod tests { use super::*; use monero_rpc::wallet::CheckTxKey; - use std::sync::atomic::{AtomicU32, Ordering}; + use std::sync::atomic::{AtomicU32, AtomicU64, Ordering}; use std::sync::Arc; #[tokio::test] @@ -364,9 +364,9 @@ mod tests { #[tokio::test] async fn visual_log_check() { let _ = tracing_subscriber::fmt().with_test_writer().try_init(); - const MAX_REQUESTS: u32 = 20; + const MAX_REQUESTS: u64 = 20; - let requests = Arc::new(AtomicU32::new(0)); + let requests = Arc::new(AtomicU64::new(0)); let result = wait_for_confirmations( String::from("TXID"), diff --git a/swap/src/protocol/alice/state.rs b/swap/src/protocol/alice/state.rs index 3b035a41..e0ff69df 100644 --- a/swap/src/protocol/alice/state.rs +++ b/swap/src/protocol/alice/state.rs @@ -361,7 +361,7 @@ impl State3 { pub fn lock_xmr_watch_request( &self, transfer_proof: TransferProof, - conf_target: u32, + conf_target: u64, ) -> WatchRequest { let S_a = monero::PublicKey::from_private_key(&monero::PrivateKey { scalar: self.s_a }); diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index b2703a51..6a7c8d95 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -83,7 +83,7 @@ pub struct State0 { cancel_timelock: CancelTimelock, punish_timelock: PunishTimelock, refund_address: bitcoin::Address, - min_monero_confirmations: u32, + min_monero_confirmations: u64, } impl State0 { @@ -94,7 +94,7 @@ impl State0 { cancel_timelock: CancelTimelock, punish_timelock: PunishTimelock, refund_address: bitcoin::Address, - min_monero_confirmations: u32, + min_monero_confirmations: u64, ) -> Self { let b = bitcoin::SecretKey::new_random(rng); @@ -185,7 +185,7 @@ pub struct State1 { redeem_address: bitcoin::Address, punish_address: bitcoin::Address, tx_lock: bitcoin::TxLock, - min_monero_confirmations: u32, + min_monero_confirmations: u64, } impl State1 { @@ -245,7 +245,7 @@ pub struct State2 { tx_lock: bitcoin::TxLock, tx_cancel_sig_a: Signature, tx_refund_encsig: bitcoin::EncryptedSignature, - min_monero_confirmations: u32, + min_monero_confirmations: u64, } impl State2 { @@ -302,7 +302,7 @@ pub struct State3 { tx_lock: bitcoin::TxLock, tx_cancel_sig_a: Signature, tx_refund_encsig: bitcoin::EncryptedSignature, - min_monero_confirmations: u32, + min_monero_confirmations: u64, } impl State3 {