Skip to content

Commit ccf84bb

Browse files
committed
Move birthday optimization out of ScanForWalletTransactions
This change has no effect on wallet behavior. On wallet startup, the transaction scan avoids reading any blocks with timestamps older than the wallet birthday (less than nTimeFirstKey - TIMESTAMP_WINDOW). This block skipping code currently resides in CWallet::ScanForWalletTransactions but it doesn't really belong there because it makes the implementation unnecessarily fragile and hard to understand, and it never has any effect except at startup (because all other callers do their rescans based on timestamps other than, but always greater or equal to, nTimeFirstKey).
1 parent e654d61 commit ccf84bb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/wallet/wallet.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,11 +1479,6 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
14791479
fAbortRescan = false;
14801480
fScanningWallet = true;
14811481

1482-
// no need to read and scan block, if block was created before
1483-
// our wallet birthday (as adjusted for block time variability)
1484-
while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - TIMESTAMP_WINDOW)))
1485-
pindex = chainActive.Next(pindex);
1486-
14871482
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
14881483
double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
14891484
double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip());
@@ -3880,6 +3875,13 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
38803875

38813876
uiInterface.InitMessage(_("Rescanning..."));
38823877
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight);
3878+
3879+
// No need to read and scan block if block was created before
3880+
// our wallet birthday (as adjusted for block time variability)
3881+
while (pindexRescan && walletInstance->nTimeFirstKey && (pindexRescan->GetBlockTime() < (walletInstance->nTimeFirstKey - TIMESTAMP_WINDOW))) {
3882+
pindexRescan = chainActive.Next(pindexRescan);
3883+
}
3884+
38833885
nStart = GetTimeMillis();
38843886
walletInstance->ScanForWalletTransactions(pindexRescan, true);
38853887
LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart);

0 commit comments

Comments
 (0)