|
|
|
@ -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)
|
|
|
|
|