mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
blockstorage, refactor: make GetFirstStoredBlock() a member of BlockManager
instead of a global
This commit is contained in:
@@ -75,7 +75,7 @@ bool BaseIndex::Init()
|
|||||||
if (!m_best_block_index) {
|
if (!m_best_block_index) {
|
||||||
// index is not built yet
|
// index is not built yet
|
||||||
// make sure we have all block data back to the genesis
|
// make sure we have all block data back to the genesis
|
||||||
prune_violation = node::GetFirstStoredBlock(active_chain.Tip()) != active_chain.Genesis();
|
prune_violation = m_chainstate->m_blockman.GetFirstStoredBlock(active_chain.Tip()) != active_chain.Genesis();
|
||||||
}
|
}
|
||||||
// in case the index has a best block set and is not fully synced
|
// in case the index has a best block set and is not fully synced
|
||||||
// check if we have the required blocks to continue building the index
|
// check if we have the required blocks to continue building the index
|
||||||
|
|||||||
@@ -390,7 +390,8 @@ bool BlockManager::IsBlockPruned(const CBlockIndex* pblockindex)
|
|||||||
return (m_have_pruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
|
return (m_have_pruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CBlockIndex* GetFirstStoredBlock(const CBlockIndex* start_block) {
|
const CBlockIndex* BlockManager::GetFirstStoredBlock(const CBlockIndex* start_block)
|
||||||
|
{
|
||||||
AssertLockHeld(::cs_main);
|
AssertLockHeld(::cs_main);
|
||||||
assert(start_block);
|
assert(start_block);
|
||||||
const CBlockIndex* last_block = start_block;
|
const CBlockIndex* last_block = start_block;
|
||||||
|
|||||||
@@ -178,6 +178,9 @@ public:
|
|||||||
//! Returns last CBlockIndex* that is a checkpoint
|
//! Returns last CBlockIndex* that is a checkpoint
|
||||||
const CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
const CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
|
//! Find the first block that is not pruned
|
||||||
|
const CBlockIndex* GetFirstStoredBlock(const CBlockIndex* start_block) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
/** True if any block files have ever been pruned. */
|
/** True if any block files have ever been pruned. */
|
||||||
bool m_have_pruned = false;
|
bool m_have_pruned = false;
|
||||||
|
|
||||||
@@ -188,9 +191,6 @@ public:
|
|||||||
void UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
void UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Find the first block that is not pruned
|
|
||||||
const CBlockIndex* GetFirstStoredBlock(const CBlockIndex* start_block) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
|
||||||
|
|
||||||
void CleanupBlockRevFiles();
|
void CleanupBlockRevFiles();
|
||||||
|
|
||||||
/** Open a block file (blk?????.dat) */
|
/** Open a block file (blk?????.dat) */
|
||||||
|
|||||||
@@ -787,7 +787,7 @@ static RPCHelpMan pruneblockchain()
|
|||||||
|
|
||||||
PruneBlockFilesManual(active_chainstate, height);
|
PruneBlockFilesManual(active_chainstate, height);
|
||||||
const CBlockIndex* block = CHECK_NONFATAL(active_chain.Tip());
|
const CBlockIndex* block = CHECK_NONFATAL(active_chain.Tip());
|
||||||
const CBlockIndex* last_block = node::GetFirstStoredBlock(block);
|
const CBlockIndex* last_block{active_chainstate.m_blockman.GetFirstStoredBlock(block)};
|
||||||
|
|
||||||
return static_cast<uint64_t>(last_block->nHeight);
|
return static_cast<uint64_t>(last_block->nHeight);
|
||||||
},
|
},
|
||||||
@@ -1215,7 +1215,7 @@ RPCHelpMan getblockchaininfo()
|
|||||||
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
|
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
|
||||||
obj.pushKV("pruned", node::fPruneMode);
|
obj.pushKV("pruned", node::fPruneMode);
|
||||||
if (node::fPruneMode) {
|
if (node::fPruneMode) {
|
||||||
obj.pushKV("pruneheight", node::GetFirstStoredBlock(&tip)->nHeight);
|
obj.pushKV("pruneheight", chainman.m_blockman.GetFirstStoredBlock(&tip)->nHeight);
|
||||||
|
|
||||||
// if 0, execution bypasses the whole if block.
|
// if 0, execution bypasses the whole if block.
|
||||||
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
|
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
|
||||||
|
|||||||
Reference in New Issue
Block a user