validation: Move LoadBlockIndexDB to CChainState

CChainState needed cuz setBlockIndexCandidates
This commit is contained in:
Carl Dong committed 2021-03-01 17:56:22 -05:00
1 parent 8b99efbcc0
commit 8cdb2f7e58
2 files changed
+8 -5

No files matched your search

+6 -5
View File
@@ -4136,11 +4136,12 @@ void BlockManager::Unload() {
m_block_index.clear(); m_block_index.clear();
} }
bool static LoadBlockIndexDB(ChainstateManager& chainman, const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) bool CChainState::LoadBlockIndexDB(const CChainParams& chainparams)
{ {
if (!chainman.m_blockman.LoadBlockIndex( assert(std::addressof(::ChainstateActive()) == std::addressof(*this));
if (!m_blockman.LoadBlockIndex(
chainparams.GetConsensus(), *pblocktree, chainparams.GetConsensus(), *pblocktree,
::ChainstateActive().setBlockIndexCandidates)) { setBlockIndexCandidates)) {
return false; return false;
} }
@@ -4164,7 +4165,7 @@ bool static LoadBlockIndexDB(ChainstateManager& chainman, const CChainParams& ch
// 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 : chainman.BlockIndex()) { for (const std::pair<const uint256, CBlockIndex*>& item : m_blockman.m_block_index) {
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);
@@ -4596,7 +4597,7 @@ bool ChainstateManager::LoadBlockIndex(const CChainParams& chainparams)
// 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(*this, chainparams); bool ret = ActiveChainstate().LoadBlockIndexDB(chainparams);
if (!ret) return false; if (!ret) return false;
needs_init = m_blockman.m_block_index.empty(); needs_init = m_blockman.m_block_index.empty();
} }
+2
View File
@@ -776,6 +776,8 @@ private:
void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main); void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
void InvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main); void InvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
bool LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
friend ChainstateManager; friend ChainstateManager;
}; };