Skip to content

Commit d9f5132

Browse files
author
MarcoFalke
committed
Merge #20344: wallet: fix scanning progress calculation for single block range
5e14602 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 5e14602 promag: Core review ACK 5e14602. Tree-SHA512: f0e6aad5a6cd08b36c5fe820fff0ef26663229b39169a4dbe757f3c795a41cf5c69c9dc90efe7515675ae1059307f8971123781a0514d10704123a6f28b125ab
2 parents 179ece4 + 5e14602 commit d9f5132

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/wallet/wallet.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,11 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
17781778
double progress_current = progress_begin;
17791779
int block_height = start_height;
17801780
while (!fAbortRescan && !chain().shutdownRequested()) {
1781-
m_scanning_progress = (progress_current - progress_begin) / (progress_end - progress_begin);
1781+
if (progress_end - progress_begin > 0.0) {
1782+
m_scanning_progress = (progress_current - progress_begin) / (progress_end - progress_begin);
1783+
} else { // avoid divide-by-zero for single block scan range (i.e. start and stop hashes are equal)
1784+
m_scanning_progress = 0;
1785+
}
17821786
if (block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
17831787
ShowProgress(strprintf("%s " + _("Rescanning...").translated, GetDisplayName()), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
17841788
}

test/sanitizer_suppressions/ubsan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -fsanitize=undefined suppressions
22
# =================================
33
float-divide-by-zero:validation.cpp
4-
float-divide-by-zero:wallet/wallet.cpp
54

65
# -fsanitize=integer suppressions
76
# ===============================

0 commit comments

Comments
 (0)