diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-20 22:00:11 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-10-18 14:08:49 +0200 |
commit | fa29d0b57cdeb91c8798d5c90ba9cc18085e99fb (patch) | |
tree | 70ac8833fe2de5938b96d988537e5d9955b7c141 /src/validation.cpp | |
parent | faf44876db555f7488c8df96db9fa88b793f897c (diff) | |
download | bitcoin-fa29d0b57cdeb91c8798d5c90ba9cc18085e99fb.tar.xz |
Move ::hashAssumeValid into ChainstateManager
This changes the assumed valid block for the bitcoin-chainstate
executable. Previously it was uint256{}, now it is defaultAssumeValid.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index db8a176a74..a6f71aba9f 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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); |