diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 490a44f05c..deacb1d2ce 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -1077,7 +1077,7 @@ void CDeterministicMNManager::CleanupCache(int nHeight) } } -bool CDeterministicMNManager::UpgradeDiff(CDBBatch& batch, const CBlockIndex* pindexNext, const CDeterministicMNList& curMNList, CDeterministicMNList& newMNList) +void CDeterministicMNManager::UpgradeDiff(CDBBatch& batch, const CBlockIndex* pindexNext, const CDeterministicMNList& curMNList, CDeterministicMNList& newMNList) { CDataStream oldDiffData(SER_DISK, CLIENT_VERSION); if (!evoDb.GetRawDB().ReadDataStream(std::make_pair(DB_LIST_DIFF, pindexNext->GetBlockHash()), oldDiffData)) { @@ -1085,7 +1085,7 @@ bool CDeterministicMNManager::UpgradeDiff(CDBBatch& batch, const CBlockIndex* pi newMNList = curMNList; newMNList.SetBlockHash(pindexNext->GetBlockHash()); newMNList.SetHeight(pindexNext->nHeight); - return false; + return; } CDeterministicMNListDiff_OldFormat oldDiff; @@ -1125,27 +1125,27 @@ bool CDeterministicMNManager::UpgradeDiff(CDBBatch& batch, const CBlockIndex* pi batch.Write(std::make_pair(DB_LIST_DIFF, pindexNext->GetBlockHash()), newDiff); - return true; + return; } // TODO this can be completely removed in a future version -void CDeterministicMNManager::UpgradeDBIfNeeded() +bool CDeterministicMNManager::UpgradeDBIfNeeded() { LOCK(cs_main); if (chainActive.Tip() == nullptr) { - return; + return true; } if (evoDb.GetRawDB().Exists(EVODB_BEST_BLOCK)) { - return; + return true; } // Removing the old EVODB_BEST_BLOCK value early results in older version to crash immediately, even if the upgrade // process is cancelled in-between. But if the new version sees that the old EVODB_BEST_BLOCK is already removed, // then we must assume that the upgrade process was already running before but was interrupted. if (chainActive.Height() > 1 && !evoDb.GetRawDB().Exists(std::string("b_b"))) { - LogPrintf("CDeterministicMNManager::%s -- ERROR, upgrade process was interrupted and can't be continued. You need to reindex now.\n", __func__); + return false; } evoDb.GetRawDB().Erase(std::string("b_b")); @@ -1154,7 +1154,7 @@ void CDeterministicMNManager::UpgradeDBIfNeeded() auto dbTx = evoDb.BeginTransaction(); evoDb.WriteBestBlock(chainActive.Tip()->GetBlockHash()); dbTx->Commit(); - return; + return true; } LogPrintf("CDeterministicMNManager::%s -- upgrading DB to use compact diffs\n", __func__); @@ -1190,4 +1190,6 @@ void CDeterministicMNManager::UpgradeDBIfNeeded() dbTx->Commit(); evoDb.GetRawDB().CompactFull(); + + return true; } diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index a65013fb06..c5dfe60b4a 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -673,8 +673,8 @@ public: public: // TODO these can all be removed in a future version - bool UpgradeDiff(CDBBatch& batch, const CBlockIndex* pindexNext, const CDeterministicMNList& curMNList, CDeterministicMNList& newMNList); - void UpgradeDBIfNeeded(); + void UpgradeDiff(CDBBatch& batch, const CBlockIndex* pindexNext, const CDeterministicMNList& curMNList, CDeterministicMNList& newMNList); + bool UpgradeDBIfNeeded(); private: void CleanupCache(int nHeight); diff --git a/src/init.cpp b/src/init.cpp index 1159b057fa..94b3fb5949 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1944,7 +1944,10 @@ bool AppInitMain() assert(chainActive.Tip() != NULL); } - deterministicMNManager->UpgradeDBIfNeeded(); + if (!deterministicMNManager->UpgradeDBIfNeeded()) { + strLoadError = _("Error upgrading evo database"); + break; + } if (!is_coinsview_empty) { uiInterface.InitMessage(_("Verifying blocks..."));