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.
This commit is contained in:
TheCharlatan 2025-04-20 12:48:43 +02:00
parent 008748c3ae
commit e1f88913b7
No known key found for this signature in database
GPG key ID: 9B79B45691DB4173

View file

@ -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;
}
}