mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Compare commits
27 Commits
ximinez/le
...
ximinez/le
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d41fabf48 | ||
|
|
5aab5de8cd | ||
|
|
89d17442e2 | ||
|
|
bb5585e34b | ||
|
|
8e4be94f4a | ||
|
|
1f3ded7116 | ||
|
|
aa1234199a | ||
|
|
abff92d52c | ||
|
|
da9a483b79 | ||
|
|
f447827474 | ||
|
|
b9ca539c49 | ||
|
|
19c72b30e4 | ||
|
|
07497322de | ||
|
|
3b1bc3d497 | ||
|
|
c58f5abcc9 | ||
|
|
4760885955 | ||
|
|
3249461379 | ||
|
|
11479cdf68 | ||
|
|
27af46b111 | ||
|
|
5e860ec749 | ||
|
|
4719e05d89 | ||
|
|
c8394eb52f | ||
|
|
5a3df22cea | ||
|
|
b44859ff15 | ||
|
|
fe8d931992 | ||
|
|
0008e2d1db | ||
|
|
060b6d3231 |
@@ -2738,8 +2738,12 @@ protected:
|
||||
broker.params.managementFeeRate);
|
||||
|
||||
BEAST_EXPECT(
|
||||
paymentComponents.trackedValueDelta <=
|
||||
roundedPeriodicPayment);
|
||||
paymentComponents.trackedValueDelta ==
|
||||
roundedPeriodicPayment ||
|
||||
(paymentComponents.specialCase ==
|
||||
detail::PaymentSpecialCase::final &&
|
||||
paymentComponents.trackedValueDelta <
|
||||
roundedPeriodicPayment));
|
||||
|
||||
ripple::LoanState const nextTrueState = computeRawLoanState(
|
||||
state.periodicPayment,
|
||||
|
||||
@@ -187,9 +187,9 @@ class Feature_test : public beast::unit_test::suite
|
||||
BEAST_EXPECTS(jrr[jss::status] == jss::success, "status");
|
||||
jrr.removeMember(jss::status);
|
||||
BEAST_EXPECT(jrr.size() == 1);
|
||||
BEAST_EXPECT(
|
||||
jrr.isMember("12523DF04B553A0B1AD74F42DDB741DE8DC06A03FC089A0EF197E"
|
||||
"2A87F1D8107"));
|
||||
BEAST_EXPECT(jrr.isMember(
|
||||
"740352F2412A9909880C23A559FCECEDA3BE2126FED62FC7660D6"
|
||||
"28A06927F11"));
|
||||
auto feature = *(jrr.begin());
|
||||
|
||||
BEAST_EXPECTS(feature[jss::name] == "fixAMMOverflowOffer", "name");
|
||||
|
||||
@@ -1075,6 +1075,23 @@ computePaymentComponents(
|
||||
"ripple::detail::computePaymentComponents",
|
||||
"excess non-negative");
|
||||
};
|
||||
auto giveTo =
|
||||
[](Number& component, Number& shortage, Number const& maximum) {
|
||||
if (shortage > beast::zero)
|
||||
{
|
||||
// Put as much of the shortage as we can into the provided part
|
||||
// and the total
|
||||
auto part = std::min(maximum - component, shortage);
|
||||
component += part;
|
||||
shortage -= part;
|
||||
}
|
||||
// If the shortage goes negative, we put too much, which should be
|
||||
// impossible
|
||||
XRPL_ASSERT_PARTS(
|
||||
shortage >= beast::zero,
|
||||
"ripple::detail::computePaymentComponents",
|
||||
"excess non-negative");
|
||||
};
|
||||
// Helper to reduce deltas when they collectively exceed a limit.
|
||||
// Order matters: we prefer to reduce interest first (most flexible),
|
||||
// then management fee, then principal (least flexible).
|
||||
@@ -1084,6 +1101,19 @@ computePaymentComponents(
|
||||
takeFrom(deltas.managementFee, excess);
|
||||
takeFrom(deltas.principal, excess);
|
||||
};
|
||||
// Helper to increase deltas when they collectively do not reach an
|
||||
// expected value.
|
||||
// Order matters: we prefer to increase interest first (most flexible),
|
||||
// then management fee, then principal (least flexible).
|
||||
auto addressShortage = [&giveTo](
|
||||
LoanDeltas& deltas,
|
||||
Number& shortage,
|
||||
LoanState const& current) {
|
||||
giveTo(deltas.interestDueDelta, shortage, current.interestDue);
|
||||
giveTo(
|
||||
deltas.managementFeeDueDelta, shortage, current.managementFeeDue);
|
||||
giveTo(deltas.principalDelta, shortage, current.principalOutstanding);
|
||||
};
|
||||
|
||||
// Check if deltas exceed the total outstanding value. This should never
|
||||
// happen due to earlier caps, but handle it defensively.
|
||||
@@ -1115,12 +1145,19 @@ computePaymentComponents(
|
||||
addressExcess(deltas, excess);
|
||||
shortage = -excess;
|
||||
}
|
||||
else if (shortage > beast::zero && totalOverpayment < beast::zero)
|
||||
{
|
||||
// If there's a shortage, and there's room in the loan itself, we can
|
||||
// top up the parts to make the payment correct.
|
||||
shortage = std::min(-totalOverpayment, shortage);
|
||||
addressShortage(deltas, shortage, currentLedgerState);
|
||||
}
|
||||
|
||||
// At this point, shortage >= 0 means we're paying less than the full
|
||||
// periodic payment (due to rounding or component caps).
|
||||
// shortage < 0 would mean we're trying to pay more than allowed (bug).
|
||||
// shortage < 0 means mean we're trying to pay more than allowed (bug).
|
||||
XRPL_ASSERT_PARTS(
|
||||
shortage >= beast::zero,
|
||||
shortage == beast::zero,
|
||||
"ripple::detail::computePaymentComponents",
|
||||
"no shortage or excess");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user