Skip to content

Commit f8d4975

Browse files
committed
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.
1 parent 74f73c7 commit f8d4975

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/validation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3912,12 +3912,12 @@ uint64_t CalculateCurrentUsage()
39123912
return retval;
39133913
}
39143914

3915-
void ChainstateManager::PruneOneBlockFile(const int fileNumber)
3915+
void BlockManager::PruneOneBlockFile(const int fileNumber)
39163916
{
39173917
AssertLockHeld(cs_main);
39183918
LOCK(cs_LastBlockFile);
39193919

3920-
for (const auto& entry : m_blockman.m_block_index) {
3920+
for (const auto& entry : m_block_index) {
39213921
CBlockIndex* pindex = entry.second;
39223922
if (pindex->nFile == fileNumber) {
39233923
pindex->nStatus &= ~BLOCK_HAVE_DATA;
@@ -3931,12 +3931,12 @@ void ChainstateManager::PruneOneBlockFile(const int fileNumber)
39313931
// to be downloaded again in order to consider its chain, at which
39323932
// point it would be considered as a candidate for
39333933
// m_blocks_unlinked or setBlockIndexCandidates.
3934-
auto range = m_blockman.m_blocks_unlinked.equal_range(pindex->pprev);
3934+
auto range = m_blocks_unlinked.equal_range(pindex->pprev);
39353935
while (range.first != range.second) {
39363936
std::multimap<CBlockIndex *, CBlockIndex *>::iterator _it = range.first;
39373937
range.first++;
39383938
if (_it->second == pindex) {
3939-
m_blockman.m_blocks_unlinked.erase(_it);
3939+
m_blocks_unlinked.erase(_it);
39403940
}
39413941
}
39423942
}
@@ -3972,7 +3972,7 @@ static void FindFilesToPruneManual(ChainstateManager& chainman, std::set<int>& s
39723972
for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) {
39733973
if (vinfoBlockFile[fileNumber].nSize == 0 || vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
39743974
continue;
3975-
chainman.PruneOneBlockFile(fileNumber);
3975+
chainman.m_blockman.PruneOneBlockFile(fileNumber);
39763976
setFilesToPrune.insert(fileNumber);
39773977
count++;
39783978
}
@@ -4047,7 +4047,7 @@ static void FindFilesToPrune(ChainstateManager& chainman, std::set<int>& setFile
40474047
if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
40484048
continue;
40494049

4050-
chainman.PruneOneBlockFile(fileNumber);
4050+
chainman.m_blockman.PruneOneBlockFile(fileNumber);
40514051
// Queue up the files for removal
40524052
setFilesToPrune.insert(fileNumber);
40534053
nCurrentUsage -= nBytesToPrune;

src/validation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ class BlockManager {
407407
/** Create a new block index entry for a given block hash */
408408
CBlockIndex* InsertBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
409409

410+
//! Mark one block file as pruned (modify associated database entries)
411+
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
412+
410413
/**
411414
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
412415
* that it doesn't descend from an invalid block, and then add it to m_block_index.
@@ -903,9 +906,6 @@ class ChainstateManager
903906
*/
904907
bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
905908

906-
//! Mark one block file as pruned (modify associated database entries)
907-
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
908-
909909
//! Load the block tree and coins database from disk, initializing state if we're running with -reindex
910910
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
911911

src/wallet/test/wallet_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
126126
// Prune the older block file.
127127
{
128128
LOCK(cs_main);
129-
Assert(m_node.chainman)->PruneOneBlockFile(oldTip->GetBlockPos().nFile);
129+
Assert(m_node.chainman)->m_blockman.PruneOneBlockFile(oldTip->GetBlockPos().nFile);
130130
}
131131
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
132132

@@ -152,7 +152,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
152152
// Prune the remaining block file.
153153
{
154154
LOCK(cs_main);
155-
Assert(m_node.chainman)->PruneOneBlockFile(newTip->GetBlockPos().nFile);
155+
Assert(m_node.chainman)->m_blockman.PruneOneBlockFile(newTip->GetBlockPos().nFile);
156156
}
157157
UnlinkPrunedFiles({newTip->GetBlockPos().nFile});
158158

@@ -189,7 +189,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
189189
// Prune the older block file.
190190
{
191191
LOCK(cs_main);
192-
Assert(m_node.chainman)->PruneOneBlockFile(oldTip->GetBlockPos().nFile);
192+
Assert(m_node.chainman)->m_blockman.PruneOneBlockFile(oldTip->GetBlockPos().nFile);
193193
}
194194
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
195195

0 commit comments

Comments
 (0)