What changed, and why it matters
This commit is a straightforward internal code cleanup: it moves a small helper function that decides which block heights can be pruned from one class (ChainstateManager) to another (Chainstate), and removes an unneeded parameter from two related functions. The actual pruning logic and results are unchanged. There is no user-visible behavior change and no security issue.
No security action needed. Treat as normal code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors GetPruneRange from a ChainstateManager method taking a Chainstate reference into a const Chainstate method. Callers in BlockManager::FindFilesToPruneManual and BlockManager::FindFilesToPrune are updated accordingly, and the chainman parameter is removed. The implementation body is identical except for using m_chain, m_from_snapshot_blockhash, m_assumeutxo, and SnapshotBase() directly instead of through the chainstate parameter. No functional changes are introduced.
Changed components
src/node/blockstorage.cppsrc/node/blockstorage.hsrc/validation.cppsrc/validation.hInspect captured patch +15 / −18
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index ec95f11b..41931a81 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -284,8 +284,7 @@ void BlockManager::PruneOneBlockFile(const int fileNumber)
void BlockManager::FindFilesToPruneManual(
std::set<int>& setFilesToPrune,
int nManualPruneHeight,
- const Chainstate& chain,
- ChainstateManager& chainman)
+ const Chainstate& chain)
{
assert(IsPruneMode() && nManualPruneHeight > 0);
@@ -294,7 +293,7 @@ void BlockManager::FindFilesToPruneManual(
return;
}
- const auto [min_block_to_prune, last_block_can_prune] = chainman.GetPruneRange(chain, nManualPruneHeight);
+ const auto [min_block_to_prune, last_block_can_prune] = chain.GetPruneRange(nManualPruneHeight);
int count = 0;
for (int fileNumber = 0; fileNumber < this->MaxBlockfileNum(); fileNumber++) {
@@ -337,7 +336,7 @@ void BlockManager::FindFilesToPrune(
return;
}
- const auto [min_block_to_prune, last_block_can_prune] = chainman.GetPruneRange(chain, last_prune);
+ const auto [min_block_to_prune, last_block_can_prune] = chain.GetPruneRange(last_prune);
uint64_t nCurrentUsage = CalculateCurrentUsage();
// We don't check to prune until after we've allocated new space for files
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index 9ba7873c..70baa273 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -218,8 +218,7 @@ private:
void FindFilesToPruneManual(
std::set<int>& setFilesToPrune,
int nManualPruneHeight,
- const Chainstate& chain,
- ChainstateManager& chainman);
+ const Chainstate& chain);
/**
* Prune block and undo files (blk???.dat and rev???.dat) so that the disk space used is less than a user-defined target.
diff --git a/src/validation.cpp b/src/validation.cpp
index 72872c5c..9ecfdfa1 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2785,7 +2785,7 @@ bool Chainstate::FlushStateToDisk(
m_blockman.FindFilesToPruneManual(
setFilesToPrune,
std::min(last_prune, nManualPruneHeight),
- *this, m_chainman);
+ *this);
} else {
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune", BCLog::BENCH);
@@ -6399,22 +6399,22 @@ bool ChainstateManager::ValidatedSnapshotCleanup(Chainstate& validated_cs, Chain
return true;
}
-std::pair<int, int> ChainstateManager::GetPruneRange(const Chainstate& chainstate, int last_height_can_prune)
+std::pair<int, int> Chainstate::GetPruneRange(int last_height_can_prune) const
{
- if (chainstate.m_chain.Height() <= 0) {
+ if (m_chain.Height() <= 0) {
return {0, 0};
}
int prune_start{0};
- if (chainstate.m_from_snapshot_blockhash && chainstate.m_assumeutxo != Assumeutxo::VALIDATED) {
+ if (m_from_snapshot_blockhash && m_assumeutxo != Assumeutxo::VALIDATED) {
// Only prune blocks _after_ the snapshot if this is a snapshot chain
// that has not been fully validated yet. The earlier blocks need to be
// kept to validate the snapshot
- prune_start = Assert(chainstate.SnapshotBase())->nHeight + 1;
+ prune_start = Assert(SnapshotBase())->nHeight + 1;
}
int max_prune = std::max<int>(
- 0, chainstate.m_chain.Height() - static_cast<int>(MIN_BLOCKS_TO_KEEP));
+ 0, m_chain.Height() - static_cast<int>(MIN_BLOCKS_TO_KEEP));
// last block to prune is the lesser of (caller-specified height, MIN_BLOCKS_TO_KEEP from the tip)
//
diff --git a/src/validation.h b/src/validation.h
index e14dac74..e810e872 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -835,6 +835,11 @@ public:
return m_mempool ? &m_mempool->cs : nullptr;
}
+ //! Return the [start, end] (inclusive) of block heights we can prune.
+ //!
+ //! start > end is possible, meaning no blocks can be pruned.
+ std::pair<int, int> GetPruneRange(int last_height_can_prune) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+
protected:
bool ActivateBestChainStep(BlockValidationState& state, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);
bool ConnectTip(
@@ -1325,12 +1330,6 @@ public:
//! @sa node/chainstate:LoadChainstate()
bool ValidatedSnapshotCleanup(Chainstate& validated_cs, Chainstate& unvalidated_cs) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
- //! Return the [start, end] (inclusive) of block heights we can prune.
- //!
- //! start > end is possible, meaning no blocks can be pruned.
- std::pair<int, int> GetPruneRange(
- const Chainstate& chainstate, int last_height_can_prune) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
-
//! Get range of historical blocks to download.
std::optional<std::pair<const CBlockIndex*, const CBlockIndex*>> GetHistoricalBlockRange() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.