From fef79e7b12576fc07ea721ce7ea335c6fd95fa5a Mon Sep 17 00:00:00 2001 From: DanS Date: Wed, 28 Oct 2026 12:40:42 -0500 Subject: [PATCH] wallet: skip fully validated txs before the depth lookup in the root selection The root selection of VerifyAndSetInitialWitness looked up the depth of every note-bearing tx on every block, although in the steady state between restarts every note is already validated and nothing is selected. A tx whose notes are all validated is now skipped before GetDepthInMainChain. The selection is the same: it never took a validated note. Co-Authored-By: Claude Opus 5.5 --- src/wallet/wallet.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 51f8d3691..a94c9a1c8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1450,7 +1450,15 @@ int CWallet::VerifyAndSetInitialWitness(const CBlockIndex* pindex, bool witnessO // surfaces exactly where it used to. std::vector rootNotes; for (const std::pair& wtxItem : mapWallet) { - if (wtxItem.second.mapSaplingNoteData.empty() || wtxItem.second.GetDepthInMainChain() <= 0) + // Once every note is validated (the steady state between restarts) nothing here selects one, so + // skip the depth lookup for such a tx. + bool fAnyUnvalidated = false; + for (const mapSaplingNoteData_t::value_type& item : wtxItem.second.mapSaplingNoteData) + if (!item.second.witnessRootValidated) { + fAnyUnvalidated = true; + break; + } + if (!fAnyUnvalidated || wtxItem.second.GetDepthInMainChain() <= 0) continue; for (const mapSaplingNoteData_t::value_type& item : wtxItem.second.mapSaplingNoteData) { const SaplingNoteData* nd = &(item.second);