diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-11-23 20:05:07 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-12-15 17:46:01 +0100 |
commit | fa47b5c100f81c65c15b5a6afaf6c91bc0861264 (patch) | |
tree | 61bb183b370cec9573e75132bc8a211cb416f7a0 /src/validation.cpp | |
parent | fa3d62cf7b3501a056b34c5458c14d2fe6a55bd7 (diff) |
Move AcceptBlockHeader to ChainstateManager
This is needed for the next commit.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index c2d86d89c5..60c01ad7b6 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3260,14 +3260,14 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat return true; } -bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex) +bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex) { AssertLockHeld(cs_main); // Check for duplicate uint256 hash = block.GetHash(); - BlockMap::iterator miSelf = m_block_index.find(hash); + BlockMap::iterator miSelf{m_blockman.m_block_index.find(hash)}; if (hash != chainparams.GetConsensus().hashGenesisBlock) { - if (miSelf != m_block_index.end()) { + if (miSelf != m_blockman.m_block_index.end()) { // Block header is already known. CBlockIndex* pindex = miSelf->second; if (ppindex) @@ -3286,8 +3286,8 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS // Get prev block index CBlockIndex* pindexPrev = nullptr; - BlockMap::iterator mi = m_block_index.find(block.hashPrevBlock); - if (mi == m_block_index.end()) { + BlockMap::iterator mi{m_blockman.m_block_index.find(block.hashPrevBlock)}; + if (mi == m_blockman.m_block_index.end()) { LogPrint(BCLog::VALIDATION, "%s: %s prev block not found\n", __func__, hash.ToString()); return state.Invalid(BlockValidationResult::BLOCK_MISSING_PREV, "prev-blk-not-found"); } @@ -3296,7 +3296,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS LogPrint(BCLog::VALIDATION, "%s: %s prev block invalid\n", __func__, hash.ToString()); return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk"); } - if (!ContextualCheckBlockHeader(block, state, *this, chainparams, pindexPrev, GetAdjustedTime())) { + if (!ContextualCheckBlockHeader(block, state, m_blockman, chainparams, pindexPrev, GetAdjustedTime())) { LogPrint(BCLog::VALIDATION, "%s: Consensus::ContextualCheckBlockHeader: %s, %s\n", __func__, hash.ToString(), state.ToString()); return false; } @@ -3325,7 +3325,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS // hasn't been validated up to BLOCK_VALID_SCRIPTS. This is a performance // optimization, in the common case of adding a new block to the tip, // we don't need to iterate over the failed blocks list. - for (const CBlockIndex* failedit : m_failed_blocks) { + for (const CBlockIndex* failedit : m_blockman.m_failed_blocks) { if (pindexPrev->GetAncestor(failedit->nHeight) == failedit) { assert(failedit->nStatus & BLOCK_FAILED_VALID); CBlockIndex* invalid_walk = pindexPrev; @@ -3340,7 +3340,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS } } } - CBlockIndex* pindex = AddToBlockIndex(block); + CBlockIndex* pindex{m_blockman.AddToBlockIndex(block)}; if (ppindex) *ppindex = pindex; @@ -3356,8 +3356,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>& LOCK(cs_main); for (const CBlockHeader& header : headers) { CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast - bool accepted = m_blockman.AcceptBlockHeader( - header, state, chainparams, &pindex); + bool accepted{AcceptBlockHeader(header, state, chainparams, &pindex)}; ActiveChainstate().CheckBlockIndex(); if (!accepted) { @@ -3387,7 +3386,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block CBlockIndex *pindexDummy = nullptr; CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy; - bool accepted_header = m_blockman.AcceptBlockHeader(block, state, m_params, &pindex); + bool accepted_header{m_chainman.AcceptBlockHeader(block, state, m_params, &pindex)}; CheckBlockIndex(); if (!accepted_header) |