mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
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.
This commit is contained in:
@@ -536,14 +536,11 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||
}
|
||||
file.close();
|
||||
pwallet->ShowProgress("", 100); // hide progress dialog in GUI
|
||||
|
||||
CBlockIndex *pindex = chainActive.Tip();
|
||||
while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - TIMESTAMP_WINDOW)
|
||||
pindex = pindex->pprev;
|
||||
|
||||
pwallet->UpdateTimeFirstKey(nTimeBegin);
|
||||
|
||||
LogPrintf("Rescanning last %i blocks\n", chainActive.Height() - pindex->nHeight + 1);
|
||||
CBlockIndex *pindex = chainActive.FindEarliestAtLeast(nTimeBegin - TIMESTAMP_WINDOW);
|
||||
|
||||
LogPrintf("Rescanning last %i blocks\n", pindex ? chainActive.Height() - pindex->nHeight + 1 : 0);
|
||||
pwallet->ScanForWalletTransactions(pindex);
|
||||
pwallet->MarkDirty();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user