From 321419bc06fdc19e3713b2bcfc10c3c9bbbb8b62 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Tue, 16 May 2017 11:34:28 -0400 Subject: Fix importwallet edge case rescan bug Start importwallet rescans at the first block with timestamp greater or equal to the wallet birthday instead of the last block with timestamp less or equal. This fixes an edge case bug where importwallet could fail to start the rescan early enough if there are blocks with decreasing timestamps or multiple blocks with the same timestamp. Github-Pull: #10410 Rebased-From: 2a8e35a11d4bd4828631654fc7b8b8fe8f0a2460 --- src/wallet/rpcdump.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/wallet/rpcdump.cpp') diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index cfb53af49..cd6ec207f 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -497,14 +497,11 @@ UniValue importwallet(const JSONRPCRequest& request) } file.close(); pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI - - CBlockIndex *pindex = chainActive.Tip(); - while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200) - pindex = pindex->pprev; - pwalletMain->UpdateTimeFirstKey(nTimeBegin); - LogPrintf("Rescanning last %i blocks\n", chainActive.Height() - pindex->nHeight + 1); + CBlockIndex *pindex = chainActive.FindEarliestAtLeast(nTimeBegin - 7200); + + LogPrintf("Rescanning last %i blocks\n", pindex ? chainActive.Height() - pindex->nHeight + 1 : 0); pwalletMain->ScanForWalletTransactions(pindex); pwalletMain->MarkDirty(); -- cgit v1.2.3