Skip to content

Commit fa84b1c

Browse files
author
MarcoFalke
committed
validation: Make LoadBlockIndex() a member of ChainstateManager
1 parent fa05fdf commit fa84b1c

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
15821582
// block file from disk.
15831583
// Note that it also sets fReindex based on the disk flag!
15841584
// From here on out fReindex and fReset mean something different!
1585-
if (!LoadBlockIndex(chainparams)) {
1585+
if (!chainman.LoadBlockIndex(chainparams)) {
15861586
if (ShutdownRequested()) break;
15871587
strLoadError = _("Error loading block database");
15881588
break;

src/validation.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4154,9 +4154,9 @@ void BlockManager::Unload() {
41544154
m_block_index.clear();
41554155
}
41564156

4157-
bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
4157+
bool static LoadBlockIndexDB(ChainstateManager& chainman, const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
41584158
{
4159-
if (!g_chainman.m_blockman.LoadBlockIndex(
4159+
if (!chainman.m_blockman.LoadBlockIndex(
41604160
chainparams.GetConsensus(), *pblocktree,
41614161
::ChainstateActive().setBlockIndexCandidates)) {
41624162
return false;
@@ -4182,8 +4182,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_RE
41824182
// Check presence of blk files
41834183
LogPrintf("Checking all blk files are present...\n");
41844184
std::set<int> setBlkDataFiles;
4185-
for (const std::pair<const uint256, CBlockIndex*>& item : g_chainman.BlockIndex())
4186-
{
4185+
for (const std::pair<const uint256, CBlockIndex*>& item : chainman.BlockIndex()) {
41874186
CBlockIndex* pindex = item.second;
41884187
if (pindex->nStatus & BLOCK_HAVE_DATA) {
41894188
setBlkDataFiles.insert(pindex->nFile);
@@ -4600,14 +4599,15 @@ void UnloadBlockIndex()
46004599
fHavePruned = false;
46014600
}
46024601

4603-
bool LoadBlockIndex(const CChainParams& chainparams)
4602+
bool ChainstateManager::LoadBlockIndex(const CChainParams& chainparams)
46044603
{
4604+
AssertLockHeld(cs_main);
46054605
// Load block index from databases
46064606
bool needs_init = fReindex;
46074607
if (!fReindex) {
4608-
bool ret = LoadBlockIndexDB(chainparams);
4608+
bool ret = LoadBlockIndexDB(*this, chainparams);
46094609
if (!ret) return false;
4610-
needs_init = g_chainman.m_blockman.m_block_index.empty();
4610+
needs_init = m_blockman.m_block_index.empty();
46114611
}
46124612

46134613
if (needs_init) {

src/validation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ fs::path GetBlockPosFilename(const FlatFilePos &pos);
193193
void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFilePos* dbp = nullptr);
194194
/** Ensures we have a genesis block in the block tree, possibly writing one to disk. */
195195
bool LoadGenesisBlock(const CChainParams& chainparams);
196-
/** Load the block tree and coins database from disk,
197-
* initializing state if we're running with -reindex. */
198-
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
199196
/** Unload database information */
200197
void UnloadBlockIndex();
201198
/** Run an instance of the script checking thread */
@@ -868,6 +865,9 @@ class ChainstateManager
868865
CChain& ValidatedChain() const { return ValidatedChainstate().m_chain; }
869866
CBlockIndex* ValidatedTip() const { return ValidatedChain().Tip(); }
870867

868+
//! Load the block tree and coins database from disk, initializing state if we're running with -reindex
869+
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
870+
871871
//! Unload block index and chain data before shutdown.
872872
void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
873873

0 commit comments

Comments
 (0)