mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
Move AcceptBlockHeader to ChainstateManager
This is needed for the next commit.
This commit is contained in:
parent
fa3d62cf7b
commit
fa47b5c100
2 changed files with 21 additions and 21 deletions
|
@ -3260,14 +3260,14 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat
|
||||||
return true;
|
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);
|
AssertLockHeld(cs_main);
|
||||||
// Check for duplicate
|
// Check for duplicate
|
||||||
uint256 hash = block.GetHash();
|
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 (hash != chainparams.GetConsensus().hashGenesisBlock) {
|
||||||
if (miSelf != m_block_index.end()) {
|
if (miSelf != m_blockman.m_block_index.end()) {
|
||||||
// Block header is already known.
|
// Block header is already known.
|
||||||
CBlockIndex* pindex = miSelf->second;
|
CBlockIndex* pindex = miSelf->second;
|
||||||
if (ppindex)
|
if (ppindex)
|
||||||
|
@ -3286,8 +3286,8 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
|
||||||
|
|
||||||
// Get prev block index
|
// Get prev block index
|
||||||
CBlockIndex* pindexPrev = nullptr;
|
CBlockIndex* pindexPrev = nullptr;
|
||||||
BlockMap::iterator mi = m_block_index.find(block.hashPrevBlock);
|
BlockMap::iterator mi{m_blockman.m_block_index.find(block.hashPrevBlock)};
|
||||||
if (mi == m_block_index.end()) {
|
if (mi == m_blockman.m_block_index.end()) {
|
||||||
LogPrint(BCLog::VALIDATION, "%s: %s prev block not found\n", __func__, hash.ToString());
|
LogPrint(BCLog::VALIDATION, "%s: %s prev block not found\n", __func__, hash.ToString());
|
||||||
return state.Invalid(BlockValidationResult::BLOCK_MISSING_PREV, "prev-blk-not-found");
|
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());
|
LogPrint(BCLog::VALIDATION, "%s: %s prev block invalid\n", __func__, hash.ToString());
|
||||||
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk");
|
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());
|
LogPrint(BCLog::VALIDATION, "%s: Consensus::ContextualCheckBlockHeader: %s, %s\n", __func__, hash.ToString(), state.ToString());
|
||||||
return false;
|
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
|
// 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,
|
// optimization, in the common case of adding a new block to the tip,
|
||||||
// we don't need to iterate over the failed blocks list.
|
// 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) {
|
if (pindexPrev->GetAncestor(failedit->nHeight) == failedit) {
|
||||||
assert(failedit->nStatus & BLOCK_FAILED_VALID);
|
assert(failedit->nStatus & BLOCK_FAILED_VALID);
|
||||||
CBlockIndex* invalid_walk = pindexPrev;
|
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)
|
if (ppindex)
|
||||||
*ppindex = pindex;
|
*ppindex = pindex;
|
||||||
|
@ -3356,8 +3356,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
for (const CBlockHeader& header : headers) {
|
for (const CBlockHeader& header : headers) {
|
||||||
CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast
|
CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast
|
||||||
bool accepted = m_blockman.AcceptBlockHeader(
|
bool accepted{AcceptBlockHeader(header, state, chainparams, &pindex)};
|
||||||
header, state, chainparams, &pindex);
|
|
||||||
ActiveChainstate().CheckBlockIndex();
|
ActiveChainstate().CheckBlockIndex();
|
||||||
|
|
||||||
if (!accepted) {
|
if (!accepted) {
|
||||||
|
@ -3387,7 +3386,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
|
||||||
CBlockIndex *pindexDummy = nullptr;
|
CBlockIndex *pindexDummy = nullptr;
|
||||||
CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy;
|
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();
|
CheckBlockIndex();
|
||||||
|
|
||||||
if (!accepted_header)
|
if (!accepted_header)
|
||||||
|
|
|
@ -454,16 +454,6 @@ public:
|
||||||
//! Mark one block file as pruned (modify associated database entries)
|
//! Mark one block file as pruned (modify associated database entries)
|
||||||
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
/**
|
|
||||||
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
|
|
||||||
* that it doesn't descend from an invalid block, and then add it to m_block_index.
|
|
||||||
*/
|
|
||||||
bool AcceptBlockHeader(
|
|
||||||
const CBlockHeader& block,
|
|
||||||
BlockValidationState& state,
|
|
||||||
const CChainParams& chainparams,
|
|
||||||
CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
|
||||||
|
|
||||||
CBlockIndex* LookupBlockIndex(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
CBlockIndex* LookupBlockIndex(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
//! Returns last CBlockIndex* that is a checkpoint
|
//! Returns last CBlockIndex* that is a checkpoint
|
||||||
|
@ -902,6 +892,17 @@ private:
|
||||||
CAutoFile& coins_file,
|
CAutoFile& coins_file,
|
||||||
const SnapshotMetadata& metadata);
|
const SnapshotMetadata& metadata);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
|
||||||
|
* that it doesn't descend from an invalid block, and then add it to m_block_index.
|
||||||
|
*/
|
||||||
|
bool AcceptBlockHeader(
|
||||||
|
const CBlockHeader& block,
|
||||||
|
BlockValidationState& state,
|
||||||
|
const CChainParams& chainparams,
|
||||||
|
CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
friend CChainState;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::thread m_load_block;
|
std::thread m_load_block;
|
||||||
//! A single BlockManager instance is shared across each constructed
|
//! A single BlockManager instance is shared across each constructed
|
||||||
|
|
Loading…
Add table
Reference in a new issue