Skip to content

Commit

Permalink
Throw error on invalid state
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Feb 7, 2023
1 parent ad7a206 commit b1b99c5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ void SetupInterrupts() {
fStopOrInterrupt = isSet;
}

static void EraseLoanAmountsInClosedVaults(CCustomCSView &mnview) {
static bool LoanAmountsInClosedVaults(CCustomCSView &mnview) {
LOCK(cs_main);

std::set<CVaultId> vaults;
Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions src/masternodes/loan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,6 @@ Res CLoanView::SubLoanToken(const CVaultId &vaultId, CTokenAmount amount) {
return Res::Ok();
}

void CLoanView::EraseVaultLoanTokens(const CVaultId &vaultId) {
EraseBy<LoanTokenAmount>(vaultId);
}

std::optional<CBalances> CLoanView::GetLoanTokens(const CVaultId &vaultId) {
return ReadBy<LoanTokenAmount, CBalances>(vaultId);
}
Expand Down
1 change: 0 additions & 1 deletion src/masternodes/loan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CBalances> GetLoanTokens(const CVaultId &vaultId);
void ForEachLoanTokenAmount(std::function<bool(const CVaultId &, const CBalances &)> callback);

Expand Down

0 comments on commit b1b99c5

Please sign in to comment.