MCPcopy Create free account
hub / github.com/ElementsProject/elements / Rewind

Method Rewind

src/index/coinstatsindex.cpp:276–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274}
275
276bool CoinStatsIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip)
277{
278 assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);
279
280 CDBBatch batch(*m_db);
281 std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
282
283 // During a reorg, we need to copy all hash digests for blocks that are
284 // getting disconnected from the height index to the hash index so we can
285 // still find them when the height index entries are overwritten.
286 if (!CopyHeightIndexToHashIndex(*db_it, batch, m_name, new_tip->nHeight, current_tip->nHeight)) {
287 return false;
288 }
289
290 if (!m_db->WriteBatch(batch)) return false;
291
292 {
293 LOCK(cs_main);
294 CBlockIndex* iter_tip{m_chainstate->m_blockman.LookupBlockIndex(current_tip->GetBlockHash())};
295 const auto& consensus_params{Params().GetConsensus()};
296
297 do {
298 CBlock block;
299
300 if (!ReadBlockFromDisk(block, iter_tip, consensus_params)) {
301 return error("%s: Failed to read block %s from disk",
302 __func__, iter_tip->GetBlockHash().ToString());
303 }
304
305 ReverseBlock(block, iter_tip);
306
307 iter_tip = iter_tip->GetAncestor(iter_tip->nHeight - 1);
308 } while (new_tip != iter_tip);
309 }
310
311 return BaseIndex::Rewind(current_tip, new_tip);
312}
313
314static bool LookUpOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVal& result)
315{

Callers

nothing calls this directly

Calls 10

ReadBlockFromDiskFunction · 0.85
errorFunction · 0.85
GetAncestorMethod · 0.80
LookupBlockIndexMethod · 0.80
ParamsClass · 0.50
NewIteratorMethod · 0.45
WriteBatchMethod · 0.45
GetBlockHashMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected