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.
This commit is contained in:
Daniel Karzel 2021-04-13 16:24:17 +10:00
parent 6c4d72704a
commit 99268c2715
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E

View File

@ -281,8 +281,17 @@ impl Client {
debug!("check_tx_key RPC response: {}", response);
let r = serde_json::from_str::<Response<CheckTxKey>>(&response)?;
Ok(r.result)
let check_tx_key = serde_json::from_str::<Response<CheckTxKey>>(&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(