From ebae59eedfd9abcfbbb3cdb7be97eb730d62e0da Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sun, 13 Oct 2024 15:43:07 +0000 Subject: [PATCH] fix: make sure we flush our committed best block in no-upgrade cases This was spotted when working on `feature_txindex_compatibility.py`, attempting to load old databases would fail because `MigrateDBIfNeeded()` would delete `DB_OLD_BEST_BLOCK`, write `EVODB_BEST_BLOCK`, commit it but never flush it. So when `MigrateDBIfNeeded2()` would read it again, it would note the lack of `DB_OLD_BEST_BLOCK` and conclude it was a failed run and exit. This is solved by actually flushing our new best block, which would prevent `MigrateDBIfNeeded2` from raising an objection. --- src/evo/deterministicmns.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index ac167a298b..495ca8a03b 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -1238,6 +1238,10 @@ bool CDeterministicMNManager::MigrateDBIfNeeded() auto dbTx = m_evoDb.BeginTransaction(); m_evoDb.WriteBestBlock(m_chainstate.m_chain.Tip()->GetBlockHash()); dbTx->Commit(); + if (!m_evoDb.CommitRootTransaction()) { + LogPrintf("CDeterministicMNManager::%s -- failed to commit to evoDB\n", __func__); + return false; + } return true; } @@ -1349,6 +1353,10 @@ bool CDeterministicMNManager::MigrateDBIfNeeded2() auto dbTx = m_evoDb.BeginTransaction(); m_evoDb.WriteBestBlock(m_chainstate.m_chain.Tip()->GetBlockHash()); dbTx->Commit(); + if (!m_evoDb.CommitRootTransaction()) { + LogPrintf("CDeterministicMNManager::%s -- failed to commit to evoDB\n", __func__); + return false; + } return true; }