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

Method LoadBlockIndexGuts

src/node/blockstorage.cpp:120–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120bool 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
166std::string CBlockFileInfo::ToString() const
167{

Callers 2

block_index.cppFile · 0.80
LoadBlockIndexMethod · 0.80

Calls 10

CheckProofOfWorkFunction · 0.85
ConstructBlockHashMethod · 0.80
uint256Class · 0.70
SeekMethod · 0.45
ValidMethod · 0.45
GetKeyMethod · 0.45
GetValueMethod · 0.45
GetBlockHashMethod · 0.45
ToStringMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected