Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 4,099 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/** | /** | ||||
* Prune a block file (modify associated database entries) | * Prune a block file (modify associated database entries) | ||||
*/ | */ | ||||
void PruneOneBlockFile(const int fileNumber) { | void PruneOneBlockFile(const int fileNumber) { | ||||
LOCK(cs_LastBlockFile); | LOCK(cs_LastBlockFile); | ||||
for (const std::pair<const uint256, CBlockIndex *> &it : mapBlockIndex) { | for (const auto &entry : mapBlockIndex) { | ||||
CBlockIndex *pindex = it.second; | CBlockIndex *pindex = entry.second; | ||||
if (pindex->nFile == fileNumber) { | if (pindex->nFile == fileNumber) { | ||||
pindex->nStatus = pindex->nStatus.withData(false).withUndo(false); | pindex->nStatus = pindex->nStatus.withData(false).withUndo(false); | ||||
pindex->nFile = 0; | pindex->nFile = 0; | ||||
pindex->nDataPos = 0; | pindex->nDataPos = 0; | ||||
pindex->nUndoPos = 0; | pindex->nUndoPos = 0; | ||||
setDirtyBlockIndex.insert(pindex); | setDirtyBlockIndex.insert(pindex); | ||||
// Prune from mapBlocksUnlinked -- any block we prune would have | // Prune from mapBlocksUnlinked -- any block we prune would have | ||||
▲ Show 20 Lines • Show All 693 Lines • ▼ Show 20 Lines | while (chainActive.Height() >= nHeight) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
// Reduce validity flag and have-data flags. | // Reduce validity flag and have-data flags. | ||||
// We do this after actual disconnecting, otherwise we'll end up writing the | // We do this after actual disconnecting, otherwise we'll end up writing the | ||||
// lack of data to disk before writing the chainstate, resulting in a | // lack of data to disk before writing the chainstate, resulting in a | ||||
// failure to continue if interrupted. | // failure to continue if interrupted. | ||||
for (const std::pair<uint256, CBlockIndex *> &p : mapBlockIndex) { | for (const auto &entry : mapBlockIndex) { | ||||
CBlockIndex *pindexIter = p.second; | CBlockIndex *pindexIter = entry.second; | ||||
if (pindexIter->IsValid(BlockValidity::TRANSACTIONS) && | if (pindexIter->IsValid(BlockValidity::TRANSACTIONS) && | ||||
pindexIter->nChainTx) { | pindexIter->nChainTx) { | ||||
setBlockIndexCandidates.insert(pindexIter); | setBlockIndexCandidates.insert(pindexIter); | ||||
} | } | ||||
} | } | ||||
if (chainActive.Tip() != nullptr) { | if (chainActive.Tip() != nullptr) { | ||||
// We can't prune block index candidates based on our tip if we have | // We can't prune block index candidates based on our tip if we have | ||||
▲ Show 20 Lines • Show All 274 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 (const std::pair<const uint256, CBlockIndex *> &it : mapBlockIndex) { | for (auto &entry : mapBlockIndex) { | ||||
forward.emplace(it.second->pprev, it.second); | forward.emplace(entry.second->pprev, entry.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 462 Lines • Show Last 20 Lines |