Skip to content

Commit

Permalink
refactor: Remove redundant reindex check
Browse files Browse the repository at this point in the history
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 bitcoin#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.
  • Loading branch information
TheCharlatan committed Jan 16, 2025
1 parent df8bf65 commit 57ba59c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57ba59c

Please sign in to comment.