diff --git a/include/xrpl/basics/Number.h b/include/xrpl/basics/Number.h index 05dd42bc26..93bef82a8c 100644 --- a/include/xrpl/basics/Number.h +++ b/include/xrpl/basics/Number.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -408,7 +407,6 @@ public: return !(x == y); } -#if 0 friend constexpr bool operator<(Number const& x, Number const& y) noexcept { @@ -438,7 +436,6 @@ public: // If equal exponents, compare mantissas return x.mantissa_ < y.mantissa_; } -#endif /** Return the sign of the amount */ [[nodiscard]] constexpr int @@ -452,7 +449,6 @@ public: [[nodiscard]] Number truncate() const noexcept; -#if 0 friend constexpr bool operator>(Number const& x, Number const& y) noexcept { @@ -470,7 +466,6 @@ public: { return !(x < y); } -#endif friend std::ostream& operator<<(std::ostream& os, Number const& x) @@ -820,7 +815,7 @@ Number::normalizeToRange() const constexpr Number abs(Number x) noexcept { - if (x < beast::kZero) + if (x < Number{}) x = -x; return x; } @@ -851,10 +846,8 @@ power(Number const& f, unsigned n, unsigned d); constexpr Number squelch(Number const& x, Number const& limit) noexcept { -#if 0 if (abs(x) < limit) return Number{}; -#endif return x; } diff --git a/include/xrpl/ledger/helpers/AMMHelpers.h b/include/xrpl/ledger/helpers/AMMHelpers.h index 9b566a43ae..61d6e9d2fb 100644 --- a/include/xrpl/ledger/helpers/AMMHelpers.h +++ b/include/xrpl/ledger/helpers/AMMHelpers.h @@ -113,15 +113,11 @@ withinRelativeDistance(Quality const& calcQuality, Quality const& reqQuality, Nu { if (calcQuality == reqQuality) return true; -#if 0 auto const [min, max] = std::minmax(calcQuality, reqQuality); // Relative distance is (max - min)/max. Can't use basic operations // on Quality. Have to use Quality::rate() instead, which // is inverse of quality: (1/max.rate - 1/min.rate)/(1/max.rate) return ((min.rate() - max.rate()) / min.rate()) < dist; -#else - return false; -#endif } /** Check if the relative distance between the amounts @@ -141,12 +137,8 @@ withinRelativeDistance(Amt const& calc, Amt const& req, Number const& dist) { if (calc == req) return true; -#if 0 auto const [min, max] = std::minmax(calc, req); return ((max - min) / max) < dist; -#else - return false; -#endif } /** Solve quadratic equation to find takerGets or takerPays. Round @@ -195,18 +187,16 @@ getAMMOfferStartWithTakerGets( auto const c = pool.out * pool.out - (pool.in * pool.out) / targetQuality.rate(); auto nTakerGets = solveQuadraticEqSmallest(a, b, c); - if (!nTakerGets || *nTakerGets <= beast::kZero) + if (!nTakerGets || *nTakerGets <= 0) return std::nullopt; // LCOV_EXCL_LINE auto const nTakerGetsConstraint = pool.out - pool.in / (targetQuality.rate() * f); - if (nTakerGetsConstraint <= beast::kZero) + if (nTakerGetsConstraint <= 0) return std::nullopt; -// Select the smallest to maximize the quality -#if 0 + // Select the smallest to maximize the quality if (nTakerGetsConstraint < *nTakerGets) nTakerGets = nTakerGetsConstraint; -#endif auto getAmounts = [&pool, &tfee](Number const& nTakerGetsProposed) { // Round downward to minimize the offer and to maximize the quality. @@ -264,18 +254,16 @@ getAMMOfferStartWithTakerPays( auto const c = pool.in * pool.in - pool.in * pool.out * targetQuality.rate(); auto nTakerPays = solveQuadraticEqSmallest(a, b, c); - if (!nTakerPays || *nTakerPays <= beast::kZero) + if (!nTakerPays || nTakerPays <= 0) return std::nullopt; // LCOV_EXCL_LINE auto const nTakerPaysConstraint = pool.out * targetQuality.rate() - pool.in / f; - if (nTakerPaysConstraint <= beast::kZero) + if (nTakerPaysConstraint <= 0) return std::nullopt; -#if 0 // Select the smallest to maximize the quality if (nTakerPaysConstraint < *nTakerPays) nTakerPays = nTakerPaysConstraint; -#endif auto getAmounts = [&pool, &tfee](Number const& nTakerPaysProposed) { // Round downward to minimize the offer and to maximize the quality. @@ -331,26 +319,23 @@ changeSpotPriceQuality( auto const b = pool.in * (1 + f); Number const c = pool.in * pool.in - pool.in * pool.out * quality.rate(); auto const res = b * b - 4 * a * c; - if (res < beast::kZero) + if (res < 0) { return std::nullopt; // LCOV_EXCL_LINE } - if (auto const nTakerPaysPropose = (-b + root2(res)) / (2 * a); - nTakerPaysPropose > beast::kZero) + if (auto const nTakerPaysPropose = (-b + root2(res)) / (2 * a); nTakerPaysPropose > 0) { auto const nTakerPays = [&]() { -// The fee might make the AMM offer quality less than CLOB -// quality. Therefore, AMM offer has to satisfy this constraint: -// o / i >= q. Substituting o with swapAssetIn() gives: i <= O / -// q - I / (1 - fee). -#if 0 + // The fee might make the AMM offer quality less than CLOB + // quality. Therefore, AMM offer has to satisfy this constraint: + // o / i >= q. Substituting o with swapAssetIn() gives: i <= O / + // q - I / (1 - fee). auto const nTakerPaysConstraint = pool.out * quality.rate() - pool.in / f; if (nTakerPaysPropose > nTakerPaysConstraint) return nTakerPaysConstraint; -#endif return nTakerPaysPropose; }(); - if (nTakerPays <= beast::kZero) + if (nTakerPays <= 0) { JLOG(j.trace()) << "changeSpotPriceQuality calc failed: " << to_string(pool.in) << " " << to_string(pool.out) << " " << quality << " " << tfee; diff --git a/include/xrpl/protocol/IOUAmount.h b/include/xrpl/protocol/IOUAmount.h index d74fc55024..9e0fbe38eb 100644 --- a/include/xrpl/protocol/IOUAmount.h +++ b/include/xrpl/protocol/IOUAmount.h @@ -136,13 +136,11 @@ IOUAmount::operator==(IOUAmount const& other) const return exponent_ == other.exponent_ && mantissa_ == other.mantissa_; } -#if 0 inline bool IOUAmount::operator<(IOUAmount const& other) const { return Number{*this} < Number{other}; } -#endif inline IOUAmount:: operator bool() const noexcept diff --git a/include/xrpl/tx/invariants/VaultInvariant.h b/include/xrpl/tx/invariants/VaultInvariant.h index 5d0f8c29f0..2a9ffc8282 100644 --- a/include/xrpl/tx/invariants/VaultInvariant.h +++ b/include/xrpl/tx/invariants/VaultInvariant.h @@ -37,7 +37,7 @@ namespace xrpl { */ class ValidVault { - static constexpr beast::Zero kZero{}; + static constexpr Number kZero{}; struct Vault final { diff --git a/src/libxrpl/basics/Number.cpp b/src/libxrpl/basics/Number.cpp index f99cac9f60..275d82d8c9 100644 --- a/src/libxrpl/basics/Number.cpp +++ b/src/libxrpl/basics/Number.cpp @@ -1209,16 +1209,12 @@ root(Number f, unsigned d) { if (f == -one) return one; -#if 0 if (abs(f) < one) return kZero; -#endif throw std::overflow_error("Number::root infinity"); } -#if 0 if (f < kZero && d % 2 == 0) throw std::overflow_error("Number::root nan"); -#endif if (f == kZero) return f; @@ -1238,13 +1234,11 @@ root(Number f, unsigned d) XRPL_ASSERT_PARTS(f.isnormal(), "xrpl::root(Number, unsigned)", "f is normalized"); bool neg = false; -#if 0 if (f < kZero) { neg = true; f = -f; } -#endif // Quadratic least squares curve fit of f^(1/d) in the range [0, 1] auto const D = (((6 * di + 11) * di + 6) * di) + 1; // NOLINT(readability-identifier-naming) @@ -1283,10 +1277,8 @@ root2(Number f) if (f == one) return f; -#if 0 if (f < kZero) throw std::overflow_error("Number::root nan"); -#endif if (f == kZero) return f; @@ -1327,7 +1319,6 @@ root2(Number f) Number power(Number const& f, unsigned n, unsigned d) { - [[maybe_unused]] static constexpr Number kZero = Number{}; auto const one = Number::one(); @@ -1340,10 +1331,8 @@ power(Number const& f, unsigned n, unsigned d) { if (f == -one) return one; -#if 0 if (abs(f) < one) return kZero; -#endif // abs(f) > one throw std::overflow_error("Number::power infinity"); } @@ -1351,10 +1340,8 @@ power(Number const& f, unsigned n, unsigned d) return one; n /= g; d /= g; -#if 0 if ((n % 2) == 1 && (d % 2) == 0 && f < kZero) throw std::overflow_error("Number::power nan"); -#endif return root(power(f, n), d); } diff --git a/src/libxrpl/ledger/helpers/AMMHelpers.cpp b/src/libxrpl/ledger/helpers/AMMHelpers.cpp index 734cad2cc1..fe6d022490 100644 --- a/src/libxrpl/ledger/helpers/AMMHelpers.cpp +++ b/src/libxrpl/ledger/helpers/AMMHelpers.cpp @@ -276,11 +276,11 @@ std::optional solveQuadraticEqSmallest(Number const& a, Number const& b, Number const& c) { auto const d = b * b - 4 * a * c; - if (d < beast::kZero) + if (d < 0) return std::nullopt; // use numerically stable citardauq formula for quadratic equation solution // https://people.csail.mit.edu/bkph/articles/Quadratics.pdf - if (b > beast::kZero) + if (b > 0) { return (2 * c) / (-b - root2(d)); } diff --git a/src/libxrpl/ledger/helpers/LendingHelpers.cpp b/src/libxrpl/ledger/helpers/LendingHelpers.cpp index 4618206222..15ebf33e46 100644 --- a/src/libxrpl/ledger/helpers/LendingHelpers.cpp +++ b/src/libxrpl/ledger/helpers/LendingHelpers.cpp @@ -205,7 +205,6 @@ computePowerMinusOneHybrid(Number const& periodicRate, std::uint32_t paymentsRem if (paymentsRemaining == 0 || periodicRate == beast::kZero) return kNumZero; -#if 0 // Threshold 1e-9 retains ~10 sig digits of (1+r)^n - 1 against // Number's 19-digit mantissa: the leading "1" of (1+r)^n consumes // ~log10(1/(r*n)) digits before the subtraction. Above this point @@ -214,7 +213,6 @@ computePowerMinusOneHybrid(Number const& periodicRate, std::uint32_t paymentsRem Number const cancellationThreshold{1, -9}; if (paymentsRemaining * periodicRate >= cancellationThreshold) return power(1 + periodicRate, paymentsRemaining) - 1; -#endif return computePowerMinusOne(periodicRate, paymentsRemaining); } @@ -449,7 +447,6 @@ doPayment( prevPaymentDateProxy = nextDueDateProxy; nextDueDateProxy += paymentInterval; } -#if 0 XRPL_ASSERT_PARTS( principalOutstandingProxy > payment.trackedPrincipalDelta, "xrpl::detail::doPayment", @@ -464,7 +461,6 @@ doPayment( managementFeeOutstandingProxy >= payment.trackedManagementFeeDelta, "xrpl::detail::doPayment", "Valid management fee"); -#endif // Apply the payment deltas to reduce the outstanding balances principalOutstandingProxy -= payment.trackedPrincipalDelta; @@ -472,7 +468,6 @@ doPayment( managementFeeOutstandingProxy -= payment.trackedManagementFeeDelta; } -#if 0 // Principal can never exceed total value (principal is part of total value) XRPL_ASSERT_PARTS( // Use an explicit cast because the template parameter can be @@ -481,7 +476,6 @@ doPayment( static_cast(totalValueOutstandingProxy), "xrpl::detail::doPayment", "principal does not exceed total"); -#endif XRPL_ASSERT_PARTS( // Use an explicit cast because the template parameter can be @@ -543,16 +537,11 @@ tryOverpayment( // up with a different total value than what the borrower has actually paid. auto const errors = roundedOldState - theoreticalState; -#if 0 // Compute the new principal by applying the overpayment to the theoretical // principal. Use max with 0 to ensure we never go negative. auto const newTheoreticalPrincipal = std::max( theoreticalState.principalOutstanding - overpaymentComponents.trackedPrincipalDelta, Number{0}); -#else - auto const newTheoreticalPrincipal = - theoreticalState.principalOutstanding - overpaymentComponents.trackedPrincipalDelta; -#endif // Compute new loan properties based on the reduced principal. This // recalculates the periodic payment, total value, and management fees @@ -606,7 +595,6 @@ tryOverpayment( // Update the loan state variables with the new values that include the // preserved rounding errors. This ensures the loan's tracked state remains // consistent with its payment history. -#if 0 auto const principalOutstanding = std::clamp( roundToAsset( asset, @@ -627,17 +615,6 @@ tryOverpayment( roundToAsset(asset, newTheoreticalState.managementFeeDue, loanScale), kNumZero, roundedOldState.managementFeeDue); -#else - auto const principalOutstanding = roundToAsset( - asset, newTheoreticalState.principalOutstanding, loanScale, Number::RoundingMode::Upward); - auto const totalValueOutstanding = roundToAsset( - asset, - principalOutstanding + newTheoreticalState.interestOutstanding(), - loanScale, - Number::RoundingMode::Upward); - auto const managementFeeOutstanding = - roundToAsset(asset, newTheoreticalState.managementFeeDue, loanScale); -#endif auto const roundedNewState = constructLoanState(totalValueOutstanding, principalOutstanding, managementFeeOutstanding); @@ -669,7 +646,6 @@ tryOverpayment( return Unexpected(tesSUCCESS); } -#if 0 // Validate that all computed properties are reasonable. These checks should // never fail under normal circumstances, but we validate defensively. if (newLoanProperties.periodicPayment <= 0 || @@ -687,7 +663,6 @@ tryOverpayment( return Unexpected(tesSUCCESS); // LCOV_EXCL_STOP } -#endif auto const deltas = roundedOldState - roundedNewState; @@ -706,14 +681,12 @@ tryOverpayment( // We do not consider the change in management fee here, since // management fees are excluded from the valueOutstanding. auto const valueChange = -deltas.interest; -#if 0 if (valueChange > 0) { JLOG(j.warn()) << "Principal overpayment would increase the value of " "the loan. Ignore the overpayment"; return Unexpected(tesSUCCESS); } -#endif return std::make_pair( LoanPaymentParts{ @@ -918,9 +891,7 @@ computeLatePayment( return computeInterestAndFeeParts(asset, interest, managementFeeRate, loanScale); }(); -#if 0 XRPL_ASSERT(roundedLateInterest >= 0, "xrpl::detail::computeLatePayment : valid late interest"); -#endif XRPL_ASSERT_PARTS( periodic.specialCase != PaymentSpecialCase::Extra, "xrpl::detail::computeLatePayment", @@ -954,14 +925,12 @@ computeLatePayment( // Check that the borrower provided enough funds to cover the late payment. // The late payment is more expensive than a regular payment due to the // penalties. -#if 0 if (amount < late.totalDue) { JLOG(j.warn()) << "Late loan payment amount is insufficient. Due: " << late.totalDue << ", paid: " << amount; return Unexpected(tecINSUFFICIENT_PAYMENT); } -#endif return late; } @@ -1086,14 +1055,12 @@ computeFullPayment( << ", roundedFullManagementFee: " << roundedFullManagementFee << ", untrackedInterest: " << full.untrackedInterest; -#if 0 if (amount < full.totalDue) { // If the payment is less than the full payment amount, it's not // sufficient to be a full payment. return Unexpected(tecINSUFFICIENT_PAYMENT); } -#endif return full; } @@ -1148,11 +1115,7 @@ computePaymentComponents( // Final payment: pay off everything remaining, ignoring the normal // periodic payment amount. This ensures the loan completes cleanly. - if (paymentRemaining == 1 -#if 0 - || totalValueOutstanding <= roundedPeriodicPayment -#endif - ) + if (paymentRemaining == 1 || totalValueOutstanding <= roundedPeriodicPayment) { // If there's only one payment left, we need to pay off each of the loan // parts. @@ -1200,7 +1163,6 @@ computePaymentComponents( // Rounding can occasionally produce negative deltas. Zero them out. deltas.nonNegative(); -#if 0 XRPL_ASSERT_PARTS( deltas.principal <= currentLedgerState.principalOutstanding, "xrpl::detail::computePaymentComponents", @@ -1234,7 +1196,6 @@ computePaymentComponents( {deltas.managementFee, roundedPeriodicPayment - (deltas.principal + deltas.interest), currentLedgerState.managementFeeDue}); -#endif // The shortage must never be negative, which indicates that the parts are // trying to take more than the whole payment. The excess can be positive, @@ -1243,11 +1204,9 @@ computePaymentComponents( auto takeFrom = [](Number& component, Number& excess) { if (excess > beast::kZero) { -#if 0 auto part = std::min(component, excess); component -= part; excess -= part; -#endif } XRPL_ASSERT_PARTS( excess >= beast::kZero, @@ -1308,7 +1267,6 @@ computePaymentComponents( "xrpl::detail::computePaymentComponents", "total value adds up"); -#if 0 XRPL_ASSERT_PARTS( deltas.principal >= beast::kZero && deltas.principal <= currentLedgerState.principalOutstanding, @@ -1323,15 +1281,13 @@ computePaymentComponents( deltas.managementFee <= currentLedgerState.managementFeeDue, "xrpl::detail::computePaymentComponents", "valid fee result"); -#endif XRPL_ASSERT_PARTS( deltas.principal + deltas.interest + deltas.managementFee > beast::kZero, "xrpl::detail::computePaymentComponents", "payment parts add to payment"); -// Final safety clamp to ensure no value exceeds its outstanding balance -#if 0 + // Final safety clamp to ensure no value exceeds its outstanding balance return PaymentComponents{ .trackedValueDelta = std::clamp(deltas.total(), kNumZero, currentLedgerState.valueOutstanding), @@ -1340,13 +1296,6 @@ computePaymentComponents( .trackedManagementFeeDelta = std::clamp(deltas.managementFee, kNumZero, currentLedgerState.managementFeeDue), }; -#else - return PaymentComponents{ - .trackedValueDelta = deltas.total(), - .trackedPrincipalDelta = deltas.principal, - .trackedManagementFeeDelta = deltas.managementFee, - }; -#endif } /* Computes payment components for an overpayment scenario. @@ -1380,7 +1329,7 @@ computeOverpaymentComponents( if (rules.enabled(fixCleanup3_2_0)) { XRPL_ASSERT( - overpayment > beast::kZero && isRounded(asset, overpayment, loanScale), + overpayment > 0 && isRounded(asset, overpayment, loanScale), "xrpl::detail::computeOverpaymentComponents : valid overpayment " "amount"); } @@ -1480,7 +1429,7 @@ checkLoanGuards( // Guard 1: if there is no computed total interest over the life of the // loan for a non-zero interest rate, we cannot properly amortize the // loan - if (expectInterest && totalInterestOutstanding <= beast::kZero) + if (expectInterest && totalInterestOutstanding <= 0) { // Unless this is a zero-interest loan, there must be some interest // due on the loan, even if it's (measurable) dust @@ -1489,7 +1438,7 @@ checkLoanGuards( } // Guard 1a: If there is any interest computed over the life of the // loan, for a zero interest rate, something went sideways. - if (!expectInterest && totalInterestOutstanding > beast::kZero) + if (!expectInterest && totalInterestOutstanding > 0) { // LCOV_EXCL_START JLOG(j.warn()) << "Loan for " << principalRequested << " with no interest has interest due"; @@ -1500,7 +1449,7 @@ checkLoanGuards( // Guard 2: if the principal portion of the first periodic payment is // too small to be accurately represented with the given rounding mode, // raise an error - if (properties.firstPaymentPrincipal <= beast::kZero) + if (properties.firstPaymentPrincipal <= 0) { // Check that some true (unrounded) principal is paid each period. // Since the first payment pays the least principal, if it's good, @@ -1568,7 +1517,7 @@ computeFullPaymentInterest( prevPaymentDate, paymentInterval); XRPL_ASSERT( - accruedInterest >= beast::kZero, + accruedInterest >= 0, "xrpl::detail::computeFullPaymentInterest : valid accrued " "interest"); @@ -1578,7 +1527,7 @@ computeFullPaymentInterest( : tenthBipsOfValue(theoreticalPrincipalOutstanding, closeInterestRate); XRPL_ASSERT( - prepaymentPenalty >= beast::kZero, + prepaymentPenalty >= 0, "xrpl::detail::computeFullPaymentInterest : valid prepayment " "interest"); @@ -1730,9 +1679,7 @@ computeLoanProperties( std::int32_t minimumScale) { auto const periodicRate = loanPeriodicRate(interestRate, paymentInterval); - XRPL_ASSERT( - interestRate == 0 || periodicRate > beast::kZero, - "xrpl::computeLoanProperties : valid rate"); + XRPL_ASSERT(interestRate == 0 || periodicRate > 0, "xrpl::computeLoanProperties : valid rate"); return computeLoanProperties( rules, asset, @@ -1887,11 +1834,9 @@ loanMakePayment( // Compute the periodic rate that will be used for calculations // throughout Number const periodicRate = loanPeriodicRate(interestRate, paymentInterval); - XRPL_ASSERT( - interestRate == 0 || periodicRate > beast::kZero, "xrpl::loanMakePayment : valid rate"); + XRPL_ASSERT(interestRate == 0 || periodicRate > 0, "xrpl::loanMakePayment : valid rate"); - XRPL_ASSERT( - *totalValueOutstandingProxy > beast::kZero, "xrpl::loanMakePayment : valid total value"); + XRPL_ASSERT(*totalValueOutstandingProxy > 0, "xrpl::loanMakePayment : valid total value"); view.update(loan); @@ -1984,7 +1929,7 @@ loanMakePayment( managementFeeRate), serviceFee}; XRPL_ASSERT_PARTS( - periodic.trackedPrincipalDelta >= beast::kZero, + periodic.trackedPrincipalDelta >= 0, "xrpl::loanMakePayment", "regular payment valid principal"); @@ -2048,13 +1993,12 @@ loanMakePayment( Number totalPaid; std::size_t numPayments = 0; -#if 0 - while ((amount >= (totalPaid + periodic.totalDue)) && paymentRemainingProxy > beast::kZero && + while ((amount >= (totalPaid + periodic.totalDue)) && paymentRemainingProxy > 0 && numPayments < kLoanMaximumPaymentsPerTransaction) { // Try to make more payments XRPL_ASSERT_PARTS( - periodic.trackedPrincipalDelta >= beast::kZero, + periodic.trackedPrincipalDelta >= 0, "xrpl::loanMakePayment", "payment pays non-negative principal"); @@ -2094,7 +2038,6 @@ loanMakePayment( managementFeeRate), serviceFee}; } -#endif if (numPayments == 0) { @@ -2109,16 +2052,15 @@ loanMakePayment( "payment parts add up"); XRPL_ASSERT_PARTS(totalParts.valueChange == 0, "xrpl::loanMakePayment", "no value change"); -// ------------------------------------------------------------- -// overpayment handling -// -// If the "fixCleanup3_1_3" amendment is enabled, truncate "amount", -// at the loan scale. If the raw value is used, the overpayment -// amount could be meaningless dust. Trying to process such a small -// amount will, at best, waste time when all the result values round -// to zero. At worst, it can cause logical errors with tiny amounts -// of interest that don't add up correctly. -#if 0 + // ------------------------------------------------------------- + // overpayment handling + // + // If the "fixCleanup3_1_3" amendment is enabled, truncate "amount", + // at the loan scale. If the raw value is used, the overpayment + // amount could be meaningless dust. Trying to process such a small + // amount will, at best, waste time when all the result values round + // to zero. At worst, it can cause logical errors with tiny amounts + // of interest that don't add up correctly. auto const roundedAmount = view.rules().enabled(fixCleanup3_1_3) ? roundToAsset(asset, amount, loanScale, Number::RoundingMode::TowardsZero) : amount; @@ -2192,7 +2134,6 @@ loanMakePayment( } } } -#endif // Check the final results are rounded, to double-check that the // intermediate steps were rounded. diff --git a/src/libxrpl/protocol/QualityFunction.cpp b/src/libxrpl/protocol/QualityFunction.cpp index 2b3222f7ed..e862770406 100644 --- a/src/libxrpl/protocol/QualityFunction.cpp +++ b/src/libxrpl/protocol/QualityFunction.cpp @@ -34,7 +34,7 @@ QualityFunction::outFromAvgQ(Quality const& quality) { SaveNumberRoundMode const rm(Number::setround(Number::RoundingMode::Upward)); auto const out = (1 / quality.rate() - b_) / m_; - if (out <= beast::kZero) + if (out <= 0) return std::nullopt; return out; } diff --git a/src/libxrpl/tx/invariants/AMMInvariant.cpp b/src/libxrpl/tx/invariants/AMMInvariant.cpp index 809fbdc27f..ecd7bedf89 100644 --- a/src/libxrpl/tx/invariants/AMMInvariant.cpp +++ b/src/libxrpl/tx/invariants/AMMInvariant.cpp @@ -214,11 +214,10 @@ ValidAMM::generalInvariant( FreezeHandling::IgnoreFreeze, AuthHandling::IgnoreAuth, j); -// Deposit and Withdrawal invariant: -// sqrt(amount * amount2) >= LPTokens -// all balances are greater than zero -// unless on last withdrawal -#if 0 + // Deposit and Withdrawal invariant: + // sqrt(amount * amount2) >= LPTokens + // all balances are greater than zero + // unless on last withdrawal auto const poolProductMean = root2(amount * amount2); bool const nonNegativeBalances = validBalances(amount, amount2, *lptAMMBalanceAfter_, zeroAllowed); @@ -239,7 +238,6 @@ ValidAMM::generalInvariant( : ((*lptAMMBalanceAfter_ - poolProductMean) / poolProductMean)); return false; } -#endif // NOLINTEND(bugprone-unchecked-optional-access) return true; diff --git a/src/libxrpl/tx/invariants/LoanBrokerInvariant.cpp b/src/libxrpl/tx/invariants/LoanBrokerInvariant.cpp index 08ed728592..8586a27be3 100644 --- a/src/libxrpl/tx/invariants/LoanBrokerInvariant.cpp +++ b/src/libxrpl/tx/invariants/LoanBrokerInvariant.cpp @@ -161,12 +161,12 @@ ValidLoanBroker::finalize( "decreased"; return false; } - if (after->at(sfDebtTotal) < beast::kZero) + if (after->at(sfDebtTotal) < 0) { JLOG(j.fatal()) << "Invariant failed: Loan Broker debt total is negative"; return false; } - if (after->at(sfCoverAvailable) < beast::kZero) + if (after->at(sfCoverAvailable) < 0) { JLOG(j.fatal()) << "Invariant failed: Loan Broker cover available is negative"; return false; @@ -185,16 +185,13 @@ ValidLoanBroker::finalize( FreezeHandling::IgnoreFreeze, AuthHandling::IgnoreAuth, j); -#if 0 if (after->at(sfCoverAvailable) < pseudoBalance) { JLOG(j.fatal()) << "Invariant failed: Loan Broker cover available " "is less than pseudo-account asset balance"; return false; } -#endif -#if 0 if (view.rules().enabled(fixCleanup3_1_3)) { // Don't check the balance when LoanBroker is deleted, @@ -207,7 +204,6 @@ ValidLoanBroker::finalize( return false; } } -#endif } return true; } diff --git a/src/libxrpl/tx/invariants/LoanInvariant.cpp b/src/libxrpl/tx/invariants/LoanInvariant.cpp index de01a1aeb7..ce9a7c6e03 100644 --- a/src/libxrpl/tx/invariants/LoanInvariant.cpp +++ b/src/libxrpl/tx/invariants/LoanInvariant.cpp @@ -71,7 +71,7 @@ ValidLoan::finalize( &sfTotalValueOutstanding, &sfManagementFeeOutstanding}) { - if (after->at(*field) < beast::kZero) + if (after->at(*field) < 0) { JLOG(j.fatal()) << "Invariant failed: " << field->getName() << " is negative "; return false; @@ -82,7 +82,7 @@ ValidLoan::finalize( &sfPeriodicPayment, }) { - if (after->at(*field) <= beast::kZero) + if (after->at(*field) <= 0) { JLOG(j.fatal()) << "Invariant failed: " << field->getName() << " is zero or negative "; diff --git a/src/libxrpl/tx/invariants/VaultInvariant.cpp b/src/libxrpl/tx/invariants/VaultInvariant.cpp index d91b1e7545..80b8f36bd9 100644 --- a/src/libxrpl/tx/invariants/VaultInvariant.cpp +++ b/src/libxrpl/tx/invariants/VaultInvariant.cpp @@ -466,7 +466,6 @@ ValidVault::finalize( result = false; } -#if 0 if (afterVault.assetsAvailable > afterVault.assetsTotal) { JLOG(j.fatal()) << "Invariant failed: assets available must " @@ -480,7 +479,6 @@ ValidVault::finalize( "the difference between assets outstanding and available"; result = false; } -#endif if (afterVault.assetsTotal < kZero) { @@ -624,7 +622,6 @@ ValidVault::finalize( result = false; } -#if 0 if (afterVault.assetsMaximum > kZero && afterVault.assetsTotal > afterVault.assetsMaximum) { @@ -633,7 +630,6 @@ ValidVault::finalize( "exceed assets maximum"; result = false; } -#endif if (beforeVault.assetsAvailable != afterVault.assetsAvailable) { @@ -674,7 +670,6 @@ ValidVault::finalize( auto const vaultDeltaAssets = roundToAsset(vaultAsset, maybeVaultDeltaAssets->delta, minScale); -#if 0 auto const txAmount = roundToAsset(vaultAsset, tx[sfAmount], minScale); if (vaultDeltaAssets > txAmount) @@ -684,7 +679,6 @@ ValidVault::finalize( "balance by more than deposited amount"; result = false; } -#endif if (vaultDeltaAssets <= kZero) { @@ -736,7 +730,6 @@ ValidVault::finalize( } } -#if 0 if (afterVault.assetsMaximum > kZero && afterVault.assetsTotal > afterVault.assetsMaximum) { @@ -744,7 +737,6 @@ ValidVault::finalize( "deposit assets outstanding must not exceed assets maximum"; result = false; } -#endif auto const maybeAccDeltaShares = deltaShares(tx[sfAccount]); if (!maybeAccDeltaShares) diff --git a/src/libxrpl/tx/paths/AMMOffer.cpp b/src/libxrpl/tx/paths/AMMOffer.cpp index a262439c3e..3a7bd8f1df 100644 --- a/src/libxrpl/tx/paths/AMMOffer.cpp +++ b/src/libxrpl/tx/paths/AMMOffer.cpp @@ -146,10 +146,8 @@ AMMOffer::checkInvariant(TAmounts const& consumed, beast:: TAmounts{balances_.in + consumed.in, balances_.out - consumed.out}; Number const newProduct = newBalances.in * newBalances.out; -#if 0 if (newProduct >= product || withinRelativeDistance(product, newProduct, Number{1, -7})) return true; -#endif JLOG(j.error()) << "AMMOffer::checkInvariant failed: balances " << to_string(balances_.in) << " " << to_string(balances_.out) << " new balances " diff --git a/src/libxrpl/tx/paths/MPTEndpointStep.cpp b/src/libxrpl/tx/paths/MPTEndpointStep.cpp index f3e16778b2..7dcd6d9241 100644 --- a/src/libxrpl/tx/paths/MPTEndpointStep.cpp +++ b/src/libxrpl/tx/paths/MPTEndpointStep.cpp @@ -567,7 +567,6 @@ MPTEndpointStep::setCacheLimiting( auto const diff = fwdIn - cache_->in; if (diff > smallDiff) { -#if 0 if (!cache_->in.value() || (Number(fwdIn.value()) / Number(cache_->in.value())) > Number(101, -2)) { @@ -583,7 +582,6 @@ MPTEndpointStep::setCacheLimiting( cache_.emplace(fwdIn, fwdSrcToDst, fwdOut, srcDebtDir); return; } -#endif } } cache_->in = fwdIn; diff --git a/src/libxrpl/tx/paths/OfferStream.cpp b/src/libxrpl/tx/paths/OfferStream.cpp index cebcc042d1..b7defb4df8 100644 --- a/src/libxrpl/tx/paths/OfferStream.cpp +++ b/src/libxrpl/tx/paths/OfferStream.cpp @@ -157,10 +157,8 @@ TOfferStreamBase::shouldRmSmallIncreasedQOffer() const if constexpr (!kInIsXrp && !kOutIsXrp) { -#if 0 if (Number(ofrAmts.in) >= Number(ofrAmts.out)) return false; -#endif } TTakerGets const ownerFunds = toAmount(*ownerFunds_); diff --git a/src/libxrpl/tx/paths/PaySteps.cpp b/src/libxrpl/tx/paths/PaySteps.cpp index 3a0b3f37b7..0a5adeb77f 100644 --- a/src/libxrpl/tx/paths/PaySteps.cpp +++ b/src/libxrpl/tx/paths/PaySteps.cpp @@ -36,10 +36,8 @@ bool checkNear(IOUAmount const& expected, IOUAmount const& actual) { double const ratTol = 0.001; -#if 0 if (abs(expected.exponent() - actual.exponent()) > 1) return false; -#endif if (actual.exponent() < -20) return true; diff --git a/src/libxrpl/tx/transactors/dex/AMMBid.cpp b/src/libxrpl/tx/transactors/dex/AMMBid.cpp index a8f2f06303..a98f439d0a 100644 --- a/src/libxrpl/tx/transactors/dex/AMMBid.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMBid.cpp @@ -271,27 +271,21 @@ applyBid(ApplyContext& ctx, Sandbox& sb, AccountID const& account, beast::Journa // Both min/max bid price are defined if (bidMin && bidMax) { -#if 0 if (computedPrice <= *bidMax) return std::max(computedPrice, Number(*bidMin)); -#endif JLOG(ctx.journal.debug()) << "AMM Bid: not in range " << computedPrice << " " << *bidMin << " " << *bidMax; return std::nullopt; } -// Bidder pays max(bidPrice, computedPrice) -#if 0 + // Bidder pays max(bidPrice, computedPrice) if (bidMin) { return std::max(computedPrice, Number(*bidMin)); } -#endif if (bidMax) { -#if 0 if (computedPrice <= *bidMax) return computedPrice; -#endif JLOG(ctx.journal.debug()) << "AMM Bid: not in range " << computedPrice << " " << *bidMax; return std::nullopt; @@ -303,12 +297,10 @@ applyBid(ApplyContext& ctx, Sandbox& sb, AccountID const& account, beast::Journa { return Unexpected(tecAMM_FAILED); } -#if 0 if (payPrice > lpTokens) { return Unexpected(tecAMM_INVALID_TOKENS); } -#endif return *payPrice; }; @@ -349,7 +341,6 @@ applyBid(ApplyContext& ctx, Sandbox& sb, AccountID const& account, beast::Journa // Refund the previous owner. If the time slot is 0 then // the owner is refunded 95% of the amount. auto const refund = fractionRemaining * pricePurchased; -#if 0 if (refund > *payPrice) { // This error case should never occur. @@ -357,7 +348,6 @@ applyBid(ApplyContext& ctx, Sandbox& sb, AccountID const& account, beast::Journa << "AMM Bid: refund exceeds payPrice " << refund << " " << *payPrice; return {tecINTERNAL, false}; } -#endif res = accountSend( sb, account, auctionSlot[sfAccount], toSTAmount(lpTokens.asset(), refund), ctx.journal); if (!isTesSuccess(res)) diff --git a/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp b/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp index b0355a370b..91858e3cd7 100644 --- a/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp @@ -917,7 +917,6 @@ AMMDeposit::singleDepositEPrice( adjustAssetInByTokens(view.rules(), amountBalance, amount, lptAMMBalance, tokens, tfee); if (view.rules().enabled(fixAMMv1_3) && tokensAdj == beast::kZero) return {tecAMM_INVALID_TOKENS, STAmount{}}; // LCOV_EXCL_LINE -#if 0 auto const ep = Number{amountDepositAdj} / tokensAdj; if (ep <= ePrice) { @@ -934,7 +933,6 @@ AMMDeposit::singleDepositEPrice( std::nullopt, tfee); } -#endif } // LPTokens is asset out => E = b / t diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp index 2304510575..0e1a4b3a3d 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp @@ -190,10 +190,8 @@ determineClawAmount( if (!amount || *amount == beast::kZero) return STAmount{vaultAsset, maxClawAmount}; Number const magnitude{*amount}; -#if 0 if (magnitude > maxClawAmount) return STAmount{vaultAsset, maxClawAmount}; -#endif return STAmount{vaultAsset, magnitude}; } diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp index ba47c1b3b2..fea6f3b9cb 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp @@ -136,7 +136,6 @@ LoanBrokerCoverWithdraw::preclaim(PreclaimContext const& ctx) return ret; } -#if 0 auto const coverAvail = sleBroker->at(sfCoverAvailable); // Cover Rate is in 1/10 bips units auto const currentDebtTotal = sleBroker->at(sfDebtTotal); @@ -159,7 +158,6 @@ LoanBrokerCoverWithdraw::preclaim(PreclaimContext const& ctx) return tecINSUFFICIENT_FUNDS; if ((coverAvail - amount) < minimumCover) return tecINSUFFICIENT_FUNDS; -#endif if (accountHolds( ctx.view, diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp index da75136b94..2dc003eb7f 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp @@ -46,10 +46,8 @@ LoanBrokerSet::preflight(PreflightContext const& ctx) return temINVALID; if (!validNumericRange(tx[~sfCoverRateLiquidation], kMaxCoverRate)) return temINVALID; -#if 0 if (!validNumericRange(tx[~sfDebtMaximum], Number(kMaxMpTokenAmount), Number(0))) return temINVALID; -#endif if (tx.isFieldPresent(sfLoanBrokerID)) { @@ -135,15 +133,13 @@ LoanBrokerSet::preclaim(PreclaimContext const& ctx) if (auto const debtMax = tx[~sfDebtMaximum]) { -// Can't reduce the debt maximum below the current total debt -#if 0 + // Can't reduce the debt maximum below the current total debt auto const currentDebtTotal = sleBroker->at(sfDebtTotal); if (*debtMax != 0 && *debtMax < currentDebtTotal) { JLOG(ctx.j.warn()) << "Cannot reduce DebtMaximum below current DebtTotal."; return tecLIMIT_EXCEEDED; } -#endif } } else diff --git a/src/libxrpl/tx/transactors/lending/LoanManage.cpp b/src/libxrpl/tx/transactors/lending/LoanManage.cpp index 615e0857d3..2b5c9d25f6 100644 --- a/src/libxrpl/tx/transactors/lending/LoanManage.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanManage.cpp @@ -170,26 +170,16 @@ LoanManage::defaultLoan( // Round the liquidation amount up, too auto const covered = roundToAsset( vaultAsset, -/* - * This formula is from the XLS-66 spec, section 3.2.3.2 (State - * Changes), specifically "if the `tfLoanDefault` flag is set" / - * "Apply the First-Loss Capital to the Default Amount" - */ -#if 0 - std::min( - tenthBipsOfValue(minimumCover, coverRateLiquidation) - , totalDefaultAmount), -#else - tenthBipsOfValue(minimumCover, coverRateLiquidation), -#endif + /* + * This formula is from the XLS-66 spec, section 3.2.3.2 (State + * Changes), specifically "if the `tfLoanDefault` flag is set" / + * "Apply the First-Loss Capital to the Default Amount" + */ + std::min(tenthBipsOfValue(minimumCover, coverRateLiquidation), totalDefaultAmount), loanScale); -#if 0 auto const coverAvailable = *brokerSle->at(sfCoverAvailable); return std::min(covered, coverAvailable); -#else - return covered; -#endif }(); auto const vaultDefaultAmount = totalDefaultAmount - defaultCovered; @@ -206,7 +196,6 @@ LoanManage::defaultLoan( auto vaultTotalProxy = vaultSle->at(sfAssetsTotal); auto vaultAvailableProxy = vaultSle->at(sfAssetsAvailable); -#if 0 if (vaultTotalProxy < vaultDefaultAmount) { // LCOV_EXCL_START @@ -214,7 +203,6 @@ LoanManage::defaultLoan( return tefBAD_LEDGER; // LCOV_EXCL_STOP } -#endif auto const vaultDefaultRounded = roundToAsset( vaultAsset, vaultDefaultAmount, vaultScale, Number::RoundingMode::Downward); @@ -222,7 +210,6 @@ LoanManage::defaultLoan( // Increase the Asset Available of the Vault by liquidated First-Loss // Capital and any unclaimed funds amount: vaultAvailableProxy += defaultCovered; -#if 0 if (*vaultAvailableProxy > *vaultTotalProxy && !vaultAsset.integral()) { auto const difference = vaultAvailableProxy - vaultTotalProxy; @@ -249,13 +236,11 @@ LoanManage::defaultLoan( return tecINTERNAL; // LCOV_EXCL_STOP } -#endif // The loss has been realized if (loanSle->isFlag(lsfLoanImpaired)) { auto vaultLossUnrealizedProxy = vaultSle->at(sfLossUnrealized); -#if 0 if (vaultLossUnrealizedProxy < totalDefaultAmount) { // LCOV_EXCL_START @@ -263,7 +248,6 @@ LoanManage::defaultLoan( return tefBAD_LEDGER; // LCOV_EXCL_STOP } -#endif adjustImpreciseNumber( vaultLossUnrealizedProxy, -totalDefaultAmount, vaultAsset, vaultScale); } @@ -277,7 +261,6 @@ LoanManage::defaultLoan( adjustImpreciseNumber(brokerDebtTotalProxy, -totalDefaultAmount, vaultAsset, vaultScale); // Decrease the First-Loss Capital Cover Available: auto coverAvailableProxy = brokerSle->at(sfCoverAvailable); -#if 0 if (coverAvailableProxy < defaultCovered) { // LCOV_EXCL_START @@ -285,7 +268,6 @@ LoanManage::defaultLoan( return tefBAD_LEDGER; // LCOV_EXCL_STOP } -#endif coverAvailableProxy -= defaultCovered; view.update(brokerSle); } @@ -331,7 +313,6 @@ LoanManage::impairLoan( // Update the Vault object(set "paper loss") auto vaultLossUnrealizedProxy = vaultSle->at(sfLossUnrealized); adjustImpreciseNumber(vaultLossUnrealizedProxy, lossUnrealized, vaultAsset, vaultScale); -#if 0 if (vaultLossUnrealizedProxy > vaultSle->at(sfAssetsTotal) - vaultSle->at(sfAssetsAvailable)) { // Having a loss greater than the vault's unavailable assets @@ -340,7 +321,6 @@ LoanManage::impairLoan( "corrupt the vault."; return tecLIMIT_EXCEEDED; } -#endif view.update(vaultSle); // Update the Loan object @@ -373,7 +353,6 @@ LoanManage::unimpairLoan( // Update the Vault object(clear "paper loss") auto vaultLossUnrealizedProxy = vaultSle->at(sfLossUnrealized); Number const lossReversed = owedToVault(loanSle); -#if 0 if (vaultLossUnrealizedProxy < lossReversed) { // LCOV_EXCL_START @@ -381,7 +360,6 @@ LoanManage::unimpairLoan( return tefBAD_LEDGER; // LCOV_EXCL_STOP } -#endif // Reverse the "paper loss" adjustImpreciseNumber(vaultLossUnrealizedProxy, -lossReversed, vaultAsset, vaultScale); diff --git a/src/libxrpl/tx/transactors/lending/LoanPay.cpp b/src/libxrpl/tx/transactors/lending/LoanPay.cpp index 4d4bc26df6..a0a1479bdb 100644 --- a/src/libxrpl/tx/transactors/lending/LoanPay.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanPay.cpp @@ -146,7 +146,6 @@ LoanPay::calculateBaseFee(ReadView const& view, STTx const& tx) static constexpr std::int64_t kMaxFeeIncrements = kLoanMaximumPaymentsPerTransaction / kLoanPaymentsPerFeeIncrement; -#if 0 if (view.rules().enabled(fixCleanup3_1_3) && amount >= regularPayment * kLoanMaximumPaymentsPerTransaction) { @@ -158,7 +157,6 @@ LoanPay::calculateBaseFee(ReadView const& view, STTx const& tx) // increments. return kMaxFeeIncrements * normalCost; } -#endif // Estimate how many payments will be made Number const numPaymentEstimate = static_cast(amount / regularPayment); @@ -326,7 +324,6 @@ LoanPay::doApply() // In the fixCleanup3_2_0 path, vault-related values (for example, // DebtTotal) use vaultScale. The legacy path below intentionally retains // its pre-amendment loanScale behavior. - [[maybe_unused]] auto const minCover = [&]() { if (view.rules().enabled(fixCleanup3_2_0)) { @@ -339,12 +336,8 @@ LoanPay::doApply() return roundToAsset( asset, tenthBipsOfValue(debtTotalProxy.value(), coverRateMinimum), loanScale); }(); -#if 0 return coverAvailableProxy >= minCover && !isDeepFrozen(view, brokerOwner, asset) && !requireAuth(view, asset, brokerOwner, AuthType::StrongAuth); -#else - return true; -#endif }(); auto const brokerPayee = sendBrokerFeeToOwner ? brokerOwner : brokerPseudoAccount; @@ -403,24 +396,23 @@ LoanPay::doApply() XRPL_ASSERT_PARTS( // It is possible to pay 0 principal - paymentParts->principalPaid >= beast::kZero, + paymentParts->principalPaid >= 0, "xrpl::LoanPay::doApply", "valid principal paid"); XRPL_ASSERT_PARTS( // It is possible to pay 0 interest - paymentParts->interestPaid >= beast::kZero, + paymentParts->interestPaid >= 0, "xrpl::LoanPay::doApply", "valid interest paid"); XRPL_ASSERT_PARTS( // It should not be possible to pay 0 total - paymentParts->principalPaid + paymentParts->interestPaid > beast::kZero, + paymentParts->principalPaid + paymentParts->interestPaid > 0, "xrpl::LoanPay::doApply", "valid total paid"); - XRPL_ASSERT_PARTS( - paymentParts->feePaid >= beast::kZero, "xrpl::LoanPay::doApply", "valid fee paid"); + XRPL_ASSERT_PARTS(paymentParts->feePaid >= 0, "xrpl::LoanPay::doApply", "valid fee paid"); - if (paymentParts->principalPaid < beast::kZero || paymentParts->interestPaid < beast::kZero || - paymentParts->feePaid < beast::kZero) + if (paymentParts->principalPaid < 0 || paymentParts->interestPaid < 0 || + paymentParts->feePaid < 0) { // LCOV_EXCL_START JLOG(j_.fatal()) << "Loan payment computation returned invalid values."; @@ -500,25 +492,21 @@ LoanPay::doApply() assetsAvailableProxy += totalPaidToVaultRounded; assetsTotalProxy += paymentParts->valueChange; -#if 0 XRPL_ASSERT_PARTS( *assetsAvailableProxy <= *assetsTotalProxy, "xrpl::LoanPay::doApply", "assets available must not be greater than assets outstanding"); -#endif JLOG(j_.debug()) << "total paid to vault raw: " << totalPaidToVaultRaw << ", total paid to vault rounded: " << totalPaidToVaultRounded << ", total paid to broker: " << totalPaidToBroker << ", amount from transaction: " << amount; -#if 0 // Move funds XRPL_ASSERT_PARTS( totalPaidToVaultRounded + totalPaidToBroker <= amount, "xrpl::LoanPay::doApply", "amount is sufficient"); -#endif if (!sendBrokerFeeToOwner) { @@ -537,12 +525,10 @@ LoanPay::doApply() Number const assetsAvailableAfter = *assetsAvailableProxy; Number const assetsTotalAfter = *assetsTotalProxy; -#if 0 XRPL_ASSERT_PARTS( assetsAvailableAfter <= assetsTotalAfter, "xrpl::LoanPay::doApply", "assets available must not be greater than assets outstanding"); -#endif if (assetsAvailableAfter == assetsAvailableBefore) { // An unchanged assetsAvailable indicates that the amount paid to the @@ -586,7 +572,6 @@ LoanPay::doApply() return tecINTERNAL; // LCOV_EXCL_STOP } -#if 0 if (assetsAvailableAfter > assetsTotalAfter) { // Assets available are not allowed to be larger than assets total. @@ -597,7 +582,6 @@ LoanPay::doApply() return tecINTERNAL; // LCOV_EXCL_STOP } -#endif // These three values are used to check that funds are conserved after the transfers auto const accountBalanceBefore = accountHolds( diff --git a/src/libxrpl/tx/transactors/lending/LoanSet.cpp b/src/libxrpl/tx/transactors/lending/LoanSet.cpp index 7447d10cbe..573f700f51 100644 --- a/src/libxrpl/tx/transactors/lending/LoanSet.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanSet.cpp @@ -87,21 +87,17 @@ LoanSet::preflight(PreflightContext const& ctx) if (auto const data = tx[~sfData]; data && !data->empty() && !validDataLength(tx[~sfData], kMaxDataPayloadLength)) return temINVALID; -#if 0 for (auto const& field : {&sfLoanServiceFee, &sfLatePaymentFee, &sfClosePaymentFee}) { if (!validNumericMinimum(tx[~*field])) return temINVALID; } -#endif // Principal Requested is required auto const p = tx[sfPrincipalRequested]; - if (p <= beast::kZero) + if (p <= 0) return temINVALID; -#if 0 if (!validNumericRange(tx[~sfLoanOriginationFee], p)) return temINVALID; -#endif if (!validNumericRange(tx[~sfInterestRate], kMaxInterestRate)) return temINVALID; if (!validNumericRange(tx[~sfOverpaymentFee], kMaxOverpaymentFee)) @@ -306,13 +302,11 @@ LoanSet::preclaim(PreclaimContext const& ctx) return tefBAD_LEDGER; // LCOV_EXCL_LINE } -#if 0 if (vault->at(sfAssetsMaximum) != 0 && vault->at(sfAssetsTotal) >= vault->at(sfAssetsMaximum)) { JLOG(ctx.j.warn()) << "Vault at maximum assets limit. Can't add another loan."; return tecLIMIT_EXCEEDED; } -#endif Asset const asset = vault->at(sfAsset); @@ -412,13 +406,11 @@ LoanSet::doApply() auto vaultAvailableProxy = vaultSle->at(sfAssetsAvailable); auto vaultTotalProxy = vaultSle->at(sfAssetsTotal); auto const vaultScale = getAssetsTotalScale(vaultSle); -#if 0 if (vaultAvailableProxy < principalRequested) { JLOG(j_.warn()) << "Insufficient assets available in the Vault to fund the loan."; return tecINSUFFICIENT_FUNDS; } -#endif TenthBips32 const interestRate{tx[~sfInterestRate].value_or(0)}; @@ -440,7 +432,6 @@ LoanSet::doApply() principalRequested, properties.loanState.managementFeeDue); -#if 0 auto const vaultMaximum = *vaultSle->at(sfAssetsMaximum); XRPL_ASSERT_PARTS( vaultMaximum == 0 || vaultMaximum > *vaultTotalProxy, @@ -451,7 +442,6 @@ LoanSet::doApply() JLOG(j_.warn()) << "Loan would exceed the maximum assets of the vault"; return tecLIMIT_EXCEEDED; } -#endif // Check that relevant values won't lose precision. This is mostly only // relevant for IOU assets. for (auto const& field : getValueFields()) @@ -477,9 +467,8 @@ LoanSet::doApply() return ret; // Check that the other computed values are valid - if (properties.loanState.managementFeeDue < beast::kZero || - properties.loanState.valueOutstanding <= beast::kZero || - properties.periodicPayment <= beast::kZero) + if (properties.loanState.managementFeeDue < 0 || properties.loanState.valueOutstanding <= 0 || + properties.periodicPayment <= 0) { // LCOV_EXCL_START JLOG(j_.warn()) << "Computed loan properties are invalid. Does not compute." @@ -496,17 +485,14 @@ LoanSet::doApply() auto const newDebtDelta = principalRequested + state.interestDue; auto const newDebtTotal = brokerSle->at(sfDebtTotal) + newDebtDelta; -#if 0 if (auto const debtMaximum = brokerSle->at(sfDebtMaximum); debtMaximum != 0 && debtMaximum < newDebtTotal) { JLOG(j_.warn()) << "Loan would exceed the maximum debt limit of the LoanBroker."; return tecLIMIT_EXCEEDED; } -#endif TenthBips32 const coverRateMinimum{brokerSle->at(sfCoverRateMinimum)}; { - [[maybe_unused]] auto const minCover = [&]() { if (ctx_.view().rules().enabled(fixCleanup3_2_0)) { @@ -519,13 +505,11 @@ LoanSet::doApply() NumberRoundModeGuard const mg(Number::RoundingMode::Upward); return tenthBipsOfValue(newDebtTotal, coverRateMinimum); }(); -#if 0 if (brokerSle->at(sfCoverAvailable) < minCover) { JLOG(j_.warn()) << "Insufficient first-loss capital to cover the loan."; return tecINSUFFICIENT_FUNDS; } -#endif } adjustOwnerCount(view, borrowerSle, 1, j_); @@ -639,12 +623,10 @@ LoanSet::doApply() // Update the balances in the vault vaultAvailableProxy -= principalRequested; vaultTotalProxy += state.interestDue; -#if 0 XRPL_ASSERT_PARTS( *vaultAvailableProxy <= *vaultTotalProxy, "xrpl::LoanSet::doApply", "assets available must not be greater than assets outstanding"); -#endif view.update(vaultSle); // Update the balances in the loan broker diff --git a/src/libxrpl/tx/transactors/system/Batch.cpp b/src/libxrpl/tx/transactors/system/Batch.cpp index de85f464c0..64a62ac273 100644 --- a/src/libxrpl/tx/transactors/system/Batch.cpp +++ b/src/libxrpl/tx/transactors/system/Batch.cpp @@ -133,7 +133,6 @@ Batch::calculateBaseFee(ReadView const& view, STTx const& tx) } } -#if 0 // LCOV_EXCL_START if (signerCount > 0 && view.fees().base > maxAmount / signerCount) { @@ -141,7 +140,6 @@ Batch::calculateBaseFee(ReadView const& view, STTx const& tx) return XRPAmount{kInitialXrp}; } // LCOV_EXCL_STOP -#endif XRPAmount const signerFees = signerCount * view.fees().base; diff --git a/src/libxrpl/tx/transactors/vault/VaultClawback.cpp b/src/libxrpl/tx/transactors/vault/VaultClawback.cpp index 8deaa16d00..eb12905467 100644 --- a/src/libxrpl/tx/transactors/vault/VaultClawback.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultClawback.cpp @@ -234,7 +234,6 @@ VaultClawback::assetsToClawback( // LCOV_EXCL_STOP } - [[maybe_unused]] auto const assetsAvailable = vault->at(sfAssetsAvailable); auto const mptIssuanceID = *vault->at(sfShareMPTID); MPTIssue const share{mptIssuanceID}; @@ -284,8 +283,7 @@ VaultClawback::assetsToClawback( return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE assetsRecovered = *maybeAssets; } -// Clamp to maximum. -#if 0 + // Clamp to maximum. if (assetsRecovered > *assetsAvailable) { assetsRecovered = *assetsAvailable; @@ -313,7 +311,6 @@ VaultClawback::assetsToClawback( // LCOV_EXCL_STOP } } -#endif } catch (std::overflow_error const&) { @@ -357,11 +354,9 @@ VaultClawback::doApply() auto assetsTotal = vault->at(sfAssetsTotal); [[maybe_unused]] auto const lossUnrealized = vault->at(sfLossUnrealized); -#if 0 XRPL_ASSERT( lossUnrealized <= (assetsTotal - assetsAvailable), "xrpl::VaultClawback::doApply : loss and assets do balance"); -#endif AccountID const holder = tx[sfHolder]; STAmount sharesDestroyed = {share}; diff --git a/src/libxrpl/tx/transactors/vault/VaultDeposit.cpp b/src/libxrpl/tx/transactors/vault/VaultDeposit.cpp index 1139c3b3bb..c08d1e957c 100644 --- a/src/libxrpl/tx/transactors/vault/VaultDeposit.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultDeposit.cpp @@ -302,12 +302,10 @@ VaultDeposit::doApply() vault->at(sfAssetsAvailable) += assetsDeposited; view().update(vault); -// A deposit must not push the vault over its limit. -#if 0 + // A deposit must not push the vault over its limit. auto const maximum = *vault->at(sfAssetsMaximum); - if (maximum != beast::kZero && *vault->at(sfAssetsTotal) > maximum) + if (maximum != 0 && *vault->at(sfAssetsTotal) > maximum) return tecLIMIT_EXCEEDED; -#endif // Transfer assets from depositor to vault. if (auto const ter = accountSend( diff --git a/src/libxrpl/tx/transactors/vault/VaultSet.cpp b/src/libxrpl/tx/transactors/vault/VaultSet.cpp index a026b128c7..6d0ade6e52 100644 --- a/src/libxrpl/tx/transactors/vault/VaultSet.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultSet.cpp @@ -144,10 +144,8 @@ VaultSet::doApply() vault->at(sfData) = tx[sfData]; if (tx.isFieldPresent(sfAssetsMaximum)) { -#if 0 if (tx[sfAssetsMaximum] != 0 && tx[sfAssetsMaximum] < *vault->at(sfAssetsTotal)) return tecLIMIT_EXCEEDED; -#endif vault->at(sfAssetsMaximum) = tx[sfAssetsMaximum]; } diff --git a/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp b/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp index 8a643b5164..cfcf79fdba 100644 --- a/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp @@ -265,7 +265,6 @@ VaultWithdraw::doApply() auto assetsAvailable = vault->at(sfAssetsAvailable); auto assetsTotal = vault->at(sfAssetsTotal); auto const lossUnrealized = vault->at(sfLossUnrealized); -#if 0 XRPL_ASSERT( lossUnrealized <= (assetsTotal - assetsAvailable), "xrpl::VaultWithdraw::doApply : loss and assets do balance"); @@ -276,7 +275,6 @@ VaultWithdraw::doApply() JLOG(j_.debug()) << "VaultWithdraw: vault doesn't hold enough assets"; return tecINSUFFICIENT_FUNDS; } -#endif // Post-fixCleanup3_2_0 "final withdrawal" rule: // a transaction that would burn every outstanding share is only permitted when the vault is in diff --git a/src/test/app/AMM_test.cpp b/src/test/app/AMM_test.cpp index b4b721dc56..64972c24ab 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -1211,9 +1211,7 @@ private: // Number{UINT64_C(100000'0000000009), -10} are both rounded // down to 1e5 BEAST_EXPECT((finalLPToken - initLPToken == IOUAmount{1, 5})); -#if 0 BEAST_EXPECT(finalLPToken - initLPToken < deltaLPTokens); -#endif // fraction of newLPTokens/(existing LPToken balance). The // existing LPToken balance is 1e7 @@ -6273,7 +6271,6 @@ private: // payment or a swap transaction BEAST_EXPECT(amm.getLPTokensBalance() == preSwapLPTokenBalance); -#if 0 // Invariant: The square root of (product of the pool // balances) must be at least the LPTokenBalance Number const sqrtPoolProduct = root2(goodUsdGH * goodUsdBIT); @@ -6287,7 +6284,6 @@ private: // internally rounded to 100, due to representation // error. BEAST_EXPECT((sqrtPoolProduct + Number{1, -14} >= input.lpTokenBalance)); -#endif } } } @@ -6798,7 +6794,6 @@ private: NumberMantissaScaleGuard const sg(MantissaRange::MantissaScale::Small); NumberRoundModeGuard const g( env.enabled(fixAMMv1_3) ? Number::RoundingMode::Upward : Number::getround()); -#if 0 auto const res = root2(amount * amount2); if (shouldFail) @@ -6809,7 +6804,6 @@ private: { BEAST_EXPECT(res >= lptBalance); } -#endif } void diff --git a/src/test/app/LendingHelpers_test.cpp b/src/test/app/LendingHelpers_test.cpp index 5f609572e8..ac8e0764fc 100644 --- a/src/test/app/LendingHelpers_test.cpp +++ b/src/test/app/LendingHelpers_test.cpp @@ -268,8 +268,8 @@ class LendingHelpers_test : public beast::unit_test::Suite std::uint32_t const n2 = 1'000; BEAST_EXPECT(computePowerMinusOne(r1, n1) == computePowerMinusOneHybrid(r1, n1)); BEAST_EXPECT(computePowerMinusOne(r2, n2) == computePowerMinusOneHybrid(r2, n2)); - BEAST_EXPECT(computePowerMinusOne(r1, n1) > beast::kZero); - BEAST_EXPECT(computePowerMinusOne(r2, n2) > beast::kZero); + BEAST_EXPECT(computePowerMinusOne(r1, n1) > 0); + BEAST_EXPECT(computePowerMinusOne(r2, n2) > 0); } } @@ -373,7 +373,6 @@ class LendingHelpers_test : public beast::unit_test::Suite { Number const closed = power(1 + tc.r, tc.n) - 1; Number const hybrid = computePowerMinusOneHybrid(tc.r, tc.n); - [[maybe_unused]] Number const binom = computePowerMinusOne(tc.r, tc.n); // At exact threshold, hybrid must take closed-form path: @@ -383,7 +382,6 @@ class LendingHelpers_test : public beast::unit_test::Suite tc.name + ": hybrid should equal closed at threshold; got hybrid=" + to_string(hybrid) + ", closed=" + to_string(closed)); -#if 0 // Closed-form and binomial must agree at the threshold to // within Number's post-subtraction precision (~10 sig // digits of `r*n = 1e-9`, i.e. ~1e-19 absolute error). @@ -392,7 +390,6 @@ class LendingHelpers_test : public beast::unit_test::Suite BEAST_EXPECTS( diff < tolerance, tc.name + ": closed and binomial diverge at threshold by " + to_string(diff)); -#endif } } } @@ -408,14 +405,12 @@ class LendingHelpers_test : public beast::unit_test::Suite using namespace jtx; using namespace xrpl::detail; Env const env{*this}; - [[maybe_unused]] auto const& rules = env.current()->rules(); -// Inputs from the bug reproduction in Loan_test.cpp: -// InterestRate = 1 TenthBips32 (0.001 % per year), -// PaymentInterval = 600 s, principal = 100, 3 payments. -// periodicRate is ~1.9e-10. -#if 0 + // Inputs from the bug reproduction in Loan_test.cpp: + // InterestRate = 1 TenthBips32 (0.001 % per year), + // PaymentInterval = 600 s, principal = 100, 3 payments. + // periodicRate is ~1.9e-10. auto const periodicRate = loanPeriodicRate(TenthBips32{1}, 600); auto const periodicPayment = loanPeriodicPayment(rules, 100, periodicRate, 3); @@ -429,7 +424,6 @@ class LendingHelpers_test : public beast::unit_test::Suite "n=" + std::to_string(n) + ": payment*n=" + to_string(upperBound) + ", principal=" + to_string(computed)); } -#endif } // Regression: `computeTheoreticalLoanState` must produce a non-negative @@ -451,11 +445,9 @@ class LendingHelpers_test : public beast::unit_test::Suite auto const state = computeTheoreticalLoanState(rules, periodicPayment, periodicRate, 2, TenthBips32{0}); -#if 0 BEAST_EXPECT(state.principalOutstanding <= state.valueOutstanding); -#endif - BEAST_EXPECT(state.interestDue >= beast::kZero); - BEAST_EXPECT(state.managementFeeDue == beast::kZero); + BEAST_EXPECT(state.interestDue >= 0); + BEAST_EXPECT(state.managementFeeDue == 0); } // Direct gating proof: at near-zero rate, `computePaymentFactor` must @@ -478,7 +470,6 @@ class LendingHelpers_test : public beast::unit_test::Suite // F(r,3) = (1 + 3r + 3r^2 + r^3) / (3 + 3r + r^2) // No power(), no binomial series — pure polynomial arithmetic in // Number. - [[maybe_unused]] Number const reference = (1 + 3 * r + 3 * r * r + r * r * r) / (3 + 3 * r + r * r); // Pre-fix: closed form power(1+r, n) - 1 suffers catastrophic @@ -493,7 +484,6 @@ class LendingHelpers_test : public beast::unit_test::Suite // The amendment must change the computed factor in this regime. BEAST_EXPECT(buggyFactor != correctFactor); -#if 0 // The fixed factor must agree with the polynomial reference to // within a few ULPs of Number's 19-digit precision. BEAST_EXPECT(abs(correctFactor - reference) < Number(1, -15)); @@ -501,7 +491,6 @@ class LendingHelpers_test : public beast::unit_test::Suite // The buggy factor must diverge from the reference by a measurable // amount — empirically ~1e-10 in this regime. BEAST_EXPECT(abs(buggyFactor - reference) > Number(1, -12)); -#endif } void diff --git a/src/test/app/LoanBroker_test.cpp b/src/test/app/LoanBroker_test.cpp index 8205a9df8d..0edb955b90 100644 --- a/src/test/app/LoanBroker_test.cpp +++ b/src/test/app/LoanBroker_test.cpp @@ -1447,18 +1447,14 @@ class LoanBroker_test : public beast::unit_test::Suite { auto const dm = power(2, 64) - 1; -#if 0 BEAST_EXPECT(dm > kMaxMpTokenAmount); -#endif tx2[sfDebtMaximum] = dm; env(tx2, Ter(temINVALID)); } { auto const dm = power(2, 63) - 1; -#if 0 BEAST_EXPECTS(dm > kMaxMpTokenAmount, to_string(dm)); -#endif tx2[sfDebtMaximum] = dm; env(tx2, Ter(temINVALID)); } @@ -1633,7 +1629,7 @@ class LoanBroker_test : public beast::unit_test::Suite auto const broker = env.le(brokerKeylet); if (!BEAST_EXPECT(broker)) return; - BEAST_EXPECT(broker->at(sfCoverAvailable) > beast::kZero); + BEAST_EXPECT(broker->at(sfCoverAvailable) > 0); // Get the broker pseudo-account ID auto const brokerPseudoID = broker->at(sfAccount); @@ -1750,7 +1746,7 @@ class LoanBroker_test : public beast::unit_test::Suite auto const broker = env.le(brokerKeylet); if (!BEAST_EXPECT(broker)) return; - BEAST_EXPECT(broker->at(sfCoverAvailable) > beast::kZero); + BEAST_EXPECT(broker->at(sfCoverAvailable) > 0); // Get the broker pseudo-account auto const brokerPseudoID = broker->at(sfAccount); @@ -2154,10 +2150,8 @@ class LoanBroker_test : public beast::unit_test::Suite Number const coverAfter = brokerAfter->at(sfCoverAvailable); Number const actual = coverAfter - coverBefore; Number const lost = requested - actual; - BEAST_EXPECT(lost >= beast::kZero); -#if 0 + BEAST_EXPECT(lost >= Number{0}); BEAST_EXPECT(lost < oneUlp); -#endif } } diff --git a/src/test/app/Loan_test.cpp b/src/test/app/Loan_test.cpp index d01e0fb0a3..c3b5850231 100644 --- a/src/test/app/Loan_test.cpp +++ b/src/test/app/Loan_test.cpp @@ -638,8 +638,7 @@ protected: if (auto const vaultSle = env.le(keylet::vault(brokerSle->at(sfVaultID))); BEAST_EXPECT(vaultSle)) { -// log << vaultSle->getJson() << std::endl; -#if 0 + // log << vaultSle->getJson() << std::endl; auto const assetsUnavailable = vaultSle->at(sfAssetsTotal) - vaultSle->at(sfAssetsAvailable); auto const unrealizedLoss = vaultSle->at(sfLossUnrealized) + state.totalValue - @@ -649,7 +648,6 @@ protected: { return false; } -#endif } } return true; @@ -1028,12 +1026,10 @@ protected: state.paymentRemaining, broker.params.managementFeeRate); -#if 0 BEAST_EXPECT( paymentComponents.trackedValueDelta <= roundedPeriodicPayment || (paymentComponents.specialCase == xrpl::detail::PaymentSpecialCase::Final && paymentComponents.trackedValueDelta >= roundedPeriodicPayment)); -#endif BEAST_EXPECT( paymentComponents.trackedValueDelta == paymentComponents.trackedPrincipalDelta + paymentComponents.trackedInterestPart() + diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index d9fab8a4e2..81019970ad 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -15,11 +15,11 @@ #include #include #include +#include #include #include #include #include -#include namespace xrpl { @@ -1386,13 +1386,10 @@ public: testRelationals() { testcase << "test_relationals " << to_string(Number::getMantissaScale()); -#if 0 BEAST_EXPECT(!(Number{100} < Number{10})); BEAST_EXPECT(Number{100} > Number{10}); BEAST_EXPECT(Number{100} >= Number{10}); BEAST_EXPECT(!(Number{100} <= Number{10})); -#endif - // *facepalm* } void @@ -1471,9 +1468,9 @@ public: // Test that rounding works as expected. testcase("Rounding"); - using NumberRoundings = std::unordered_map; + using NumberRoundings = std::map; - std::unordered_map const expected{ + std::map const expected{ // Positive numbers {Number{13, -1}, {{Number::RoundingMode::ToNearest, 1},