| 118 | } |
| 119 | |
| 120 | bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, const util::SignalInterrupt& interrupt) |
| 121 | { |
| 122 | AssertLockHeld(::cs_main); |
| 123 | std::unique_ptr<CDBIterator> pcursor(NewIterator()); |
| 124 | pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256())); |
| 125 | |
| 126 | // Load m_block_index |
| 127 | while (pcursor->Valid()) { |
| 128 | if (interrupt) return false; |
| 129 | std::pair<uint8_t, uint256> key; |
| 130 | if (pcursor->GetKey(key) && key.first == DB_BLOCK_INDEX) { |
| 131 | CDiskBlockIndex diskindex; |
| 132 | if (pcursor->GetValue(diskindex)) { |
| 133 | // Construct block index object |
| 134 | CBlockIndex* pindexNew = insertBlockIndex(diskindex.ConstructBlockHash()); |
| 135 | pindexNew->pprev = insertBlockIndex(diskindex.hashPrev); |
| 136 | pindexNew->nHeight = diskindex.nHeight; |
| 137 | pindexNew->nFile = diskindex.nFile; |
| 138 | pindexNew->nDataPos = diskindex.nDataPos; |
| 139 | pindexNew->nUndoPos = diskindex.nUndoPos; |
| 140 | pindexNew->nVersion = diskindex.nVersion; |
| 141 | pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot; |
| 142 | pindexNew->nTime = diskindex.nTime; |
| 143 | pindexNew->nBits = diskindex.nBits; |
| 144 | pindexNew->nNonce = diskindex.nNonce; |
| 145 | pindexNew->nStatus = diskindex.nStatus; |
| 146 | pindexNew->nTx = diskindex.nTx; |
| 147 | |
| 148 | if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) { |
| 149 | LogError("%s: CheckProofOfWork failed: %s\n", __func__, pindexNew->ToString()); |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | pcursor->Next(); |
| 154 | } else { |
| 155 | LogError("%s: failed to read value\n", __func__); |
| 156 | return false; |
| 157 | } |
| 158 | } else { |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | return true; |
| 164 | } |
| 165 | |
| 166 | std::string CBlockFileInfo::ToString() const |
| 167 | { |
no test coverage detected