From 99268c2715d4181ce5562e005f5564745900b045 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Tue, 13 Apr 2021 16:24:17 +1000 Subject: [PATCH] Workaround to avoid overflow in `check_tx_key` `check_tx_key` can run into an overflow error when handling `-1` values for confirmations. This most likely happens when a transaction is not in mempool yet. In order to avoid unwanted side effects in the tests (i.e. failure because the transfer is seemingly confirmed, when it is not yet), we add a guard that checks for values close to u64::MAX. Note that we cannot check for the exact value of u64::MAX, because it seems that there is an addition somewhere in monerod/wallet-rpc, that results in `-1` (first), `-2` (second) (...) until the transaction is in mempool. --- monero-rpc/src/rpc/wallet.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/monero-rpc/src/rpc/wallet.rs b/monero-rpc/src/rpc/wallet.rs index e4422680..3a9eea05 100644 --- a/monero-rpc/src/rpc/wallet.rs +++ b/monero-rpc/src/rpc/wallet.rs @@ -281,8 +281,17 @@ impl Client { debug!("check_tx_key RPC response: {}", response); - let r = serde_json::from_str::>(&response)?; - Ok(r.result) + let check_tx_key = serde_json::from_str::>(&response)?; + let mut check_tx_key = check_tx_key.result; + + // Due to a bug in monerod that causes check_tx_key confirmations + // to overflow we safeguard the confirmations to avoid unwanted + // side effects. + if check_tx_key.confirmations > u64::MAX - 1000 { + check_tx_key.confirmations = 0u64; + } + + Ok(check_tx_key) } pub async fn generate_from_keys(