| 248 | } |
| 249 | |
| 250 | bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex) |
| 251 | { |
| 252 | std::unique_ptr<CDBIterator> pcursor(NewIterator()); |
| 253 | |
| 254 | pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256())); |
| 255 | |
| 256 | // Load mapBlockIndex |
| 257 | while (pcursor->Valid()) { |
| 258 | boost::this_thread::interruption_point(); |
| 259 | std::pair<char, uint256> key; |
| 260 | if (pcursor->GetKey(key) && key.first == DB_BLOCK_INDEX) { |
| 261 | CDiskBlockIndex diskindex; |
| 262 | if (pcursor->GetValue(diskindex)) { |
| 263 | // Construct block index object |
| 264 | CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash()); |
| 265 | pindexNew->pprev = insertBlockIndex(diskindex.hashPrev); |
| 266 | pindexNew->nHeight = diskindex.nHeight; |
| 267 | pindexNew->nFile = diskindex.nFile; |
| 268 | pindexNew->nDataPos = diskindex.nDataPos; |
| 269 | pindexNew->nUndoPos = diskindex.nUndoPos; |
| 270 | pindexNew->nVersion = diskindex.nVersion; |
| 271 | pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot; |
| 272 | memcpy(pindexNew->nReserved, diskindex.nReserved, sizeof(pindexNew->nReserved)); |
| 273 | pindexNew->nTime = diskindex.nTime; |
| 274 | pindexNew->nBits = diskindex.nBits; |
| 275 | pindexNew->nNonce = diskindex.nNonce; |
| 276 | pindexNew->nSolution = diskindex.nSolution; |
| 277 | pindexNew->nStatus = diskindex.nStatus; |
| 278 | pindexNew->nTx = diskindex.nTx; |
| 279 | |
| 280 | // TODO(h4x3rotab): Check Equihash solution? Not sure why Zcash doesn't do it here. |
| 281 | bool postfork = pindexNew->nHeight >= consensusParams.BTGHeight; |
| 282 | if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, postfork, consensusParams)) |
| 283 | return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString()); |
| 284 | |
| 285 | pcursor->Next(); |
| 286 | } else { |
| 287 | return error("%s: failed to read value", __func__); |
| 288 | } |
| 289 | } else { |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | namespace { |
| 298 |
no test coverage detected