validation: Make LoadBlockIndex() a member of ChainstateManager

This commit is contained in:
MarcoFalke committed 2020-05-21 09:55:59 -04:00
1 parent fa05fdf0f1
commit fa84b1cd84
3 files changed
+11 -11

No files matched your search

+1 -1
View File
@@ -1582,7 +1582,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
// block file from disk. // block file from disk.
// Note that it also sets fReindex based on the disk flag! // Note that it also sets fReindex based on the disk flag!
// From here on out fReindex and fReset mean something different! // From here on out fReindex and fReset mean something different!
if (!LoadBlockIndex(chainparams)) { if (!chainman.LoadBlockIndex(chainparams)) {
if (ShutdownRequested()) break; if (ShutdownRequested()) break;
strLoadError = _("Error loading block database"); strLoadError = _("Error loading block database");
break; break;
+7 -7
View File
@@ -4154,9 +4154,9 @@ void BlockManager::Unload() {
m_block_index.clear(); m_block_index.clear();
} }
bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) bool static LoadBlockIndexDB(ChainstateManager& chainman, const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{ {
if (!g_chainman.m_blockman.LoadBlockIndex( if (!chainman.m_blockman.LoadBlockIndex(
chainparams.GetConsensus(), *pblocktree, chainparams.GetConsensus(), *pblocktree,
::ChainstateActive().setBlockIndexCandidates)) { ::ChainstateActive().setBlockIndexCandidates)) {
return false; return false;
@@ -4182,8 +4182,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_RE
// Check presence of blk files // Check presence of blk files
LogPrintf("Checking all blk files are present...\n"); LogPrintf("Checking all blk files are present...\n");
std::set<int> setBlkDataFiles; std::set<int> setBlkDataFiles;
for (const std::pair<const uint256, CBlockIndex*>& item : g_chainman.BlockIndex()) for (const std::pair<const uint256, CBlockIndex*>& item : chainman.BlockIndex()) {
{
CBlockIndex* pindex = item.second; CBlockIndex* pindex = item.second;
if (pindex->nStatus & BLOCK_HAVE_DATA) { if (pindex->nStatus & BLOCK_HAVE_DATA) {
setBlkDataFiles.insert(pindex->nFile); setBlkDataFiles.insert(pindex->nFile);
@@ -4600,14 +4599,15 @@ void UnloadBlockIndex()
fHavePruned = false; fHavePruned = false;
} }
bool LoadBlockIndex(const CChainParams& chainparams) bool ChainstateManager::LoadBlockIndex(const CChainParams& chainparams)
{ {
AssertLockHeld(cs_main);
// Load block index from databases // Load block index from databases
bool needs_init = fReindex; bool needs_init = fReindex;
if (!fReindex) { if (!fReindex) {
bool ret = LoadBlockIndexDB(chainparams); bool ret = LoadBlockIndexDB(*this, chainparams);
if (!ret) return false; if (!ret) return false;
needs_init = g_chainman.m_blockman.m_block_index.empty(); needs_init = m_blockman.m_block_index.empty();
} }
if (needs_init) { if (needs_init) {
+3 -3
View File
@@ -193,9 +193,6 @@ fs::path GetBlockPosFilename(const FlatFilePos &pos);
void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFilePos* dbp = nullptr); void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFilePos* dbp = nullptr);
/** Ensures we have a genesis block in the block tree, possibly writing one to disk. */ /** Ensures we have a genesis block in the block tree, possibly writing one to disk. */
bool LoadGenesisBlock(const CChainParams& chainparams); bool LoadGenesisBlock(const CChainParams& chainparams);
/** Load the block tree and coins database from disk,
* initializing state if we're running with -reindex. */
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/** Unload database information */ /** Unload database information */
void UnloadBlockIndex(); void UnloadBlockIndex();
/** Run an instance of the script checking thread */ /** Run an instance of the script checking thread */
@@ -868,6 +865,9 @@ public:
CChain& ValidatedChain() const { return ValidatedChainstate().m_chain; } CChain& ValidatedChain() const { return ValidatedChainstate().m_chain; }
CBlockIndex* ValidatedTip() const { return ValidatedChain().Tip(); } CBlockIndex* ValidatedTip() const { return ValidatedChain().Tip(); }
//! Load the block tree and coins database from disk, initializing state if we're running with -reindex
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
//! Unload block index and chain data before shutdown. //! Unload block index and chain data before shutdown.
void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);