Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,184 Lines • ▼ Show 20 Lines | static CBlockIndex *AddToBlockIndex(const CBlockHeader &block) { | ||||
uint256 hash = block.GetHash(); | uint256 hash = block.GetHash(); | ||||
BlockMap::iterator it = mapBlockIndex.find(hash); | BlockMap::iterator it = mapBlockIndex.find(hash); | ||||
if (it != mapBlockIndex.end()) { | if (it != mapBlockIndex.end()) { | ||||
return it->second; | return it->second; | ||||
} | } | ||||
// Construct new block index object | // Construct new block index object | ||||
CBlockIndex *pindexNew = new CBlockIndex(block); | CBlockIndex *pindexNew = new CBlockIndex(block); | ||||
assert(pindexNew); | |||||
// We assign the sequence id to blocks only when the full data is available, | // We assign the sequence id to blocks only when the full data is available, | ||||
// to avoid miners withholding blocks but broadcasting headers, to get a | // to avoid miners withholding blocks but broadcasting headers, to get a | ||||
// competitive advantage. | // competitive advantage. | ||||
pindexNew->nSequenceId = 0; | pindexNew->nSequenceId = 0; | ||||
BlockMap::iterator mi = | BlockMap::iterator mi = | ||||
mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first; | mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first; | ||||
pindexNew->phashBlock = &((*mi).first); | pindexNew->phashBlock = &((*mi).first); | ||||
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock); | BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock); | ||||
▲ Show 20 Lines • Show All 1,118 Lines • ▼ Show 20 Lines | CBlockIndex *InsertBlockIndex(uint256 hash) { | ||||
// Return existing | // Return existing | ||||
BlockMap::iterator mi = mapBlockIndex.find(hash); | BlockMap::iterator mi = mapBlockIndex.find(hash); | ||||
if (mi != mapBlockIndex.end()) { | if (mi != mapBlockIndex.end()) { | ||||
return (*mi).second; | return (*mi).second; | ||||
} | } | ||||
// Create new | // Create new | ||||
CBlockIndex *pindexNew = new CBlockIndex(); | CBlockIndex *pindexNew = new CBlockIndex(); | ||||
if (!pindexNew) { | |||||
throw std::runtime_error(std::string(__func__) + | |||||
": new CBlockIndex failed"); | |||||
} | |||||
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; | ||||
} | } | ||||
static bool LoadBlockIndexDB(const Config &config) { | static bool LoadBlockIndexDB(const Config &config) { | ||||
if (!pblocktree->LoadBlockIndexGuts(config, InsertBlockIndex)) { | if (!pblocktree->LoadBlockIndexGuts(config, InsertBlockIndex)) { | ||||
▲ Show 20 Lines • Show All 1,254 Lines • Show Last 20 Lines |