Skip to content

Commit fa47b5c

Browse files
author
MarcoFalke
committed
Move AcceptBlockHeader to ChainstateManager
This is needed for the next commit.
1 parent fa3d62c commit fa47b5c

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/validation.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,14 +3260,14 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat
32603260
return true;
32613261
}
32623262

3263-
bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex)
3263+
bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex)
32643264
{
32653265
AssertLockHeld(cs_main);
32663266
// Check for duplicate
32673267
uint256 hash = block.GetHash();
3268-
BlockMap::iterator miSelf = m_block_index.find(hash);
3268+
BlockMap::iterator miSelf{m_blockman.m_block_index.find(hash)};
32693269
if (hash != chainparams.GetConsensus().hashGenesisBlock) {
3270-
if (miSelf != m_block_index.end()) {
3270+
if (miSelf != m_blockman.m_block_index.end()) {
32713271
// Block header is already known.
32723272
CBlockIndex* pindex = miSelf->second;
32733273
if (ppindex)
@@ -3286,8 +3286,8 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
32863286

32873287
// Get prev block index
32883288
CBlockIndex* pindexPrev = nullptr;
3289-
BlockMap::iterator mi = m_block_index.find(block.hashPrevBlock);
3290-
if (mi == m_block_index.end()) {
3289+
BlockMap::iterator mi{m_blockman.m_block_index.find(block.hashPrevBlock)};
3290+
if (mi == m_blockman.m_block_index.end()) {
32913291
LogPrint(BCLog::VALIDATION, "%s: %s prev block not found\n", __func__, hash.ToString());
32923292
return state.Invalid(BlockValidationResult::BLOCK_MISSING_PREV, "prev-blk-not-found");
32933293
}
@@ -3296,7 +3296,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
32963296
LogPrint(BCLog::VALIDATION, "%s: %s prev block invalid\n", __func__, hash.ToString());
32973297
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk");
32983298
}
3299-
if (!ContextualCheckBlockHeader(block, state, *this, chainparams, pindexPrev, GetAdjustedTime())) {
3299+
if (!ContextualCheckBlockHeader(block, state, m_blockman, chainparams, pindexPrev, GetAdjustedTime())) {
33003300
LogPrint(BCLog::VALIDATION, "%s: Consensus::ContextualCheckBlockHeader: %s, %s\n", __func__, hash.ToString(), state.ToString());
33013301
return false;
33023302
}
@@ -3325,7 +3325,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
33253325
// hasn't been validated up to BLOCK_VALID_SCRIPTS. This is a performance
33263326
// optimization, in the common case of adding a new block to the tip,
33273327
// we don't need to iterate over the failed blocks list.
3328-
for (const CBlockIndex* failedit : m_failed_blocks) {
3328+
for (const CBlockIndex* failedit : m_blockman.m_failed_blocks) {
33293329
if (pindexPrev->GetAncestor(failedit->nHeight) == failedit) {
33303330
assert(failedit->nStatus & BLOCK_FAILED_VALID);
33313331
CBlockIndex* invalid_walk = pindexPrev;
@@ -3340,7 +3340,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
33403340
}
33413341
}
33423342
}
3343-
CBlockIndex* pindex = AddToBlockIndex(block);
3343+
CBlockIndex* pindex{m_blockman.AddToBlockIndex(block)};
33443344

33453345
if (ppindex)
33463346
*ppindex = pindex;
@@ -3356,8 +3356,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
33563356
LOCK(cs_main);
33573357
for (const CBlockHeader& header : headers) {
33583358
CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast
3359-
bool accepted = m_blockman.AcceptBlockHeader(
3360-
header, state, chainparams, &pindex);
3359+
bool accepted{AcceptBlockHeader(header, state, chainparams, &pindex)};
33613360
ActiveChainstate().CheckBlockIndex();
33623361

33633362
if (!accepted) {
@@ -3387,7 +3386,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
33873386
CBlockIndex *pindexDummy = nullptr;
33883387
CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy;
33893388

3390-
bool accepted_header = m_blockman.AcceptBlockHeader(block, state, m_params, &pindex);
3389+
bool accepted_header{m_chainman.AcceptBlockHeader(block, state, m_params, &pindex)};
33913390
CheckBlockIndex();
33923391

33933392
if (!accepted_header)

src/validation.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,6 @@ class BlockManager
454454
//! Mark one block file as pruned (modify associated database entries)
455455
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
456456

457-
/**
458-
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
459-
* that it doesn't descend from an invalid block, and then add it to m_block_index.
460-
*/
461-
bool AcceptBlockHeader(
462-
const CBlockHeader& block,
463-
BlockValidationState& state,
464-
const CChainParams& chainparams,
465-
CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
466-
467457
CBlockIndex* LookupBlockIndex(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
468458

469459
//! Returns last CBlockIndex* that is a checkpoint
@@ -902,6 +892,17 @@ class ChainstateManager
902892
CAutoFile& coins_file,
903893
const SnapshotMetadata& metadata);
904894

895+
/**
896+
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
897+
* that it doesn't descend from an invalid block, and then add it to m_block_index.
898+
*/
899+
bool AcceptBlockHeader(
900+
const CBlockHeader& block,
901+
BlockValidationState& state,
902+
const CChainParams& chainparams,
903+
CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
904+
friend CChainState;
905+
905906
public:
906907
std::thread m_load_block;
907908
//! A single BlockManager instance is shared across each constructed

0 commit comments

Comments
 (0)