Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 4,500 Lines • ▼ Show 20 Lines | uint64_t CalculateCurrentUsage() { | ||||
uint64_t retval = 0; | uint64_t retval = 0; | ||||
for (const CBlockFileInfo &file : vinfoBlockFile) { | for (const CBlockFileInfo &file : vinfoBlockFile) { | ||||
retval += file.nSize + file.nUndoSize; | retval += file.nSize + file.nUndoSize; | ||||
} | } | ||||
return retval; | return retval; | ||||
} | } | ||||
void ChainstateManager::PruneOneBlockFile(const int fileNumber) { | void BlockManager::PruneOneBlockFile(const int fileNumber) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
LOCK(cs_LastBlockFile); | LOCK(cs_LastBlockFile); | ||||
for (const auto &entry : m_blockman.m_block_index) { | for (const auto &entry : m_block_index) { | ||||
CBlockIndex *pindex = entry.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 m_blocks_unlinked -- any block we prune would have | // Prune from m_blocks_unlinked -- any block we prune would have | ||||
// to be downloaded again in order to consider its chain, at which | // to be downloaded again in order to consider its chain, at which | ||||
// point it would be considered as a candidate for | // point it would be considered as a candidate for | ||||
// m_blocks_unlinked or setBlockIndexCandidates. | // m_blocks_unlinked or setBlockIndexCandidates. | ||||
auto range = | auto range = m_blocks_unlinked.equal_range(pindex->pprev); | ||||
m_blockman.m_blocks_unlinked.equal_range(pindex->pprev); | |||||
while (range.first != range.second) { | while (range.first != range.second) { | ||||
std::multimap<CBlockIndex *, CBlockIndex *>::iterator _it = | std::multimap<CBlockIndex *, CBlockIndex *>::iterator _it = | ||||
range.first; | range.first; | ||||
range.first++; | range.first++; | ||||
if (_it->second == pindex) { | if (_it->second == pindex) { | ||||
m_blockman.m_blocks_unlinked.erase(_it); | m_blocks_unlinked.erase(_it); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
vinfoBlockFile[fileNumber].SetNull(); | vinfoBlockFile[fileNumber].SetNull(); | ||||
setDirtyFileInfo.insert(fileNumber); | setDirtyFileInfo.insert(fileNumber); | ||||
} | } | ||||
Show All 27 Lines | unsigned int nLastBlockWeCanPrune = | ||||
std::min((unsigned)nManualPruneHeight, | std::min((unsigned)nManualPruneHeight, | ||||
::ChainActive().Tip()->nHeight - MIN_BLOCKS_TO_KEEP); | ::ChainActive().Tip()->nHeight - MIN_BLOCKS_TO_KEEP); | ||||
int count = 0; | int count = 0; | ||||
for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) { | for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) { | ||||
if (vinfoBlockFile[fileNumber].nSize == 0 || | if (vinfoBlockFile[fileNumber].nSize == 0 || | ||||
vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) { | vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) { | ||||
continue; | continue; | ||||
} | } | ||||
chainman.PruneOneBlockFile(fileNumber); | chainman.m_blockman.PruneOneBlockFile(fileNumber); | ||||
setFilesToPrune.insert(fileNumber); | setFilesToPrune.insert(fileNumber); | ||||
count++; | count++; | ||||
} | } | ||||
LogPrintf("Prune (Manual): prune_height=%d removed %d blk/rev pairs\n", | LogPrintf("Prune (Manual): prune_height=%d removed %d blk/rev pairs\n", | ||||
nLastBlockWeCanPrune, count); | nLastBlockWeCanPrune, count); | ||||
} | } | ||||
/* This function is called from the RPC code for pruneblockchain */ | /* This function is called from the RPC code for pruneblockchain */ | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | if (nCurrentUsage + nBuffer >= nPruneTarget) { | ||||
} | } | ||||
// don't prune files that could have a block within | // don't prune files that could have a block within | ||||
// MIN_BLOCKS_TO_KEEP of the main chain's tip but keep scanning | // MIN_BLOCKS_TO_KEEP of the main chain's tip but keep scanning | ||||
if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) { | if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) { | ||||
continue; | continue; | ||||
} | } | ||||
chainman.PruneOneBlockFile(fileNumber); | chainman.m_blockman.PruneOneBlockFile(fileNumber); | ||||
// Queue up the files for removal | // Queue up the files for removal | ||||
setFilesToPrune.insert(fileNumber); | setFilesToPrune.insert(fileNumber); | ||||
nCurrentUsage -= nBytesToPrune; | nCurrentUsage -= nBytesToPrune; | ||||
count++; | count++; | ||||
} | } | ||||
} | } | ||||
LogPrint(BCLog::PRUNE, | LogPrint(BCLog::PRUNE, | ||||
▲ Show 20 Lines • Show All 1,477 Lines • Show Last 20 Lines |