Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 4,607 Lines • ▼ Show 20 Lines | void BlockManager::Unload() { | ||||
for (const BlockMap::value_type &entry : m_block_index) { | for (const BlockMap::value_type &entry : m_block_index) { | ||||
delete entry.second; | delete entry.second; | ||||
} | } | ||||
m_block_index.clear(); | m_block_index.clear(); | ||||
} | } | ||||
static bool LoadBlockIndexDB(const Consensus::Params ¶ms) | static bool LoadBlockIndexDB(ChainstateManager &chainman, | ||||
const Consensus::Params ¶ms) | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | ||||
if (!g_chainman.m_blockman.LoadBlockIndex( | if (!chainman.m_blockman.LoadBlockIndex( | ||||
params, *pblocktree, | params, *pblocktree, | ||||
::ChainstateActive().setBlockIndexCandidates)) { | ::ChainstateActive().setBlockIndexCandidates)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Load block file info | // Load block file info | ||||
pblocktree->ReadLastBlockFile(nLastBlockFile); | pblocktree->ReadLastBlockFile(nLastBlockFile); | ||||
vinfoBlockFile.resize(nLastBlockFile + 1); | vinfoBlockFile.resize(nLastBlockFile + 1); | ||||
LogPrintf("%s: last block file = %i\n", __func__, nLastBlockFile); | LogPrintf("%s: last block file = %i\n", __func__, nLastBlockFile); | ||||
for (int nFile = 0; nFile <= nLastBlockFile; nFile++) { | for (int nFile = 0; nFile <= nLastBlockFile; nFile++) { | ||||
pblocktree->ReadBlockFileInfo(nFile, vinfoBlockFile[nFile]); | pblocktree->ReadBlockFileInfo(nFile, vinfoBlockFile[nFile]); | ||||
} | } | ||||
LogPrintf("%s: last block file info: %s\n", __func__, | LogPrintf("%s: last block file info: %s\n", __func__, | ||||
vinfoBlockFile[nLastBlockFile].ToString()); | vinfoBlockFile[nLastBlockFile].ToString()); | ||||
for (int nFile = nLastBlockFile + 1; true; nFile++) { | for (int nFile = nLastBlockFile + 1; true; nFile++) { | ||||
CBlockFileInfo info; | CBlockFileInfo info; | ||||
if (pblocktree->ReadBlockFileInfo(nFile, info)) { | if (pblocktree->ReadBlockFileInfo(nFile, info)) { | ||||
vinfoBlockFile.push_back(info); | vinfoBlockFile.push_back(info); | ||||
} else { | } else { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// 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 BlockHash, CBlockIndex *> &item : | for (const std::pair<const BlockHash, CBlockIndex *> &item : | ||||
g_chainman.BlockIndex()) { | chainman.BlockIndex()) { | ||||
CBlockIndex *pindex = item.second; | CBlockIndex *pindex = item.second; | ||||
if (pindex->nStatus.hasData()) { | if (pindex->nStatus.hasData()) { | ||||
setBlkDataFiles.insert(pindex->nFile); | setBlkDataFiles.insert(pindex->nFile); | ||||
} | } | ||||
} | } | ||||
for (const int i : setBlkDataFiles) { | for (const int i : setBlkDataFiles) { | ||||
FlatFilePos pos(i, 0); | FlatFilePos pos(i, 0); | ||||
▲ Show 20 Lines • Show All 374 Lines • ▼ Show 20 Lines | void UnloadBlockIndex() { | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
vinfoBlockFile.clear(); | vinfoBlockFile.clear(); | ||||
nLastBlockFile = 0; | nLastBlockFile = 0; | ||||
setDirtyBlockIndex.clear(); | setDirtyBlockIndex.clear(); | ||||
setDirtyFileInfo.clear(); | setDirtyFileInfo.clear(); | ||||
fHavePruned = false; | fHavePruned = false; | ||||
} | } | ||||
bool LoadBlockIndex(const Consensus::Params ¶ms) { | bool ChainstateManager::LoadBlockIndex(const Consensus::Params ¶ms) { | ||||
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(params); | bool ret = LoadBlockIndexDB(*this, params); | ||||
if (!ret) { | if (!ret) { | ||||
return false; | 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) { | ||||
// Everything here is for *new* reindex/DBs. Thus, though | // Everything here is for *new* reindex/DBs. Thus, though | ||||
// LoadBlockIndexDB may have set fReindex if we shut down | // LoadBlockIndexDB may have set fReindex if we shut down | ||||
// mid-reindex previously, we don't check fReindex and | // mid-reindex previously, we don't check fReindex and | ||||
// instead only check it prior to LoadBlockIndexDB to set | // instead only check it prior to LoadBlockIndexDB to set | ||||
// needs_init. | // needs_init. | ||||
▲ Show 20 Lines • Show All 839 Lines • Show Last 20 Lines |