Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 4,021 Lines • ▼ Show 20 Lines | bool BlockManager::AcceptBlockHeader(const Config &config, | ||||
BlockValidationState &state, | BlockValidationState &state, | ||||
CBlockIndex **ppindex) { | CBlockIndex **ppindex) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
// Check for duplicate | // Check for duplicate | ||||
BlockHash hash = block.GetHash(); | BlockHash hash = block.GetHash(); | ||||
BlockMap::iterator miSelf = m_block_index.find(hash); | BlockMap::iterator miSelf = m_block_index.find(hash); | ||||
CBlockIndex *pindex = nullptr; | |||||
if (hash != chainparams.GetConsensus().hashGenesisBlock) { | if (hash != chainparams.GetConsensus().hashGenesisBlock) { | ||||
if (miSelf != m_block_index.end()) { | if (miSelf != m_block_index.end()) { | ||||
// Block header is already known. | // Block header is already known. | ||||
pindex = miSelf->second; | CBlockIndex *pindex = miSelf->second; | ||||
if (ppindex) { | if (ppindex) { | ||||
*ppindex = pindex; | *ppindex = pindex; | ||||
} | } | ||||
if (pindex->nStatus.isInvalid()) { | if (pindex->nStatus.isInvalid()) { | ||||
LogPrintf("ERROR: %s: block %s is marked invalid\n", __func__, | LogPrintf("ERROR: %s: block %s is marked invalid\n", __func__, | ||||
hash.ToString()); | hash.ToString()); | ||||
return state.Invalid( | return state.Invalid( | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | if (hash != chainparams.GetConsensus().hashGenesisBlock) { | ||||
return state.Invalid( | return state.Invalid( | ||||
BlockValidationResult::BLOCK_INVALID_PREV, | BlockValidationResult::BLOCK_INVALID_PREV, | ||||
"bad-prevblk"); | "bad-prevblk"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (pindex == nullptr) { | CBlockIndex *pindex = AddToBlockIndex(block); | ||||
pindex = AddToBlockIndex(block); | |||||
} | |||||
if (ppindex) { | if (ppindex) { | ||||
*ppindex = pindex; | *ppindex = pindex; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,192 Lines • Show Last 20 Lines |