Move ::hashAssumeValid into ChainstateManager

This changes the assumed valid block for the bitcoin-chainstate
executable. Previously it was uint256{}, now it is defaultAssumeValid.
This commit is contained in:
MacroFake
2022-07-20 22:00:11 +02:00
parent faf44876db
commit fa29d0b57c
6 changed files with 26 additions and 14 deletions

View File

@@ -124,7 +124,6 @@ bool g_parallel_script_checks{false};
bool fCheckBlockIndex = false;
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
uint256 hashAssumeValid;
arith_uint256 nMinimumChainWork;
const CBlockIndex* Chainstate::FindForkInGlobalIndex(const CBlockLocator& locator) const
@@ -2036,13 +2035,13 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
}
bool fScriptChecks = true;
if (!hashAssumeValid.IsNull()) {
if (!m_chainman.AssumedValidBlock().IsNull()) {
// We've been configured with the hash of a block which has been externally verified to have a valid history.
// A suitable default value is included with the software and updated from time to time. Because validity
// relative to a piece of software is an objective fact these defaults can be easily reviewed.
// This setting doesn't force the selection of any particular chain but makes validating some faster by
// effectively caching the result of part of the verification.
BlockMap::const_iterator it = m_blockman.m_block_index.find(hashAssumeValid);
BlockMap::const_iterator it{m_blockman.m_block_index.find(m_chainman.AssumedValidBlock())};
if (it != m_blockman.m_block_index.end()) {
if (it->second.GetAncestor(pindex->nHeight) == pindex &&
m_chainman.m_best_header->GetAncestor(pindex->nHeight) == pindex &&
@@ -5244,6 +5243,20 @@ void ChainstateManager::ResetChainstates()
m_active_chainstate = nullptr;
}
/**
* Apply default chain params to nullopt members.
* This helps to avoid coding errors around the accidental use of the compare
* operators that accept nullopt, thus ignoring the intended default value.
*/
static ChainstateManager::Options&& Flatten(ChainstateManager::Options&& opts)
{
if (!opts.assumed_valid_block.has_value()) opts.assumed_valid_block = opts.chainparams.GetConsensus().defaultAssumeValid;
Assert(opts.adjusted_time_callback);
return std::move(opts);
}
ChainstateManager::ChainstateManager(Options options) : m_options{Flatten(std::move(options))} {}
ChainstateManager::~ChainstateManager()
{
LOCK(::cs_main);