Skip to content

Commit fa24d49

Browse files
author
MarcoFalke
committed
validation: Make PruneOneBlockFile() a member of ChainstateManager
1 parent fa84b1c commit fa24d49

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

src/validation.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
196196
std::unique_ptr<CBlockTreeDB> pblocktree;
197197

198198
// See definition for documentation
199-
static void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight);
200-
static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight);
199+
static void FindFilesToPruneManual(ChainstateManager& chainman, std::set<int>& setFilesToPrune, int nManualPruneHeight);
200+
static void FindFilesToPrune(ChainstateManager& chainman, std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight);
201201
bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = nullptr);
202202
static FILE* OpenUndoFile(const FlatFilePos &pos, bool fReadOnly = false);
203203
static FlatFileSeq BlockFileSeq();
@@ -2282,11 +2282,11 @@ bool CChainState::FlushStateToDisk(
22822282
if (nManualPruneHeight > 0) {
22832283
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune (manual)", BCLog::BENCH);
22842284

2285-
FindFilesToPruneManual(setFilesToPrune, nManualPruneHeight);
2285+
FindFilesToPruneManual(g_chainman, setFilesToPrune, nManualPruneHeight);
22862286
} else {
22872287
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune", BCLog::BENCH);
22882288

2289-
FindFilesToPrune(setFilesToPrune, chainparams.PruneAfterHeight());
2289+
FindFilesToPrune(g_chainman, setFilesToPrune, chainparams.PruneAfterHeight());
22902290
fCheckForPruning = false;
22912291
}
22922292
if (!setFilesToPrune.empty()) {
@@ -3895,12 +3895,12 @@ uint64_t CalculateCurrentUsage()
38953895
return retval;
38963896
}
38973897

3898-
/* Prune a block file (modify associated database entries)*/
3899-
void PruneOneBlockFile(const int fileNumber)
3898+
void ChainstateManager::PruneOneBlockFile(const int fileNumber)
39003899
{
3900+
AssertLockHeld(cs_main);
39013901
LOCK(cs_LastBlockFile);
39023902

3903-
for (const auto& entry : g_chainman.BlockIndex()) {
3903+
for (const auto& entry : m_blockman.m_block_index) {
39043904
CBlockIndex* pindex = entry.second;
39053905
if (pindex->nFile == fileNumber) {
39063906
pindex->nStatus &= ~BLOCK_HAVE_DATA;
@@ -3914,12 +3914,12 @@ void PruneOneBlockFile(const int fileNumber)
39143914
// to be downloaded again in order to consider its chain, at which
39153915
// point it would be considered as a candidate for
39163916
// m_blocks_unlinked or setBlockIndexCandidates.
3917-
auto range = g_chainman.m_blockman.m_blocks_unlinked.equal_range(pindex->pprev);
3917+
auto range = m_blockman.m_blocks_unlinked.equal_range(pindex->pprev);
39183918
while (range.first != range.second) {
39193919
std::multimap<CBlockIndex *, CBlockIndex *>::iterator _it = range.first;
39203920
range.first++;
39213921
if (_it->second == pindex) {
3922-
g_chainman.m_blockman.m_blocks_unlinked.erase(_it);
3922+
m_blockman.m_blocks_unlinked.erase(_it);
39233923
}
39243924
}
39253925
}
@@ -3941,7 +3941,7 @@ void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune)
39413941
}
39423942

39433943
/* Calculate the block/rev files to delete based on height specified by user with RPC command pruneblockchain */
3944-
static void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight)
3944+
static void FindFilesToPruneManual(ChainstateManager& chainman, std::set<int>& setFilesToPrune, int nManualPruneHeight)
39453945
{
39463946
assert(fPruneMode && nManualPruneHeight > 0);
39473947

@@ -3955,7 +3955,7 @@ static void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPr
39553955
for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) {
39563956
if (vinfoBlockFile[fileNumber].nSize == 0 || vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
39573957
continue;
3958-
PruneOneBlockFile(fileNumber);
3958+
chainman.PruneOneBlockFile(fileNumber);
39593959
setFilesToPrune.insert(fileNumber);
39603960
count++;
39613961
}
@@ -3988,7 +3988,7 @@ void PruneBlockFilesManual(int nManualPruneHeight)
39883988
*
39893989
* @param[out] setFilesToPrune The set of file indices that can be unlinked will be returned
39903990
*/
3991-
static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight)
3991+
static void FindFilesToPrune(ChainstateManager& chainman, std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight)
39923992
{
39933993
LOCK2(cs_main, cs_LastBlockFile);
39943994
if (::ChainActive().Tip() == nullptr || nPruneTarget == 0) {
@@ -4030,7 +4030,7 @@ static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfte
40304030
if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
40314031
continue;
40324032

4033-
PruneOneBlockFile(fileNumber);
4033+
chainman.PruneOneBlockFile(fileNumber);
40344034
// Queue up the files for removal
40354035
setFilesToPrune.insert(fileNumber);
40364036
nCurrentUsage -= nBytesToPrune;

src/validation.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,6 @@ double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex* pin
214214
/** Calculate the amount of disk space the block & undo files currently use */
215215
uint64_t CalculateCurrentUsage();
216216

217-
/**
218-
* Mark one block file as pruned.
219-
*/
220-
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
221-
222217
/**
223218
* Actually unlink the specified files
224219
*/
@@ -865,6 +860,9 @@ class ChainstateManager
865860
CChain& ValidatedChain() const { return ValidatedChainstate().m_chain; }
866861
CBlockIndex* ValidatedTip() const { return ValidatedChain().Tip(); }
867862

863+
//! Mark one block file as pruned (modify associated database entries)
864+
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
865+
868866
//! Load the block tree and coins database from disk, initializing state if we're running with -reindex
869867
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
870868

src/wallet/test/wallet_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
118118
// Prune the older block file.
119119
{
120120
LOCK(cs_main);
121-
PruneOneBlockFile(oldTip->GetBlockPos().nFile);
121+
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile);
122122
}
123123
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
124124

@@ -144,7 +144,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
144144
// Prune the remaining block file.
145145
{
146146
LOCK(cs_main);
147-
PruneOneBlockFile(newTip->GetBlockPos().nFile);
147+
EnsureChainman(m_node).PruneOneBlockFile(newTip->GetBlockPos().nFile);
148148
}
149149
UnlinkPrunedFiles({newTip->GetBlockPos().nFile});
150150

@@ -181,7 +181,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
181181
// Prune the older block file.
182182
{
183183
LOCK(cs_main);
184-
PruneOneBlockFile(oldTip->GetBlockPos().nFile);
184+
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile);
185185
}
186186
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
187187

0 commit comments

Comments
 (0)