From 95fdbe520f71b8412ed2fc03f4cd0891e74a223f Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Wed, 5 Nov 2025 12:45:31 -0500 Subject: [PATCH] Partially revert aed8e2b166 Fill in payment computation shortages (#5941) - Do not attempt to fill in payment computation shortages. Fixes, tests, and optimizations are left intact. --- src/test/app/Loan_test.cpp | 6 ++++++ src/xrpld/app/misc/detail/LendingHelpers.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/test/app/Loan_test.cpp b/src/test/app/Loan_test.cpp index cddfb0135a..157873872f 100644 --- a/src/test/app/Loan_test.cpp +++ b/src/test/app/Loan_test.cpp @@ -1999,6 +1999,7 @@ protected: state.paymentRemaining, broker.params.managementFeeRate); +#if LOANFILLSHORTAGE BEAST_EXPECT( paymentComponents.trackedValueDelta == roundedPeriodicPayment || @@ -2006,6 +2007,11 @@ protected: detail::PaymentSpecialCase::final && paymentComponents.trackedValueDelta < roundedPeriodicPayment)); +#else + BEAST_EXPECT( + paymentComponents.trackedValueDelta <= + roundedPeriodicPayment); +#endif ripple::LoanState const nextTrueState = calculateRawLoanState( diff --git a/src/xrpld/app/misc/detail/LendingHelpers.cpp b/src/xrpld/app/misc/detail/LendingHelpers.cpp index 99a1d619b1..08683632a6 100644 --- a/src/xrpld/app/misc/detail/LendingHelpers.cpp +++ b/src/xrpld/app/misc/detail/LendingHelpers.cpp @@ -1208,6 +1208,7 @@ computePaymentComponents( "ripple::detail::computePaymentComponents", "excess non-negative"); }; +#if LOANFILLSHORTAGE auto giveTo = [](Number& component, Number& shortage, Number const& maximum) { if (shortage > beast::zero) @@ -1225,12 +1226,14 @@ computePaymentComponents( "ripple::detail::computePaymentComponents", "excess non-negative"); }; +#endif auto addressExcess = [&takeFrom](LoanDeltas& deltas, Number& excess) { // This order is based on where errors are the least problematic takeFrom(deltas.interestDueDelta, excess); takeFrom(deltas.managementFeeDueDelta, excess); takeFrom(deltas.principalDelta, excess); }; +#if LOANFILLSHORTAGE auto addressShortage = [&giveTo]( LoanDeltas& deltas, Number& shortage, @@ -1240,6 +1243,7 @@ computePaymentComponents( giveTo( deltas.managementFeeDueDelta, shortage, current.managementFeeDue); }; +#endif Number totalOverpayment = deltas.valueDelta() - currentLedgerState.valueOutstanding; if (totalOverpayment > beast::zero) @@ -1268,6 +1272,7 @@ computePaymentComponents( shortage = -excess; } +#if LOANFILLSHORTAGE else if (shortage > beast::zero && totalOverpayment < beast::zero) { // If there's a shortage, and there's room in the loan itself, we can @@ -1285,6 +1290,16 @@ computePaymentComponents( shortage == beast::zero, "ripple::detail::computePaymentComponents", "no shortage or excess"); +#else + // The shortage should never be negative, which indicates that the + // parts are trying to take more than the whole payment. The + // shortage may be positive, which indicates that we're not going to + // take the whole payment amount. + XRPL_ASSERT_PARTS( + shortage >= beast::zero, + "ripple::detail::computePaymentComponents", + "no shortage or excess"); +#endif #if LOANCOMPLETE /* // This used to be part of the above assert. It will eventually be removed