// Copyright (c) 2018-2025 The Dash Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include CEvoDBScopedCommitter::CEvoDBScopedCommitter(CEvoDB& _evoDB, EvoDbIdentity identity) : evoDB{_evoDB}, identity{identity} { } CEvoDBScopedCommitter::~CEvoDBScopedCommitter() { if (!didCommitOrRollback) Rollback(); } void CEvoDBScopedCommitter::Commit() { assert(!didCommitOrRollback); didCommitOrRollback = true; evoDB.CommitCurTransaction(identity); } void CEvoDBScopedCommitter::Rollback() { assert(!didCommitOrRollback); didCommitOrRollback = true; evoDB.RollbackCurTransaction(identity); } namespace { DataStream NamespaceTag() { DataStream tag{}; tag << EVODB_GENERATION_NAMESPACE; return tag; } bool StartsWith(const DataStream& key, const DataStream& prefix) { return key.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), key.begin()); } bool SameBytes(const DataStream& a, const DataStream& b) { return std::equal(a.begin(), a.end(), b.begin(), b.end()); } auto GenerationRecordKey(uint32_t generation) { return std::make_pair(EVODB_GENERATION_RECORD, generation); } } // namespace DataStream CEvoDBStore::GenerationPrefix(uint32_t generation) { DataStream prefix{}; if (generation != 0) prefix << EVODB_GENERATION_NAMESPACE << generation; return prefix; } bool CEvoDBStore::Owns(const DataStream& raw_key) const { if (m_prefix.empty()) return !StartsWith(raw_key, NamespaceTag()); return StartsWith(raw_key, m_prefix); } void CEvoDBStore::Iterator::SkipForeign() { // Generation namespaces form one contiguous key range. The NORMAL view // steps over it as a whole; a generation view ends where its prefix ends. if (!m_store.m_prefix.empty() || !m_it->Valid()) return; const DataStream tag{NamespaceTag()}; if (!StartsWith(m_it->GetKey(), tag)) return; DataStream after_tag{tag}; std::byte& last{after_tag[after_tag.size() - 1]}; last = std::byte{static_cast(std::to_integer(last) + 1)}; m_it->Seek(after_tag); } CEvoDB::CEvoDB(const util::DbWrapperParams& db_params) : db{util::MakeDbWrapper({db_params.path / "evodb", db_params.memory, db_params.wipe, /*cache_size=*/64 << 20, db_params.options})} { transaction_contexts.emplace(EvoDbIdentity::NORMAL, std::make_unique(*db, DataStream{})); } CEvoDB::~CEvoDB() = default; CEvoDB::TransactionContext& CEvoDB::GetContext(EvoDbIdentity identity) { auto it = transaction_contexts.find(identity); if (it == transaction_contexts.end()) { if (identity == EvoDbIdentity::SNAPSHOT && !m_snapshot_generation) { throw EvoViewBindingError("EvoDB: the snapshot identity has no generation bound"); } const uint32_t generation{identity == EvoDbIdentity::SNAPSHOT ? m_snapshot_generation->generation : 0}; // Construct the context before inserting so a throwing constructor // cannot leave a null entry behind for later dereference. auto context{std::make_unique(*db, CEvoDBStore::GenerationPrefix(generation))}; it = transaction_contexts.emplace(identity, std::move(context)).first; } return *it->second; } const CEvoDB::TransactionContext& CEvoDB::GetContext(EvoDbIdentity identity) const { return *transaction_contexts.at(identity); } EvoViewToken CEvoDB::MakeView(EvoDbIdentity identity) const { if (identity == EvoDbIdentity::SNAPSHOT && m_snapshot_generation) { return EvoViewToken{.db = this, .identity = identity, .generation = m_snapshot_generation->generation, .base = m_snapshot_generation->base, .base_height = m_snapshot_generation->base_height}; } return EvoViewToken{.db = this, .identity = identity}; } EvoViewToken CEvoDB::ResolveView() const { if (HoldsTransaction()) return MakeView(*active_transaction); return MakeView(m_default_identity); } EvoViewToken CEvoDB::CurrentView() const { LOCK(cs); return ResolveView(); } EvoViewToken CEvoDB::ViewFor(EvoDbIdentity identity) const { LOCK(cs); return MakeView(identity); } std::unique_ptr CEvoDB::BeginTransaction(EvoDbIdentity identity) { AssertLockHeld(::cs_main); LOCK(cs); assert(!active_transaction.has_value()); assert(identity == EvoDbIdentity::NORMAL || m_snapshot_generation); GetContext(identity); active_transaction = identity; active_transaction_thread = std::this_thread::get_id(); return std::make_unique(*this, identity); } void CEvoDB::CommitCurTransaction(EvoDbIdentity identity) { AssertLockHeld(::cs_main); LOCK(cs); assert(active_transaction == identity); GetContext(identity).cur_transaction.Commit(); active_transaction.reset(); } void CEvoDB::RollbackCurTransaction(EvoDbIdentity identity) { AssertLockHeld(::cs_main); LOCK(cs); assert(active_transaction == identity); // The open transaction's context exists. Never create one here: that can // throw, and this runs from CEvoDBScopedCommitter's destructor. if (const auto it{transaction_contexts.find(identity)}; it != transaction_contexts.end()) { it->second->cur_transaction.Clear(); } active_transaction.reset(); } bool CEvoDB::CommitRootTransaction(EvoDbIdentity identity, bool sync) { AssertLockHeld(::cs_main); LOCK(cs); auto& context = GetContext(identity); assert(context.cur_transaction.IsClean()); context.root_transaction.Commit(); bool ret = db->WriteBatch(context.root_batch, sync); context.root_batch.Clear(); return ret; } bool CEvoDB::ReadBestBlock(EvoDbIdentity identity, uint256& hash) { LOCK(cs); if (identity == EvoDbIdentity::SNAPSHOT && !m_snapshot_generation) return false; auto& transaction = GetContext(identity).cur_transaction; if (identity == EvoDbIdentity::NORMAL) { return transaction.Read(EVODB_BEST_BLOCK, hash); } return transaction.Read(std::make_pair(EVODB_BEST_BLOCK, uint8_t{1}), hash); } bool CEvoDB::VerifyBestBlock(EvoDbIdentity identity, const uint256& hash) { // Make sure evodb is consistent. // If we already have best block hash saved, the previous block should match it. uint256 hash_best_block; return ReadBestBlock(identity, hash_best_block) && hash_best_block == hash; } void CEvoDB::WriteBestBlock(EvoDbIdentity identity, const uint256& hash) { LOCK(cs); auto& transaction = GetContext(identity).cur_transaction; if (identity == EvoDbIdentity::NORMAL) { transaction.Write(EVODB_BEST_BLOCK, hash); } else { transaction.Write(std::make_pair(EVODB_BEST_BLOCK, uint8_t{1}), hash); } } void CEvoDB::WriteDualChainstateMarker() { LOCK(cs); db->Write(EVODB_DUAL_CHAINSTATE, uint8_t{1}); } bool CEvoDB::HasDualChainstateMarker() { LOCK(cs); return db->Exists(EVODB_DUAL_CHAINSTATE); } void CEvoDB::WriteSnapshotBaseMNListHash(const uint256& hash) { LOCK(cs); db->Write(EVODB_SNAPSHOT_MNLIST_HASH, hash); } bool CEvoDB::ReadSnapshotBaseMNListHash(uint256& hash) { // Lifecycle markers are read at rest (completion after both identities' // sync commits, or startup recovery). Read the raw DB so the result cannot // depend on which transaction-less default identity happens to be current. LOCK(cs); return db->Read(EVODB_SNAPSHOT_MNLIST_HASH, hash); } void CEvoDB::WriteBackgroundMNListHash(const uint256& block_hash, const uint256& mn_list_hash) { Write(EVODB_BACKGROUND_MNLIST_HASH, std::make_pair(block_hash, mn_list_hash)); } bool CEvoDB::ReadBackgroundMNListHash(uint256& block_hash, uint256& mn_list_hash) { // See ReadSnapshotBaseMNListHash: at-rest raw read, identity-independent. LOCK(cs); std::pair value; if (!db->Read(EVODB_BACKGROUND_MNLIST_HASH, value)) return false; std::tie(block_hash, mn_list_hash) = value; return true; } std::optional CEvoDB::GetSnapshotGeneration() const { LOCK(cs); return m_snapshot_generation; } void CEvoDB::BindSnapshotGeneration(std::optional record) { // A context's store is keyed by the generation it was built for. if (auto it{transaction_contexts.find(EvoDbIdentity::SNAPSHOT)}; it != transaction_contexts.end()) { Assume(it->second->cur_transaction.IsClean() && it->second->root_transaction.IsClean()); transaction_contexts.erase(it); } m_snapshot_generation = std::move(record); if (!m_snapshot_generation) m_default_identity = EvoDbIdentity::NORMAL; } bool CEvoDB::TransactionsClean() const { if (active_transaction.has_value()) return false; return std::ranges::all_of(transaction_contexts, [](const auto& entry) { return !entry.second || (entry.second->cur_transaction.IsClean() && entry.second->root_transaction.IsClean()); }); } namespace { bool IsKnown(EvoGenerationState state) { return state <= EvoGenerationState::PROMOTING; } bool IsValid(const EvoPromotionJournal& journal) { return journal.schema_version == EvoGenerationRecord::SCHEMA_VERSION && journal.phase <= EvoPromotionPhase::MERGED; } } // namespace bool CEvoDB::CreateSnapshotGeneration(const uint256& base, int base_height) { LOCK(cs); if (m_snapshot_generation) return false; uint32_t generation{1}; if (db->Exists(EVODB_GENERATION_NEXT) && !db->Read(EVODB_GENERATION_NEXT, generation)) { LogPrintf("ERROR: %s: cannot read the next snapshot EvoDB generation id\n", __func__); return false; } // Generation 0 names the NORMAL keyspace; never wrap into it. if (generation == 0 || generation == std::numeric_limits::max()) { LogPrintf("ERROR: %s: snapshot EvoDB generation ids are exhausted\n", __func__); return false; } EvoGenerationRecord record; record.generation = generation; record.state = EvoGenerationState::UNPUBLISHED; record.base = base; record.base_height = base_height; record.tip = base; CDBBatch batch{*db}; batch.Write(EVODB_GENERATION_NEXT, generation + 1); batch.Write(GenerationRecordKey(generation), record); if (!db->WriteBatch(batch, /*fSync=*/true)) return false; BindSnapshotGeneration(record); return true; } bool CEvoDB::PublishSnapshotGeneration(const std::optional& base_mn_list_hash) { LOCK(cs); if (!m_snapshot_generation || m_snapshot_generation->state != EvoGenerationState::UNPUBLISHED) return false; EvoGenerationRecord record{*m_snapshot_generation}; record.state = EvoGenerationState::PUBLISHED; CDBBatch batch{*db}; batch.Write(GenerationRecordKey(record.generation), record); batch.Write(EVODB_DUAL_CHAINSTATE, uint8_t{1}); if (base_mn_list_hash) batch.Write(EVODB_SNAPSHOT_MNLIST_HASH, *base_mn_list_hash); if (!db->WriteBatch(batch, /*fSync=*/true)) return false; m_snapshot_generation = record; return true; } util::Result CEvoDB::LoadSnapshotGenerations() { LOCK(cs); if (!Assume(TransactionsClean())) return util::Error{_("Evo database transactions are pending at startup.")}; BindSnapshotGeneration(std::nullopt); std::vector records; { std::unique_ptr it{db->NewIterator()}; it->Seek(GenerationRecordKey(0)); for (; it->Valid() && !it->HasError(); it->Next()) { std::pair key; if (!it->GetKey(key) || key.first != EVODB_GENERATION_RECORD) break; EvoGenerationRecord record; if (!it->GetValue(record) || record.schema_version != EvoGenerationRecord::SCHEMA_VERSION || !IsKnown(record.state) || record.generation == 0 || record.generation != key.second) { // Refused before anything on disk changes, so the version that // loaded the snapshot can still resume it. return util::Error{_("The Evo database holds assumeutxo snapshot state in a format this version " "does not support. Restart with the version that loaded the snapshot, or " "with -reindex-chainstate to discard it.")}; } records.push_back(record); } if (it->HasError()) { return util::Error{_("The Evo database's assumeutxo snapshot state cannot be read. " "Restart with -reindex-chainstate to discard it.")}; } } std::optional live; for (const EvoGenerationRecord& record : records) { if (record.state != EvoGenerationState::PUBLISHED && record.state != EvoGenerationState::PROMOTING) continue; if (live) { return util::Error{_("The Evo database holds more than one live assumeutxo snapshot state. " "Restart with -reindex-chainstate to discard them.")}; } live = record; } EvoPromotionJournal journal; const bool finishing_promotion{db->Read(EVODB_PROMOTION_JOURNAL, journal)}; if (db->Exists(EVODB_PROMOTION_JOURNAL) && (!finishing_promotion || !IsValid(journal))) { return util::Error{_("The Evo database holds an assumeutxo promotion journal in an unsupported format. " "Restart with -reindex-chainstate to discard it.")}; } // The journal and its PROMOTING record are written and erased together. if (finishing_promotion && (!live || live->state != EvoGenerationState::PROMOTING || live->generation != journal.generation || live->base != journal.base || live->tip != journal.tip)) { return util::Error{_("The Evo database holds an assumeutxo promotion journal that does not match its " "snapshot state. Restart with -reindex-chainstate to discard it.")}; } if (!finishing_promotion && live && live->state == EvoGenerationState::PROMOTING) { return util::Error{_("The Evo database holds assumeutxo snapshot state marked as being promoted, but its " "promotion journal is missing. Restart with -reindex-chainstate to discard it.")}; } // The dual-chainstate marker is written with a live record, and erased only by the batch that ends it. if (live && !db->Exists(EVODB_DUAL_CHAINSTATE)) { return util::Error{_("The Evo database holds live assumeutxo snapshot state, but its dual-chainstate " "marker is missing. Restart with -reindex-chainstate to discard it.")}; } for (const EvoGenerationRecord& record : records) { if (record.state == EvoGenerationState::UNPUBLISHED && !CollectGeneration(record.generation, /*erase_record=*/true)) { return util::Error{_("Failed to remove discarded assumeutxo snapshot state from the Evo database. " "Restart with -reindex-chainstate to discard it.")}; } // A rejected generation is kept until startup recovery has invalidated // its coins directory. } if (!live && (db->Exists(EVODB_DUAL_CHAINSTATE) || db->Exists(std::make_pair(EVODB_BEST_BLOCK, uint8_t{1})))) { return util::Error{_("An assumeutxo snapshot in progress was loaded by an older version that did not " "isolate its Evo state. Restart with -reindex-chainstate to discard it.")}; } BindSnapshotGeneration(live); return {}; } bool CEvoDB::HasRejectedGeneration() const { LOCK(cs); // Records that cannot be read count, so that the recovery that collects // rejected generations runs and fails. const auto rejected{RejectedGenerations()}; return !rejected || !rejected->empty(); } std::optional> CEvoDB::RejectedGenerations() const { std::vector rejected; std::unique_ptr it{db->NewIterator()}; for (it->Seek(GenerationRecordKey(0)); it->Valid() && !it->HasError(); it->Next()) { std::pair key; if (!it->GetKey(key) || key.first != EVODB_GENERATION_RECORD) break; EvoGenerationRecord record; if (it->GetValue(record) && record.state == EvoGenerationState::REJECTED) rejected.push_back(key.second); } if (it->HasError()) { LogPrintf("ERROR: %s: cannot read the snapshot generation records\n", __func__); return std::nullopt; } return rejected; } bool CEvoDB::CollectRejectedGenerations() { LOCK(cs); const auto rejected{RejectedGenerations()}; if (!rejected) return false; for (const uint32_t generation : *rejected) { if (!CollectGeneration(generation, /*erase_record=*/true)) return false; } return true; } bool CEvoDB::CollectGeneration(uint32_t generation, bool erase_record) { if (!Assume(generation != 0)) return false; const DataStream prefix{CEvoDBStore::GenerationPrefix(generation)}; std::unique_ptr it{db->NewIterator()}; CDBBatch batch{*db}; size_t pending{0}; for (it->Seek(prefix); it->Valid() && !it->HasError() && StartsWith(it->GetKey(), prefix); it->Next()) { batch.Erase(it->GetKey()); if (++pending >= m_merge_batch_size) { if (!db->WriteBatch(batch)) return false; batch.Clear(); pending = 0; } } // A read error ends the scan early: keep the record that owns what is left. if (it->HasError()) { LogPrintf("ERROR: %s: cannot read snapshot generation %u; it is kept\n", __func__, generation); return false; } if (erase_record) batch.Erase(GenerationRecordKey(generation)); return db->WriteBatch(batch, /*fSync=*/true); } bool CEvoDB::DiscardBoundGeneration() { CDBBatch batch{*db}; batch.Erase(EVODB_SNAPSHOT_MNLIST_HASH); batch.Erase(EVODB_BACKGROUND_MNLIST_HASH); batch.Erase(EVODB_DUAL_CHAINSTATE); batch.Erase(EVODB_PROMOTION_JOURNAL); if (m_snapshot_generation) { EvoGenerationRecord record{*m_snapshot_generation}; record.state = EvoGenerationState::REJECTED; batch.Write(GenerationRecordKey(record.generation), record); } // A failure to persist the rejection leaves the generation live, and the // dual-chainstate markers with it; startup recovery then retries. The // REJECTED record stays until the snapshot's coins directory is // invalidated (CollectRejectedGenerations), so a crash in between can // still finish the invalidation. if (!db->WriteBatch(batch, /*fSync=*/true)) return false; BindSnapshotGeneration(std::nullopt); return true; } bool CEvoDB::AbandonSnapshotGeneration() { AssertLockHeld(::cs_main); LOCK(cs); if (!Assume(!active_transaction.has_value())) return false; if (auto it{transaction_contexts.find(EvoDbIdentity::SNAPSHOT)}; it != transaction_contexts.end()) { it->second->cur_transaction.Clear(); it->second->root_transaction.Clear(); it->second->root_batch.Clear(); } return DiscardBoundGeneration(); } bool CEvoDB::DiscardSnapshotMarkers() { LOCK(cs); if (!Assume(TransactionsClean())) return false; return DiscardBoundGeneration(); } bool CEvoDB::PrepareSnapshotPromotion(const uint256& snapshot_tip) { LOCK(cs); if (!m_snapshot_generation || !Assume(TransactionsClean())) return false; // The coins tip being promoted must be the tip the generation's Evo state // was flushed at. uint256 evo_tip; if (!GetContext(EvoDbIdentity::SNAPSHOT).cur_transaction.Read(std::make_pair(EVODB_BEST_BLOCK, uint8_t{1}), evo_tip) || evo_tip != snapshot_tip) { return false; } EvoPromotionJournal journal; if (db->Read(EVODB_PROMOTION_JOURNAL, journal)) { // Only a promotion that has not renamed anything yet may be redone. if (!IsValid(journal) || journal.generation != m_snapshot_generation->generation || journal.phase != EvoPromotionPhase::PREPARED) { return false; } } journal = EvoPromotionJournal{}; journal.generation = m_snapshot_generation->generation; journal.base = m_snapshot_generation->base; journal.tip = snapshot_tip; uint256 base_mn_list_hash; if (db->Read(EVODB_SNAPSHOT_MNLIST_HASH, base_mn_list_hash)) journal.base_mn_list_hash = base_mn_list_hash; EvoGenerationRecord record{*m_snapshot_generation}; record.state = EvoGenerationState::PROMOTING; record.tip = snapshot_tip; CDBBatch batch{*db}; batch.Write(EVODB_PROMOTION_JOURNAL, journal); batch.Write(GenerationRecordKey(record.generation), record); if (!db->WriteBatch(batch, /*fSync=*/true)) return false; m_snapshot_generation = record; return true; } std::optional CEvoDB::ReadPromotionJournal() const { LOCK(cs); EvoPromotionJournal journal; if (!db->Read(EVODB_PROMOTION_JOURNAL, journal)) return std::nullopt; return journal; } bool CEvoDB::MergeGeneration(EvoPromotionJournal& journal) { const DataStream prefix{CEvoDBStore::GenerationPrefix(journal.generation)}; DataStream best_block_key{}; best_block_key << std::make_pair(EVODB_BEST_BLOCK, uint8_t{1}); DataStream manifest_tag{}; manifest_tag << EVODB_SEED_MANIFEST; std::unique_ptr it{db->NewIterator()}; DataStream start{prefix}; start.write(MakeByteSpan(journal.cursor)); it->Seek(start); // The cursor names the last merged key; resume after it. if (!journal.cursor.empty() && it->Valid() && SameBytes(it->GetKey(), start)) it->Next(); CDBBatch batch{*db}; size_t pending{0}; // A read error can skip records and leave the iterator valid past them: // stop before handling, or moving the cursor past, any later key. for (; it->Valid() && !it->HasError(); it->Next()) { const DataStream raw_key{it->GetKey()}; if (!StartsWith(raw_key, prefix)) break; DataStream key{raw_key}; key.ignore(prefix.size()); DataStream manifest_key{prefix}; manifest_key << SeedManifestKey(key); // The promoted best block is published with the final markers, and the // seed manifest describes this generation only. A seed restates state // at or below the base that NORMAL derived itself, and completion has // already checked the evo section it came from against NORMAL's. if (!SameBytes(key, best_block_key) && !StartsWith(key, manifest_tag) && !db->Exists(manifest_key)) { DataStream value{}; if (!db->ReadDataStream(raw_key, value)) return false; DataStream normal_value{}; const bool in_normal{db->ReadDataStream(key, normal_value)}; if (!in_normal) { batch.Write(key, Span{value}); } else if (!SameBytes(normal_value, value)) { // Unseeded records are derived from blocks above the base. NORMAL // keeps what it derived from such a block before rewinding below // the base, which is the same record. LogPrintf("ERROR: %s: snapshot generation %u disagrees with NORMAL state for key %s\n", __func__, journal.generation, HexStr(key)); return false; } } journal.cursor.assign(UCharCast(key.data()), UCharCast(key.data() + key.size())); if (++pending >= m_merge_batch_size) { batch.Write(EVODB_PROMOTION_JOURNAL, journal); if (!db->WriteBatch(batch, /*fSync=*/true)) return false; batch.Clear(); pending = 0; if (m_promotion_failpoint == PromotionFailpoint::MID_MERGE) return false; } } if (it->HasError()) { LogPrintf("ERROR: %s: cannot read snapshot generation %u; the promotion stays journaled\n", __func__, journal.generation); return false; } journal.phase = EvoPromotionPhase::MERGED; journal.cursor.clear(); batch.Write(EVODB_PROMOTION_JOURNAL, journal); return db->WriteBatch(batch, /*fSync=*/true); } bool CEvoDB::PromoteSnapshotMarkers(const uint256& expected_snapshot_tip) { LOCK(cs); if (!Assume(TransactionsClean())) return false; EvoPromotionJournal journal; if (!db->Read(EVODB_PROMOTION_JOURNAL, journal)) { uint256 normal_tip; const bool already_promoted = db->Read(EVODB_BEST_BLOCK, normal_tip) && normal_tip == expected_snapshot_tip && !m_snapshot_generation && !db->Exists(EVODB_DUAL_CHAINSTATE) && !db->Exists(EVODB_SNAPSHOT_MNLIST_HASH) && !db->Exists(EVODB_BACKGROUND_MNLIST_HASH); if (already_promoted) m_default_identity = EvoDbIdentity::NORMAL; return already_promoted; } if (!IsValid(journal) || journal.tip != expected_snapshot_tip) return false; if (journal.phase == EvoPromotionPhase::PREPARED) { journal.phase = EvoPromotionPhase::MERGING; if (!db->Write(EVODB_PROMOTION_JOURNAL, journal, /*fSync=*/true)) return false; } if (journal.phase == EvoPromotionPhase::MERGING && !MergeGeneration(journal)) return false; if (m_promotion_failpoint == PromotionFailpoint::AFTER_MERGE) return false; // Everything is merged: collecting the namespace (idempotent) cannot lose // data, and the journal still carries the promoted tip. The PROMOTING // record stays until the final batch. BindSnapshotGeneration(std::nullopt); if (!CollectGeneration(journal.generation, /*erase_record=*/false)) return false; if (m_promotion_failpoint == PromotionFailpoint::AFTER_COLLECT) return false; CDBBatch batch{*db}; batch.Write(EVODB_BEST_BLOCK, journal.tip); batch.Erase(EVODB_SNAPSHOT_MNLIST_HASH); batch.Erase(EVODB_BACKGROUND_MNLIST_HASH); batch.Erase(EVODB_DUAL_CHAINSTATE); batch.Erase(EVODB_PROMOTION_JOURNAL); batch.Erase(GenerationRecordKey(journal.generation)); if (!db->WriteBatch(batch, /*fSync=*/true)) return false; // The dual-chainstate run is over: the promoted state is the NORMAL // identity, so transaction-less access must resolve there again. m_default_identity = EvoDbIdentity::NORMAL; return true; }