mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-31 10:41:08 +00:00
refactor: Simplify pruning functions
Move GetPruneRange from ChainstateManager to Chainstate.
This commit is contained in:
parent
ae85c495f1
commit
af455dcb39
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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)
|
||||
//
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user