Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 5,054 Lines • ▼ Show 20 Lines | static void CheckBlockIndex(const Consensus::Params &consensusParams) { | ||||
// require that chainActive has been initialized.) | // require that chainActive has been initialized.) | ||||
if (chainActive.Height() < 0) { | if (chainActive.Height() < 0) { | ||||
assert(mapBlockIndex.size() <= 1); | assert(mapBlockIndex.size() <= 1); | ||||
return; | return; | ||||
} | } | ||||
// Build forward-pointing map of the entire block tree. | // Build forward-pointing map of the entire block tree. | ||||
std::multimap<CBlockIndex *, CBlockIndex *> forward; | std::multimap<CBlockIndex *, CBlockIndex *> forward; | ||||
for (BlockMap::iterator it = mapBlockIndex.begin(); | for (const std::pair<const uint256, CBlockIndex *> &it : mapBlockIndex) { | ||||
it != mapBlockIndex.end(); it++) { | forward.emplace(it.second->pprev, it.second); | ||||
forward.insert(std::make_pair(it->second->pprev, it->second)); | |||||
} | } | ||||
assert(forward.size() == mapBlockIndex.size()); | assert(forward.size() == mapBlockIndex.size()); | ||||
std::pair<std::multimap<CBlockIndex *, CBlockIndex *>::iterator, | std::pair<std::multimap<CBlockIndex *, CBlockIndex *>::iterator, | ||||
std::multimap<CBlockIndex *, CBlockIndex *>::iterator> | std::multimap<CBlockIndex *, CBlockIndex *>::iterator> | ||||
rangeGenesis = forward.equal_range(nullptr); | rangeGenesis = forward.equal_range(nullptr); | ||||
CBlockIndex *pindex = rangeGenesis.first->second; | CBlockIndex *pindex = rangeGenesis.first->second; | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | while (pindex != nullptr) { | ||||
// setBlockIndexCandidates, then it must be in mapBlocksUnlinked. | // setBlockIndexCandidates, then it must be in mapBlocksUnlinked. | ||||
if (!CBlockIndexWorkComparator()(pindex, chainActive.Tip()) && | if (!CBlockIndexWorkComparator()(pindex, chainActive.Tip()) && | ||||
setBlockIndexCandidates.count(pindex) == 0) { | setBlockIndexCandidates.count(pindex) == 0) { | ||||
if (pindexFirstInvalid == nullptr) { | if (pindexFirstInvalid == nullptr) { | ||||
assert(foundInUnlinked); | assert(foundInUnlinked); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Perhaps too slow | |||||
// assert(pindex->GetBlockHash() == pindex->GetBlockHeader().GetHash()); | // assert(pindex->GetBlockHash() == pindex->GetBlockHeader().GetHash()); | ||||
// // Perhaps too slow | |||||
// End: actual consistency checks. | // End: actual consistency checks. | ||||
// Try descending into the first subnode. | // Try descending into the first subnode. | ||||
std::pair<std::multimap<CBlockIndex *, CBlockIndex *>::iterator, | std::pair<std::multimap<CBlockIndex *, CBlockIndex *>::iterator, | ||||
std::multimap<CBlockIndex *, CBlockIndex *>::iterator> | std::multimap<CBlockIndex *, CBlockIndex *>::iterator> | ||||
range = forward.equal_range(pindex); | range = forward.equal_range(pindex); | ||||
if (range.first != range.second) { | if (range.first != range.second) { | ||||
// A subnode was found. | // A subnode was found. | ||||
▲ Show 20 Lines • Show All 244 Lines • Show Last 20 Lines |