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

Method Rewind

src/index/blockfilterindex.cpp:281–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279}
280
281bool BlockFilterIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip)
282{
283 assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);
284
285 CDBBatch batch(*m_db);
286 std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
287
288 // During a reorg, we need to copy all filters for blocks that are getting disconnected from the
289 // height index to the hash index so we can still find them when the height index entries are
290 // overwritten.
291 if (!CopyHeightIndexToHashIndex(*db_it, batch, m_name, new_tip->nHeight, current_tip->nHeight)) {
292 return false;
293 }
294
295 // The latest filter position gets written in Commit by the call to the BaseIndex::Rewind.
296 // But since this creates new references to the filter, the position should get updated here
297 // atomically as well in case Commit fails.
298 batch.Write(DB_FILTER_POS, m_next_filter_pos);
299 if (!m_db->WriteBatch(batch)) return false;
300
301 return BaseIndex::Rewind(current_tip, new_tip);
302}
303
304static bool LookupOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVal& result)
305{

Callers

nothing calls this directly

Calls 5

GetAncestorMethod · 0.80
NewIteratorMethod · 0.45
WriteMethod · 0.45
WriteBatchMethod · 0.45

Tested by

no test coverage detected