aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2022-04-27 12:21:22 +0200
committerJon Atack <jon@atack.com>2022-04-28 20:42:08 +0200
commited12c0a49d3c64d170aca9e66ef32a57d7933eeb (patch)
tree6f74d670d7c39c3cdd4531e48156f5e3fc6757a6
parentdabec990135cc32584e822126ec49f8b31350837 (diff)
blockstorage, refactor: make GetFirstStoredBlock() a member of BlockManager
instead of a global
-rw-r--r--src/index/base.cpp2
-rw-r--r--src/node/blockstorage.cpp3
-rw-r--r--src/node/blockstorage.h6
-rw-r--r--src/rpc/blockchain.cpp4
4 files changed, 8 insertions, 7 deletions
diff --git a/src/index/base.cpp b/src/index/base.cpp
index 488a214ccf..db4070b911 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -75,7 +75,7 @@ bool BaseIndex::Init()
if (!m_best_block_index) {
// index is not built yet
// 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
// check if we have the required blocks to continue building the index
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 25771aacee..be45eb7ba9 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -390,7 +390,8 @@ bool BlockManager::IsBlockPruned(const CBlockIndex* pblockindex)
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);
assert(start_block);
const CBlockIndex* last_block = start_block;
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index 622eac7fef..c5317e5a95 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -178,6 +178,9 @@ public:
//! Returns last CBlockIndex* that is a checkpoint
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. */
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);
};
-//! Find the first block that is not pruned
-const CBlockIndex* GetFirstStoredBlock(const CBlockIndex* start_block) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
-
void CleanupBlockRevFiles();
/** Open a block file (blk?????.dat) */
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index 96e9efb288..6347036b9a 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -787,7 +787,7 @@ static RPCHelpMan pruneblockchain()
PruneBlockFilesManual(active_chainstate, height);
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);
},
@@ -1215,7 +1215,7 @@ RPCHelpMan getblockchaininfo()
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
obj.pushKV("pruned", 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.
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};