mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #20344: wallet: fix scanning progress calculation for single block range
5e146022daa4336de94447e5b8e5418296286927 wallet: fix scanning progress calculation for single block range (Sebastian Falbesoner) Pull request description: If the blockchain is rescanned for a single block (i.e. start and stop hashes are equal, and with that also the estimated start/stop verification progress values) the progress calculation could lead to a NaN value caused by a division by zero (0.0/0.0), resulting in an invalid JSON result for the `getwalletinfo` RPC. This PR fixes this behaviour by setting the progress to zero in that special case. Fixes #20297. The behaviour can easily be reproduced by continuously running single block rescans in an endless loop, e.g. via ```bash #!/bin/bash while true do bitcoin-cli rescanblockchain $(bitcoin-cli getblockcount) done ``` and at the same time perform some `getwalletinfo` RPCs. On the master branch, this leads to frequent invalid responses (tested on mainchain): ``` $ bitcoin-cli getwalletinfo error: couldn't parse reply from server $ curl --user `cat ~/.bitcoin/.cookie` --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getwalletinfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/ {"result":{"walletname":"","walletversion":169900,"format":"bdb","balance":0.00000000,"unconfirmed_balance":0.00000000,"immature_balance":0.00000000,"txcount":0,"keypoololdest":1603677276,"keypoolsize":1000,"hdseedid":"3196e33ecb47c7130e6ca60f2f895f9259860dca","keypoolsize_hd_internal":1000,"paytxfee":0.00000000,"private_keys_enabled":true,"avoid_reuse":false,"scanning":{"duration":0,"progress":},"descriptors":false},"error":null,"id":"curltest"} ``` (note that missing value for "progress" in the JSON result). On the PR branch, the behaviour doesn't occur anymore. ACKs for top commit: MarcoFalke: review ACK 5e146022daa4336de94447e5b8e5418296286927 promag: Core review ACK 5e146022daa4336de94447e5b8e5418296286927. Tree-SHA512: f0e6aad5a6cd08b36c5fe820fff0ef26663229b39169a4dbe757f3c795a41cf5c69c9dc90efe7515675ae1059307f8971123781a0514d10704123a6f28b125ab
This commit is contained in:
parent
a4d894943a
commit
f8d32e7e1b
@ -1922,7 +1922,11 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
|
||||
double progress_current = progress_begin;
|
||||
int block_height = start_height;
|
||||
while (!fAbortRescan && !chain().shutdownRequested()) {
|
||||
m_scanning_progress = (progress_current - progress_begin) / (progress_end - progress_begin);
|
||||
if (progress_end - progress_begin > 0.0) {
|
||||
m_scanning_progress = (progress_current - progress_begin) / (progress_end - progress_begin);
|
||||
} else { // avoid divide-by-zero for single block scan range (i.e. start and stop hashes are equal)
|
||||
m_scanning_progress = 0;
|
||||
}
|
||||
if (block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
|
||||
ShowProgress(strprintf("%s " + _("Rescanning...").translated, GetDisplayName()), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
# -fsanitize=undefined suppressions
|
||||
# =================================
|
||||
float-divide-by-zero:validation.cpp
|
||||
float-divide-by-zero:wallet/wallet.cpp
|
||||
|
||||
# -fsanitize=integer suppressions
|
||||
# ===============================
|
||||
|
Loading…
Reference in New Issue
Block a user