From 57ba59c0cdf20de322afabe4a132ad17e483ce77 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 8 Jan 2025 14:40:04 +0100 Subject: [PATCH] refactor: Remove redundant reindex check The check for whether the block tree db has been wiped before calling NeedsRedownload() is confusing. The boolean is set in case of a reindex. It was originally introduced to guard NeedsRedownload in case of a reindex in #21009. However NeedsRedownload already returns early if the chain's tip is not loaded. Since that is the case during a reindex, the pre-check is redundant. --- src/node/chainstate.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 3ee557ae62222..10b6e52c78b0c 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -155,14 +155,12 @@ static ChainstateLoadResult CompleteChainstateInitialization( } } - if (!options.wipe_block_tree_db) { - auto chainstates{chainman.GetAll()}; - if (std::any_of(chainstates.begin(), chainstates.end(), - [](const Chainstate* cs) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return cs->NeedsRedownload(); })) { - return {ChainstateLoadStatus::FAILURE, strprintf(_("Witness data for blocks after height %d requires validation. Please restart with -reindex."), - chainman.GetConsensus().SegwitHeight)}; - }; - } + auto chainstates{chainman.GetAll()}; + if (std::any_of(chainstates.begin(), chainstates.end(), + [](const Chainstate* cs) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return cs->NeedsRedownload(); })) { + return {ChainstateLoadStatus::FAILURE, strprintf(_("Witness data for blocks after height %d requires validation. Please restart with -reindex."), + chainman.GetConsensus().SegwitHeight)}; + }; // Now that chainstates are loaded and we're able to flush to // disk, rebalance the coins caches to desired levels based