From e1f88913b7b416ae2cedf449a9fef55c4abc512a Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Sun, 20 Apr 2025 12:48:43 +0200 Subject: [PATCH] validation: Move SetBestBlock out of ConnectBlock This is a part of a series of commits for removing access to the CCoinsViewCache in consensus verification functions. The goal is to allow calling verification functions with pre-fetched, or a user-defined set of coins. --- src/validation.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index ea638703b89..608d1b14103 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2475,8 +2475,6 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, // Special case for the genesis block, skipping connection of its transactions // (its coinbase is unspendable) if (block_hash == params.GetConsensus().hashGenesisBlock) { - if (!fJustCheck) - view.SetBestBlock(pindex->GetBlockHash()); return true; } @@ -2676,9 +2674,6 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, m_blockman.m_dirty_blockindex.insert(pindex); } - // add this block to the view's block chain - view.SetBestBlock(pindex->GetBlockHash()); - const auto time_6{SteadyClock::now()}; m_chainman.time_index += time_6 - time_5; LogDebug(BCLog::BENCH, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n", @@ -3253,6 +3248,8 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew, LogError("%s: ConnectBlock %s failed, %s\n", __func__, pindexNew->GetBlockHash().ToString(), state.ToString()); return false; } + // add this block to the view's block chain + view.SetBestBlock(block_hash); time_3 = SteadyClock::now(); m_chainman.time_connect_total += time_3 - time_2; assert(m_chainman.num_blocks_total > 0); @@ -4917,6 +4914,7 @@ VerifyDBResult CVerifyDB::VerifyDB( LogPrintf("Verification error: found unconnectable block at %d, hash=%s (%s)\n", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString()); return VerifyDBResult::CORRUPTED_BLOCK_DB; } + coins.SetBestBlock(block_hash); if (chainstate.m_chainman.m_interrupt) return VerifyDBResult::INTERRUPTED; } }