Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 4,350 Lines • ▼ Show 20 Lines | CBlockIndex *CChainState::InsertBlockIndex(const BlockHash &hash) { | ||||
// Create new | // Create new | ||||
CBlockIndex *pindexNew = new CBlockIndex(); | CBlockIndex *pindexNew = new CBlockIndex(); | ||||
mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first; | mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first; | ||||
pindexNew->phashBlock = &((*mi).first); | pindexNew->phashBlock = &((*mi).first); | ||||
return pindexNew; | return pindexNew; | ||||
} | } | ||||
bool CChainState::LoadBlockIndex(const Config &config, | bool CChainState::LoadBlockIndex(const Consensus::Params ¶ms, | ||||
CBlockTreeDB &blocktree) { | CBlockTreeDB &blocktree) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
if (!blocktree.LoadBlockIndexGuts( | if (!blocktree.LoadBlockIndexGuts( | ||||
config.GetChainParams().GetConsensus(), | params, [this](const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED( | ||||
[this](const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | cs_main) { return this->InsertBlockIndex(hash); })) { | ||||
return this->InsertBlockIndex(hash); | |||||
})) { | |||||
return false; | return false; | ||||
} | } | ||||
// Calculate nChainWork | // Calculate nChainWork | ||||
std::vector<std::pair<int, CBlockIndex *>> vSortedByHeight; | std::vector<std::pair<int, CBlockIndex *>> vSortedByHeight; | ||||
vSortedByHeight.reserve(mapBlockIndex.size()); | vSortedByHeight.reserve(mapBlockIndex.size()); | ||||
for (const std::pair<const BlockHash, CBlockIndex *> &item : | for (const std::pair<const BlockHash, CBlockIndex *> &item : | ||||
mapBlockIndex) { | mapBlockIndex) { | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | for (const std::pair<int, CBlockIndex *> &item : vSortedByHeight) { | ||||
CBlockIndexWorkComparator()(pindexBestHeader, pindex))) { | CBlockIndexWorkComparator()(pindexBestHeader, pindex))) { | ||||
pindexBestHeader = pindex; | pindexBestHeader = pindex; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
static bool LoadBlockIndexDB(const Config &config) | static bool LoadBlockIndexDB(const Consensus::Params ¶ms) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | ||||
if (!::ChainstateActive().LoadBlockIndex(config, *pblocktree)) { | if (!::ChainstateActive().LoadBlockIndex(params, *pblocktree)) { | ||||
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++) { | ||||
▲ Show 20 Lines • Show All 421 Lines • ▼ Show 20 Lines | void UnloadBlockIndex() { | ||||
} | } | ||||
mapBlockIndex.clear(); | mapBlockIndex.clear(); | ||||
fHavePruned = false; | fHavePruned = false; | ||||
::ChainstateActive().UnloadBlockIndex(); | ::ChainstateActive().UnloadBlockIndex(); | ||||
} | } | ||||
bool LoadBlockIndex(const Config &config) { | bool LoadBlockIndex(const Consensus::Params ¶ms) { | ||||
// 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(config); | bool ret = LoadBlockIndexDB(params); | ||||
if (!ret) { | if (!ret) { | ||||
return false; | return false; | ||||
} | } | ||||
needs_init = mapBlockIndex.empty(); | needs_init = mapBlockIndex.empty(); | ||||
} | } | ||||
if (needs_init) { | if (needs_init) { | ||||
▲ Show 20 Lines • Show All 753 Lines • Show Last 20 Lines |