From 38089e2d15bc6aba7697cb54b72a23b3113a1edf Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 10 Jul 2021 02:30:05 -0400 Subject: [PATCH] Only build witness cache when needed --- src/wallet/wallet.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3bc3b99cd..233851d64 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -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)))); CBlock block; + bool involvesMe = false; ReadBlockFromDisk(block, pindex,1); BOOST_FOREACH(CTransaction& tx, block.vtx) { if (AddToWalletIfInvolvingMe(tx, &block, fUpdate)) { + involvesMe = true; ret++; } } @@ -2734,8 +2736,11 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) } } - // Build initial witness caches - BuildWitnessCache(pindex, true); + // Build initial witness caches for blocks involving one of our addresses + if (involvesMe) { + LogPrintf("%s: block has one of our transactions, building witness cache", __func__); + BuildWitnessCache(pindex, true); + } //Delete Transactions if (fTxDeleteEnabled) {