Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart: Check collateral valid before usage #3047

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2887,8 +2887,8 @@ static Res PaybackWithSwappedCollateral(const DCT_ID &collId,
std::vector<CollToLoan> collToLoans;
// collect all loanValues (in USD) of vaults which contain this collateral
cache.ForEachLoanTokenAmount([&](const CVaultId &vaultId, const CBalances &balances) {
auto colls = cache.GetVaultCollaterals(vaultId);
if (colls->balances.count(collId)) {
const auto colls = cache.GetVaultCollaterals(vaultId);
if (colls && colls->balances.count(collId)) {
collToLoans.emplace_back(CollToLoan{vaultId, {}, 0});
collToLoans.back().useableCollateralAmount = colls->balances.at(collId);
for (const auto &[tokenId, amount] : balances.balances) {
Expand Down Expand Up @@ -3304,6 +3304,9 @@ static Res ForceCloseAllLoans(const CBlockIndex *pindex, CCustomCSView &cache, B
std::set<DCT_ID> allUsedCollaterals;
cache.ForEachLoanTokenAmount([&](const CVaultId &vaultId, const CBalances &balances) {
auto colls = cache.GetVaultCollaterals(vaultId);
if (!colls) {
return true;
}
for (const auto &[collId, collAmount] : colls->balances) {
allUsedCollaterals.insert(collId);
}
Expand Down Expand Up @@ -3389,9 +3392,10 @@ static Res ForceCloseAllLoans(const CBlockIndex *pindex, CCustomCSView &cache, B
if (!gotLoan) {
return true;
}
auto colls = cache.GetVaultCollaterals(vaultId);
for (const auto &[collId, collAmount] : colls->balances) {
allUsedCollaterals.insert(collId);
if (const auto colls = cache.GetVaultCollaterals(vaultId)) {
for (const auto &[collId, collAmount] : colls->balances) {
allUsedCollaterals.insert(collId);
}
}
return true;
});
Expand All @@ -3416,10 +3420,11 @@ static Res ForceCloseAllLoans(const CBlockIndex *pindex, CCustomCSView &cache, B
for (const auto &loan : loanAmounts->balances) {
LogPrintf(" %s@%d\n", GetDecimalString(loan.second), loan.first.v);
}
const auto collAmounts = cache.GetVaultCollaterals(vaultId);
LogPrintf("%d collaterals: \n", collAmounts->balances.size());
for (const auto &loan : collAmounts->balances) {
LogPrintf(" %s@%d\n", GetDecimalString(loan.second), loan.first.v);
if (const auto collAmounts = cache.GetVaultCollaterals(vaultId)) {
LogPrintf("%d collaterals: \n", collAmounts->balances.size());
for (const auto &loan : collAmounts->balances) {
LogPrintf(" %s@%d\n", GetDecimalString(loan.second), loan.first.v);
}
Bushstar marked this conversation as resolved.
Show resolved Hide resolved
}
}
return true;
Expand Down
Loading