refactor: Simplify pruning functions
Move GetPruneRange from ChainstateManager to Chainstate.
This commit is contained in:
1 parent
ae85c495f1
commit
af455dcb39
4 files changed
+15
-18
No files matched your search
@@ -284,8 +284,7 @@ void BlockManager::PruneOneBlockFile(const int fileNumber)
|
|||||||
void BlockManager::FindFilesToPruneManual(
|
void BlockManager::FindFilesToPruneManual(
|
||||||
std::set<int>& setFilesToPrune,
|
std::set<int>& setFilesToPrune,
|
||||||
int nManualPruneHeight,
|
int nManualPruneHeight,
|
||||||
const Chainstate& chain,
|
const Chainstate& chain)
|
||||||
ChainstateManager& chainman)
|
|
||||||
{
|
{
|
||||||
assert(IsPruneMode() && nManualPruneHeight > 0);
|
assert(IsPruneMode() && nManualPruneHeight > 0);
|
||||||
|
|
||||||
@@ -294,7 +293,7 @@ void BlockManager::FindFilesToPruneManual(
|
|||||||
return;
|
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;
|
int count = 0;
|
||||||
for (int fileNumber = 0; fileNumber < this->MaxBlockfileNum(); fileNumber++) {
|
for (int fileNumber = 0; fileNumber < this->MaxBlockfileNum(); fileNumber++) {
|
||||||
@@ -337,7 +336,7 @@ void BlockManager::FindFilesToPrune(
|
|||||||
return;
|
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();
|
uint64_t nCurrentUsage = CalculateCurrentUsage();
|
||||||
// We don't check to prune until after we've allocated new space for files
|
// We don't check to prune until after we've allocated new space for files
|
||||||
|
|||||||
@@ -218,8 +218,7 @@ private:
|
|||||||
void FindFilesToPruneManual(
|
void FindFilesToPruneManual(
|
||||||
std::set<int>& setFilesToPrune,
|
std::set<int>& setFilesToPrune,
|
||||||
int nManualPruneHeight,
|
int nManualPruneHeight,
|
||||||
const Chainstate& chain,
|
const Chainstate& chain);
|
||||||
ChainstateManager& chainman);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prune block and undo files (blk???.dat and rev???.dat) so that the disk space used is less than a user-defined target.
|
* Prune block and undo files (blk???.dat and rev???.dat) so that the disk space used is less than a user-defined target.
|
||||||
|
|||||||
+6
-6
@@ -2785,7 +2785,7 @@ bool Chainstate::FlushStateToDisk(
|
|||||||
m_blockman.FindFilesToPruneManual(
|
m_blockman.FindFilesToPruneManual(
|
||||||
setFilesToPrune,
|
setFilesToPrune,
|
||||||
std::min(last_prune, nManualPruneHeight),
|
std::min(last_prune, nManualPruneHeight),
|
||||||
*this, m_chainman);
|
*this);
|
||||||
} else {
|
} else {
|
||||||
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune", BCLog::BENCH);
|
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune", BCLog::BENCH);
|
||||||
|
|
||||||
@@ -6399,22 +6399,22 @@ bool ChainstateManager::ValidatedSnapshotCleanup(Chainstate& validated_cs, Chain
|
|||||||
return true;
|
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};
|
return {0, 0};
|
||||||
}
|
}
|
||||||
int prune_start{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
|
// 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
|
// that has not been fully validated yet. The earlier blocks need to be
|
||||||
// kept to validate the snapshot
|
// kept to validate the snapshot
|
||||||
prune_start = Assert(chainstate.SnapshotBase())->nHeight + 1;
|
prune_start = Assert(SnapshotBase())->nHeight + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int max_prune = std::max<int>(
|
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)
|
// last block to prune is the lesser of (caller-specified height, MIN_BLOCKS_TO_KEEP from the tip)
|
||||||
//
|
//
|
||||||
|
|||||||
+5
-6
@@ -835,6 +835,11 @@ public:
|
|||||||
return m_mempool ? &m_mempool->cs : nullptr;
|
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:
|
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 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(
|
bool ConnectTip(
|
||||||
@@ -1325,12 +1330,6 @@ public:
|
|||||||
//! @sa node/chainstate:LoadChainstate()
|
//! @sa node/chainstate:LoadChainstate()
|
||||||
bool ValidatedSnapshotCleanup(Chainstate& validated_cs, Chainstate& unvalidated_cs) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
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.
|
//! Get range of historical blocks to download.
|
||||||
std::optional<std::pair<const CBlockIndex*, const CBlockIndex*>> GetHistoricalBlockRange() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
std::optional<std::pair<const CBlockIndex*, const CBlockIndex*>> GetHistoricalBlockRange() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user