mirror of
https://github.com/XRPLF/rippled.git
synced 2026-01-11 02:05:22 +00:00
Fix some minor bugs in Lending Protocol (#6101)
- add nodiscard to unimpairLoan, and check result in LoanPay - add a check to verify that issuer exists - improve LoanManage error code for dust amounts
This commit is contained in:
@@ -589,7 +589,7 @@ protected:
|
||||
auto const unrealizedLoss = vaultSle->at(sfLossUnrealized) +
|
||||
state.totalValue - state.managementFeeOutstanding;
|
||||
|
||||
if (unrealizedLoss > assetsUnavailable)
|
||||
if (!BEAST_EXPECT(unrealizedLoss <= assetsUnavailable))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -287,6 +287,14 @@ LoanBrokerCoverClawback::preclaim(PreclaimContext const& ctx)
|
||||
// Check if the vault asset issuer has the correct flags
|
||||
auto const sleIssuer =
|
||||
ctx.view.read(keylet::account(vaultAsset.getIssuer()));
|
||||
if (!sleIssuer)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
JLOG(ctx.j.fatal()) << "Issuer account does not exist.";
|
||||
return tefBAD_LEDGER;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
return std::visit(
|
||||
[&]<typename T>(T const&) {
|
||||
return preclaimHelper<T>(ctx, *sleIssuer, clawAmount);
|
||||
|
||||
@@ -223,11 +223,13 @@ LoanManage::defaultLoan(
|
||||
}
|
||||
if (*vaultAvailableProxy > *vaultTotalProxy)
|
||||
{
|
||||
JLOG(j.warn()) << "Vault assets available must not be greater "
|
||||
"than assets outstanding. Available: "
|
||||
<< *vaultAvailableProxy
|
||||
<< ", Total: " << *vaultTotalProxy;
|
||||
return tecLIMIT_EXCEEDED;
|
||||
// LCOV_EXCL_START
|
||||
JLOG(j.fatal())
|
||||
<< "Vault assets available must not be greater "
|
||||
"than assets outstanding. Available: "
|
||||
<< *vaultAvailableProxy << ", Total: " << *vaultTotalProxy;
|
||||
return tecINTERNAL;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
// The loss has been realized
|
||||
@@ -329,7 +331,7 @@ LoanManage::impairLoan(
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
TER
|
||||
[[nodiscard]] TER
|
||||
LoanManage::unimpairLoan(
|
||||
ApplyView& view,
|
||||
SLE::ref loanSle,
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
|
||||
/** Helper function that might be needed by other transactors
|
||||
*/
|
||||
static TER
|
||||
[[nodiscard]] static TER
|
||||
unimpairLoan(
|
||||
ApplyView& view,
|
||||
SLE::ref loanSle,
|
||||
|
||||
@@ -305,7 +305,12 @@ LoanPay::doApply()
|
||||
// change will be discarded.
|
||||
if (loanSle->isFlag(lsfLoanImpaired))
|
||||
{
|
||||
LoanManage::unimpairLoan(view, loanSle, vaultSle, j_);
|
||||
if (auto const ret =
|
||||
LoanManage::unimpairLoan(view, loanSle, vaultSle, asset, j_))
|
||||
{
|
||||
JLOG(j_.fatal()) << "Failed to unimpair loan before payment.";
|
||||
return ret; // LCOV_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
LoanPaymentType const paymentType = [&tx]() {
|
||||
@@ -449,6 +454,10 @@ LoanPay::doApply()
|
||||
if (*assetsAvailableProxy > *assetsTotalProxy)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
JLOG(j_.fatal())
|
||||
<< "Vault assets available must not be greater "
|
||||
"than assets outstanding. Available: "
|
||||
<< *assetsAvailableProxy << ", Total: " << *assetsTotalProxy;
|
||||
return tecINTERNAL;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user