From b1b99c53c1a3c7fb6624154781e125c28d37094d Mon Sep 17 00:00:00 2001 From: Bushstar Date: Tue, 7 Feb 2023 06:49:17 +0000 Subject: [PATCH] Throw error on invalid state --- src/init.cpp | 10 +++++++--- src/masternodes/loan.cpp | 4 ---- src/masternodes/loan.h | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index c15a81f4fb..098fa93916 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1396,7 +1396,7 @@ void SetupInterrupts() { fStopOrInterrupt = isSet; } -static void EraseLoanAmountsInClosedVaults(CCustomCSView &mnview) { +static bool LoanAmountsInClosedVaults(CCustomCSView &mnview) { LOCK(cs_main); std::set vaults; @@ -1408,9 +1408,10 @@ static void EraseLoanAmountsInClosedVaults(CCustomCSView &mnview) { for (const auto &vaultId : vaults) { const auto vault = mnview.GetVault(vaultId); if (!vault) { - mnview.EraseVaultLoanTokens(vaultId); + return true; } } + return false; } bool AppInitMain(InitInterfaces& interfaces) @@ -1774,7 +1775,10 @@ bool AppInitMain(InitInterfaces& interfaces) // Ensure we are on latest DB version pcustomcsview->SetDbVersion(CCustomCSView::DbVersion); - EraseLoanAmountsInClosedVaults(*pcustomcsview); + if (LoanAmountsInClosedVaults(*pcustomcsview)) { + strLoadError = "Corrupted block database detected. You will need to rebuild the database using -reindex-chainstate."; + break; + } // make account history db paccountHistoryDB.reset(); diff --git a/src/masternodes/loan.cpp b/src/masternodes/loan.cpp index 452f5b6de1..beca57c2b2 100644 --- a/src/masternodes/loan.cpp +++ b/src/masternodes/loan.cpp @@ -552,10 +552,6 @@ Res CLoanView::SubLoanToken(const CVaultId &vaultId, CTokenAmount amount) { return Res::Ok(); } -void CLoanView::EraseVaultLoanTokens(const CVaultId &vaultId) { - EraseBy(vaultId); -} - std::optional CLoanView::GetLoanTokens(const CVaultId &vaultId) { return ReadBy(vaultId); } diff --git a/src/masternodes/loan.h b/src/masternodes/loan.h index ea495ef71b..0aa17cae44 100644 --- a/src/masternodes/loan.h +++ b/src/masternodes/loan.h @@ -470,7 +470,6 @@ class CLoanView : public virtual CStorageView { Res AddLoanToken(const CVaultId &vaultId, CTokenAmount amount); Res SubLoanToken(const CVaultId &vaultId, CTokenAmount amount); - void EraseVaultLoanTokens(const CVaultId &vaultId); std::optional GetLoanTokens(const CVaultId &vaultId); void ForEachLoanTokenAmount(std::function callback);