From 2013e7e64de81e21081d6e636660e3d53b101906 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Wed, 30 Apr 2025 16:31:06 -0400 Subject: [PATCH] Remove the new TenthBips serialized type - It was a neat idea, but more trouble than it's worth. The conversion functions are sufficient for what I need. - Partially reverts - d7357d3eca0b70c36b5665fdf23ee5e7a3cea0d7 - cbb4dbcbe7023cb8a8d30f0e794acf9d1d9a458a - 396b981fc0da0d2d248b8c68bd3fac68c5f0b64c --- include/xrpl/protocol/SField.h | 9 --- include/xrpl/protocol/STExchange.h | 20 ------- include/xrpl/protocol/STInteger.h | 4 -- include/xrpl/protocol/detail/sfields.macro | 20 +++---- src/libxrpl/protocol/STInteger.cpp | 58 ------------------- src/libxrpl/protocol/STParsedJSON.cpp | 16 ----- src/libxrpl/protocol/STVar.cpp | 6 -- src/test/jtx/TestHelpers.h | 26 ++++----- src/test/ledger/Invariants_test.cpp | 2 +- .../app/tx/detail/LoanBrokerCoverWithdraw.cpp | 3 +- src/xrpld/app/tx/detail/LoanSet.cpp | 11 ++-- src/xrpld/app/tx/detail/Transactor.h | 17 ++++++ 12 files changed, 47 insertions(+), 145 deletions(-) diff --git a/include/xrpl/protocol/SField.h b/include/xrpl/protocol/SField.h index 035735c513..5b8dcd11c9 100644 --- a/include/xrpl/protocol/SField.h +++ b/include/xrpl/protocol/SField.h @@ -92,8 +92,6 @@ concept HasValue = requires(Integer i) { i.value(); }; STYPE(STI_ISSUE, 24) \ STYPE(STI_XCHAIN_BRIDGE, 25) \ STYPE(STI_CURRENCY, 26) \ - STYPE(STI_TENTHBIPS16, 27) \ - STYPE(STI_TENTHBIPS32, 28) \ \ /* high-level types */ \ /* cannot be serialized inside other types */ \ @@ -363,13 +361,6 @@ using SF_UINT256 = TypedField>; using SF_UINT384 = TypedField>; using SF_UINT512 = TypedField>; -// These TENTHBIPS values are serialized as the underlying type. -// The tag is only applied when deserialized. -// -// Tenth of a basis point values: -using SF_TENTHBIPS16 = TypedField>; -using SF_TENTHBIPS32 = TypedField>; - using SF_ACCOUNT = TypedField; using SF_AMOUNT = TypedField; using SF_ISSUE = TypedField; diff --git a/include/xrpl/protocol/STExchange.h b/include/xrpl/protocol/STExchange.h index dba8bf3efb..dd7c4834a6 100644 --- a/include/xrpl/protocol/STExchange.h +++ b/include/xrpl/protocol/STExchange.h @@ -61,26 +61,6 @@ struct STExchange, T> } }; -template -struct STExchange>, T> -{ - explicit STExchange() = default; - - using value_type = TenthBips; - - static void - get(std::optional& t, STInteger const& u) - { - t = u.value(); - } - - static std::unique_ptr> - set(SField const& f, T const& t) - { - return std::make_unique>(f, t); - } -}; - template <> struct STExchange { diff --git a/include/xrpl/protocol/STInteger.h b/include/xrpl/protocol/STInteger.h index c04131d4a5..6c96f886a7 100644 --- a/include/xrpl/protocol/STInteger.h +++ b/include/xrpl/protocol/STInteger.h @@ -82,10 +82,6 @@ using STUInt16 = STInteger; using STUInt32 = STInteger; using STUInt64 = STInteger; -// Tenth of a basis point values: -using STTenthBips16 = STInteger; -using STTenthBips32 = STInteger; - template inline STInteger::STInteger(Integer v) : value_(v) { diff --git a/include/xrpl/protocol/detail/sfields.macro b/include/xrpl/protocol/detail/sfields.macro index e75560de94..342e2f8770 100644 --- a/include/xrpl/protocol/detail/sfields.macro +++ b/include/xrpl/protocol/detail/sfields.macro @@ -61,9 +61,7 @@ TYPED_SFIELD(sfHookEmitCount, UINT16, 18) TYPED_SFIELD(sfHookExecutionIndex, UINT16, 19) TYPED_SFIELD(sfHookApiVersion, UINT16, 20) TYPED_SFIELD(sfLedgerFixType, UINT16, 21) - -// 16-bit integers represented as 1/10 basis points (bips) -TYPED_SFIELD(sfManagementFeeRate, TENTHBIPS16, 1) +TYPED_SFIELD(sfManagementFeeRate, UINT16, 22) // 1/10 basis points (bips) // 32-bit integers (common) TYPED_SFIELD(sfNetworkID, UINT32, 1) @@ -126,15 +124,13 @@ TYPED_SFIELD(sfNextPaymentDueDate, UINT32, 56) TYPED_SFIELD(sfPaymentRemaining, UINT32, 57) TYPED_SFIELD(sfPaymentTotal, UINT32, 58) TYPED_SFIELD(sfLoanSequence, UINT32, 59) - -// 32-bit integers represented as 1/10 basis points (bips) -TYPED_SFIELD(sfCoverRateMinimum, TENTHBIPS32, 1) -TYPED_SFIELD(sfCoverRateLiquidation, TENTHBIPS32, 2) -TYPED_SFIELD(sfOverpaymentFee, TENTHBIPS32, 3) -TYPED_SFIELD(sfInterestRate, TENTHBIPS32, 4) -TYPED_SFIELD(sfLateInterestRate, TENTHBIPS32, 5) -TYPED_SFIELD(sfCloseInterestRate, TENTHBIPS32, 6) -TYPED_SFIELD(sfOverpaymentInterestRate, TENTHBIPS32, 7) +TYPED_SFIELD(sfCoverRateMinimum, UINT32, 60) // 1/10 basis points (bips) +TYPED_SFIELD(sfCoverRateLiquidation, UINT32, 61) // 1/10 basis points (bips) +TYPED_SFIELD(sfOverpaymentFee, UINT32, 62) // 1/10 basis points (bips) +TYPED_SFIELD(sfInterestRate, UINT32, 63) // 1/10 basis points (bips) +TYPED_SFIELD(sfLateInterestRate, UINT32, 64) // 1/10 basis points (bips) +TYPED_SFIELD(sfCloseInterestRate, UINT32, 65) // 1/10 basis points (bips) +TYPED_SFIELD(sfOverpaymentInterestRate, UINT32, 66) // 1/10 basis points (bips) // 64-bit integers (common) TYPED_SFIELD(sfIndexNext, UINT64, 1) diff --git a/src/libxrpl/protocol/STInteger.cpp b/src/libxrpl/protocol/STInteger.cpp index d48c0f8f53..bc5b7e855e 100644 --- a/src/libxrpl/protocol/STInteger.cpp +++ b/src/libxrpl/protocol/STInteger.cpp @@ -229,62 +229,4 @@ STUInt64::getJson(JsonOptions) const return convertToString(value_, 16); // Convert to base 16 } -//------------------------------------------------------------------------------ - -template <> -STTenthBips16::STInteger(SerialIter& sit, SField const& name) - : STInteger(name, TenthBips16(sit.get16())) -{ -} - -template <> -SerializedTypeID -STTenthBips16::getSType() const -{ - return STI_TENTHBIPS16; -} - -template <> -std::string -STTenthBips16::getText() const -{ - return std::to_string(value_.value()); -} - -template <> -Json::Value -STTenthBips16::getJson(JsonOptions) const -{ - return value_.value(); -} - -//------------------------------------------------------------------------------ - -template <> -STTenthBips32::STInteger(SerialIter& sit, SField const& name) - : STInteger(name, TenthBips32(sit.get32())) -{ -} - -template <> -SerializedTypeID -STTenthBips32::getSType() const -{ - return STI_TENTHBIPS32; -} - -template <> -std::string -STTenthBips32::getText() const -{ - return std::to_string(value_.value()); -} - -template <> -Json::Value -STTenthBips32::getJson(JsonOptions) const -{ - return value_.value(); -} - } // namespace ripple diff --git a/src/libxrpl/protocol/STParsedJSON.cpp b/src/libxrpl/protocol/STParsedJSON.cpp index 4a9eaf82ab..40be3ac62e 100644 --- a/src/libxrpl/protocol/STParsedJSON.cpp +++ b/src/libxrpl/protocol/STParsedJSON.cpp @@ -446,14 +446,6 @@ parseLeaf( break; - case STI_TENTHBIPS16: - ret = parseUnsigned( - field, json_name, fieldName, name, value, error); - if (!ret) - return ret; - - break; - case STI_UINT32: ret = parseUnsigned( field, json_name, fieldName, name, value, error); @@ -462,14 +454,6 @@ parseLeaf( break; - case STI_TENTHBIPS32: - ret = parseUnsigned( - field, json_name, fieldName, name, value, error); - if (!ret) - return ret; - - break; - case STI_UINT64: try { diff --git a/src/libxrpl/protocol/STVar.cpp b/src/libxrpl/protocol/STVar.cpp index 744ccbc07f..24954c4add 100644 --- a/src/libxrpl/protocol/STVar.cpp +++ b/src/libxrpl/protocol/STVar.cpp @@ -190,12 +190,6 @@ STVar::constructST(SerializedTypeID id, int depth, Args&&... args) case STI_UINT64: construct(std::forward(args)...); return; - case STI_TENTHBIPS16: - construct(std::forward(args)...); - return; - case STI_TENTHBIPS32: - construct(std::forward(args)...); - return; case STI_AMOUNT: construct(std::forward(args)...); return; diff --git a/src/test/jtx/TestHelpers.h b/src/test/jtx/TestHelpers.h index 0d9cadcd47..a4be1b68c4 100644 --- a/src/test/jtx/TestHelpers.h +++ b/src/test/jtx/TestHelpers.h @@ -197,9 +197,7 @@ struct valueUnitField using OV = ValueType; using base = JTxField; - static_assert(std::is_same_v); - static_assert( - std::is_same_v); + static_assert(std::is_same_v); protected: using base::value_; @@ -273,8 +271,8 @@ public: template < class SField, - class UnitTag = typename SField::type::value_type::unit_type, - class ValueType = typename SField::type::value_type::value_type> + class UnitTag, + class ValueType = typename SField::type::value_type> using valueUnitWrapper = JTxFieldWrapper>; @@ -687,15 +685,15 @@ coverWithdraw( auto const loanBrokerID = JTxFieldWrapper(sfLoanBrokerID); auto const managementFeeRate = - valueUnitWrapper(sfManagementFeeRate); + valueUnitWrapper(sfManagementFeeRate); auto const debtMaximum = simpleField(sfDebtMaximum); auto const coverRateMinimum = - valueUnitWrapper(sfCoverRateMinimum); + valueUnitWrapper(sfCoverRateMinimum); auto const coverRateLiquidation = - valueUnitWrapper(sfCoverRateLiquidation); + valueUnitWrapper(sfCoverRateLiquidation); } // namespace loanBroker @@ -722,18 +720,20 @@ auto const latePaymentFee = simpleField(sfLatePaymentFee); auto const closePaymentFee = simpleField(sfClosePaymentFee); -auto const overpaymentFee = valueUnitWrapper(sfOverpaymentFee); +auto const overpaymentFee = + valueUnitWrapper(sfOverpaymentFee); -auto const interestRate = valueUnitWrapper(sfInterestRate); +auto const interestRate = + valueUnitWrapper(sfInterestRate); auto const lateInterestRate = - valueUnitWrapper(sfLateInterestRate); + valueUnitWrapper(sfLateInterestRate); auto const closeInterestRate = - valueUnitWrapper(sfCloseInterestRate); + valueUnitWrapper(sfCloseInterestRate); auto const overpaymentInterestRate = - valueUnitWrapper(sfOverpaymentInterestRate); + valueUnitWrapper(sfOverpaymentInterestRate); auto const paymentTotal = simpleField(sfPaymentTotal); diff --git a/src/test/ledger/Invariants_test.cpp b/src/test/ledger/Invariants_test.cpp index 3763256cad..767403e260 100644 --- a/src/test/ledger/Invariants_test.cpp +++ b/src/test/ledger/Invariants_test.cpp @@ -1405,7 +1405,7 @@ class Invariants_test : public beast::unit_test::suite sle->at(sfOwner) = sle->at(sfAccount); }, [](SLE::pointer& sle) { - sle->at(sfManagementFeeRate) += TenthBips16(1); + sle->at(sfManagementFeeRate) += 1; }, [](SLE::pointer& sle) { sle->at(sfCoverRateMinimum) += 1; }, [](SLE::pointer& sle) { diff --git a/src/xrpld/app/tx/detail/LoanBrokerCoverWithdraw.cpp b/src/xrpld/app/tx/detail/LoanBrokerCoverWithdraw.cpp index f47b607972..a2e4311b33 100644 --- a/src/xrpld/app/tx/detail/LoanBrokerCoverWithdraw.cpp +++ b/src/xrpld/app/tx/detail/LoanBrokerCoverWithdraw.cpp @@ -111,7 +111,8 @@ LoanBrokerCoverWithdraw::preclaim(PreclaimContext const& ctx) auto const coverAvail = sleBroker->at(sfCoverAvailable); // Cover Rate is in 1/10 bips units auto const minimumCover = tenthBipsOfValue( - sleBroker->at(sfDebtTotal), sleBroker->at(sfCoverRateMinimum)); + sleBroker->at(sfDebtTotal), + TenthBips32(sleBroker->at(sfCoverRateMinimum))); if (coverAvail < amount) return tecINSUFFICIENT_FUNDS; if ((coverAvail - amount) < minimumCover) diff --git a/src/xrpld/app/tx/detail/LoanSet.cpp b/src/xrpld/app/tx/detail/LoanSet.cpp index ab4d864b9f..b525beea8d 100644 --- a/src/xrpld/app/tx/detail/LoanSet.cpp +++ b/src/xrpld/app/tx/detail/LoanSet.cpp @@ -229,7 +229,8 @@ LoanSet::preclaim(PreclaimContext const& ctx) } if (brokerSle->at(sfCoverAvailable) < tenthBipsOfValue( - debtTotal + principalRequested, brokerSle->at(sfCoverRateMinimum))) + debtTotal + principalRequested, + TenthBips32(brokerSle->at(sfCoverRateMinimum)))) { JLOG(ctx.j.warn()) << "Insufficient first-loss capital to cover the loan."; @@ -270,7 +271,7 @@ LoanSet::doApply() auto const brokerPseudo = brokerSle->at(sfAccount); auto const brokerPseudoSle = view.peek(keylet::account(brokerPseudo)); auto const principalRequested = tx[sfPrincipalRequested]; - auto const interestRate = tx[~sfInterestRate].value_or(TenthBips32(0)); + TenthBips32 const interestRate{tx[~sfInterestRate].value_or(0)}; auto const originationFee = tx[~sfLoanOriginationFee]; auto const loanAssetsAvailable = principalRequested - originationFee.value_or(Number{}); @@ -332,14 +333,14 @@ LoanSet::doApply() return ter; } - auto const managementFeeRate = brokerSle->at(sfManagementFeeRate); + TenthBips32 const managementFeeRate{brokerSle->at(sfManagementFeeRate)}; // The total amount if interest the loan is expected to generate auto const loanInterest = tenthBipsOfValue(principalRequested, interestRate); // The portion of the loan interest that will go to the vault (total // interest minus the management fee) - auto const loanInterestToVault = loanInterest - - tenthBipsOfValue(loanInterest, managementFeeRate.value()); + auto const loanInterestToVault = + loanInterest - tenthBipsOfValue(loanInterest, managementFeeRate); auto const startDate = tx[sfStartDate]; auto const paymentInterval = tx[~sfPaymentInterval].value_or(defaultPaymentInterval); diff --git a/src/xrpld/app/tx/detail/Transactor.h b/src/xrpld/app/tx/detail/Transactor.h index 1e57bd02ba..d3235514b0 100644 --- a/src/xrpld/app/tx/detail/Transactor.h +++ b/src/xrpld/app/tx/detail/Transactor.h @@ -229,6 +229,13 @@ protected: static bool validNumericRange(std::optional value, T max, T min = {}); + template + static bool + validNumericRange( + std::optional value, + unit::ValueUnit max, + unit::ValueUnit min = {}); + private: std::pair reset(XRPAmount fee); @@ -322,6 +329,16 @@ Transactor::validNumericRange(std::optional value, T max, T min) return value >= min && value <= max; } +template +bool +Transactor::validNumericRange( + std::optional value, + unit::ValueUnit max, + unit::ValueUnit min) +{ + return validNumericRange(value, max.value(), min.value()); +} + } // namespace ripple #endif