From e8049b5200b108acd7d7c0531e5a957013b0926d Mon Sep 17 00:00:00 2001 From: Anthony Fieroni Date: Wed, 27 Apr 2022 10:39:23 +0300 Subject: [PATCH] Force reindex when dex live does not present Signed-off-by: Anthony Fieroni --- src/init.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 2f775dc02d4..8387a1d0c18 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -1618,9 +1619,23 @@ bool AppInitMain(InitInterfaces& interfaces) pcustomcsview.reset(); pcustomcsview = MakeUnique(*pcustomcsDB.get()); if (!fReset && !fReindexChainState) { - if (!pcustomcsDB->IsEmpty() && pcustomcsview->GetDbVersion() != CCustomCSView::DbVersion) { - strLoadError = _("Account database is unsuitable").translated; - break; + if (!pcustomcsDB->IsEmpty()) { + if (pcustomcsview->GetDbVersion() != CCustomCSView::DbVersion) { + strLoadError = _("Account database is unsuitable").translated; + break; + } + // force reindex iif there is at least one pool swap + PoolHeightKey anyPoolSwap{DCT_ID{}, ~0u}; + auto it = pcustomcsview->LowerBound(anyPoolSwap); + auto shouldReindex = it.Valid(); + if (auto attributes = pcustomcsview->GetAttributes()) { + CDataStructureV0 dexKey{AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::DexTokens}; + shouldReindex &= !attributes->CheckKey(dexKey); + } + if (shouldReindex) { + strLoadError = _("Live dex needs reindex").translated; + break; + } } }