Only build witness cache when needed

This commit is contained in:
Duke Leto
2021-07-10 02:30:05 -04:00
parent 98fbd2c0f4
commit 38089e2d15

View File

@@ -2717,10 +2717,12 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100)))); ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
CBlock block; CBlock block;
bool involvesMe = false;
ReadBlockFromDisk(block, pindex,1); ReadBlockFromDisk(block, pindex,1);
BOOST_FOREACH(CTransaction& tx, block.vtx) BOOST_FOREACH(CTransaction& tx, block.vtx)
{ {
if (AddToWalletIfInvolvingMe(tx, &block, fUpdate)) { if (AddToWalletIfInvolvingMe(tx, &block, fUpdate)) {
involvesMe = true;
ret++; ret++;
} }
} }
@@ -2734,8 +2736,11 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
} }
} }
// Build initial witness caches // Build initial witness caches for blocks involving one of our addresses
BuildWitnessCache(pindex, true); if (involvesMe) {
LogPrintf("%s: block has one of our transactions, building witness cache", __func__);
BuildWitnessCache(pindex, true);
}
//Delete Transactions //Delete Transactions
if (fTxDeleteEnabled) { if (fTxDeleteEnabled) {