MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / LoadBlockIndexGuts

Method LoadBlockIndexGuts

src/txdb.cpp:191–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191bool CBlockTreeDB::LoadBlockIndexGuts()
192{
193 boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());
194
195 CDataStream ssKeySet(SER_DISK, CLIENT_VERSION);
196 ssKeySet << make_pair(DB_BLOCK_INDEX, uint256());
197 pcursor->Seek(ssKeySet.str());
198
199 // Load mapBlockIndex
200 while (pcursor->Valid()) {
201 boost::this_thread::interruption_point();
202 try {
203 leveldb::Slice slKey = pcursor->key();
204 CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION);
205 char chType;
206 ssKey >> chType;
207 if (chType == DB_BLOCK_INDEX) {
208 leveldb::Slice slValue = pcursor->value();
209 CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION);
210 CDiskBlockIndex diskindex;
211 ssValue >> diskindex;
212
213 // Construct block index object
214 CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
215 pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
216 pindexNew->nHeight = diskindex.nHeight;
217 pindexNew->nFile = diskindex.nFile;
218 pindexNew->nDataPos = diskindex.nDataPos;
219 pindexNew->nUndoPos = diskindex.nUndoPos;
220 pindexNew->nVersion = diskindex.nVersion;
221 pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
222 pindexNew->nTime = diskindex.nTime;
223 pindexNew->nBits = diskindex.nBits;
224 pindexNew->nNonce = diskindex.nNonce;
225 pindexNew->nStatus = diskindex.nStatus;
226 pindexNew->nTx = diskindex.nTx;
227 pindexNew->nSerialVersion = diskindex.nSerialVersion;
228 pindexNew->nMaxBlockSize = diskindex.nMaxBlockSize;
229 pindexNew->nMaxBlockSizeVote = diskindex.nMaxBlockSizeVote;
230
231 if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus()))
232 return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());
233
234 pcursor->Next();
235 } else {
236 break; // if shutdown requested or finished loading block index
237 }
238 } catch (const std::exception& e) {
239 return error("%s: Deserialize or I/O error - %s", __func__, e.what());
240 }
241 }
242
243 return true;
244}

Callers 1

LoadBlockIndexDBFunction · 0.80

Calls 15

InsertBlockIndexFunction · 0.85
CheckProofOfWorkFunction · 0.85
errorFunction · 0.85
strMethod · 0.80
uint256Class · 0.70
ParamsClass · 0.70
SeekMethod · 0.45
ValidMethod · 0.45
keyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected