validation: Move PruneOneBlockFile to BlockManager

[META] This is a pure refactor commit.

Move PruneBlockFile to BlockManager because:
1. PruneOneBlockFile only acts on BlockManager
2. Eliminates the need for callers (FindFilesToPrune{,Manual}) to have a
   reference to the larger ChainstateManager, just a reference to
   BlockManager is enough. See following commits.
This commit is contained in:
Carl Dong
2020-08-25 19:05:50 -04:00
parent 74f73c783d
commit f8d4975ab3
3 changed files with 12 additions and 12 deletions

View File

@@ -3912,12 +3912,12 @@ uint64_t CalculateCurrentUsage()
return retval;
}
void ChainstateManager::PruneOneBlockFile(const int fileNumber)
void BlockManager::PruneOneBlockFile(const int fileNumber)
{
AssertLockHeld(cs_main);
LOCK(cs_LastBlockFile);
for (const auto& entry : m_blockman.m_block_index) {
for (const auto& entry : m_block_index) {
CBlockIndex* pindex = entry.second;
if (pindex->nFile == fileNumber) {
pindex->nStatus &= ~BLOCK_HAVE_DATA;
@@ -3931,12 +3931,12 @@ void ChainstateManager::PruneOneBlockFile(const int fileNumber)
// to be downloaded again in order to consider its chain, at which
// point it would be considered as a candidate for
// m_blocks_unlinked or setBlockIndexCandidates.
auto range = m_blockman.m_blocks_unlinked.equal_range(pindex->pprev);
auto range = m_blocks_unlinked.equal_range(pindex->pprev);
while (range.first != range.second) {
std::multimap<CBlockIndex *, CBlockIndex *>::iterator _it = range.first;
range.first++;
if (_it->second == pindex) {
m_blockman.m_blocks_unlinked.erase(_it);
m_blocks_unlinked.erase(_it);
}
}
}
@@ -3972,7 +3972,7 @@ static void FindFilesToPruneManual(ChainstateManager& chainman, std::set<int>& s
for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) {
if (vinfoBlockFile[fileNumber].nSize == 0 || vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
continue;
chainman.PruneOneBlockFile(fileNumber);
chainman.m_blockman.PruneOneBlockFile(fileNumber);
setFilesToPrune.insert(fileNumber);
count++;
}
@@ -4047,7 +4047,7 @@ static void FindFilesToPrune(ChainstateManager& chainman, std::set<int>& setFile
if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
continue;
chainman.PruneOneBlockFile(fileNumber);
chainman.m_blockman.PruneOneBlockFile(fileNumber);
// Queue up the files for removal
setFilesToPrune.insert(fileNumber);
nCurrentUsage -= nBytesToPrune;