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);