From 5e146022daa4336de94447e5b8e5418296286927 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Sun, 8 Nov 2020 18:37:47 +0100 Subject: wallet: fix scanning progress calculation for single block range If the blockchain is rescanned for a single block (i.e. start and stop hashes are equal, and with that also the estimated verification progress) the progress calculation could lead to a NaN value caused by a division by zero, resulting in an invalid JSON result for the getwalletinfo RPC. Fixed by setting the progress to zero in that special case. Co-authored-by: MarcoFalke --- src/wallet/wallet.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d1cde6aa89..eb92142aa9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1778,7 +1778,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)))); } -- cgit v1.2.3