diff --git a/CMakeLists.txt b/CMakeLists.txt index fa261673d35..5724c14e9de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1631,6 +1631,7 @@ else () src/ripple/basics/impl/contract.cpp src/ripple/basics/impl/CountedObject.cpp src/ripple/basics/impl/FileUtilities.cpp + src/ripple/basics/impl/IOUAmount.cpp src/ripple/basics/impl/Log.cpp src/ripple/basics/impl/strHex.cpp src/ripple/basics/impl/StringUtilities.cpp @@ -1657,7 +1658,6 @@ else () src/ripple/protocol/impl/ErrorCodes.cpp src/ripple/protocol/impl/Feature.cpp src/ripple/protocol/impl/HashPrefix.cpp - src/ripple/protocol/impl/IOUAmount.cpp src/ripple/protocol/impl/Indexes.cpp src/ripple/protocol/impl/InnerObjectFormats.cpp src/ripple/protocol/impl/Issue.cpp @@ -1730,6 +1730,7 @@ install ( src/ripple/basics/Buffer.h src/ripple/basics/CountedObject.h src/ripple/basics/FileUtilities.h + src/ripple/basics/IOUAmount.h src/ripple/basics/LocalValue.h src/ripple/basics/Log.h src/ripple/basics/safe_cast.h @@ -1784,7 +1785,6 @@ install ( src/ripple/protocol/ErrorCodes.h src/ripple/protocol/Feature.h src/ripple/protocol/HashPrefix.h - src/ripple/protocol/IOUAmount.h src/ripple/protocol/Indexes.h src/ripple/protocol/InnerObjectFormats.h src/ripple/protocol/Issue.h @@ -2338,12 +2338,14 @@ else () src/test/basics/Buffer_test.cpp src/test/basics/DetectCrash_test.cpp src/test/basics/FileUtilities_test.cpp + src/test/basics/IOUAmount_test.cpp src/test/basics/KeyCache_test.cpp src/test/basics/PerfLog_test.cpp src/test/basics/RangeSet_test.cpp src/test/basics/Slice_test.cpp src/test/basics/StringUtilities_test.cpp src/test/basics/TaggedCache_test.cpp + src/test/basics/XRPAmount_test.cpp src/test/basics/base64_test.cpp src/test/basics/base_uint_test.cpp src/test/basics/contract_test.cpp @@ -2498,7 +2500,6 @@ else () subdir: protocol #]===============================] src/test/protocol/BuildInfo_test.cpp - src/test/protocol/IOUAmount_test.cpp src/test/protocol/InnerObjectFormats_test.cpp src/test/protocol/Issue_test.cpp src/test/protocol/PublicKey_test.cpp @@ -2511,7 +2512,6 @@ else () src/test/protocol/SecretKey_test.cpp src/test/protocol/Seed_test.cpp src/test/protocol/TER_test.cpp - src/test/protocol/XRPAmount_test.cpp src/test/protocol/digest_test.cpp src/test/protocol/types_test.cpp #[===============================[ diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index b482af3d999..1eb48e9de96 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -2231,14 +2231,15 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin, bool counters) auto const loadFactorServer = app_.getFeeTrack().getLoadFactor(); auto const loadBaseServer = app_.getFeeTrack().getLoadBase(); - auto const loadFactorFeeEscalation = - escalationMetrics.openLedgerFeeLevel; - auto const loadBaseFeeEscalation = - escalationMetrics.referenceFeeLevel; + /* Scale the escalated fee level to unitless "load factor". + In practice, this just strips the units, but it will continue + to work correctly if either base value ever changes. */ + auto const loadFactorFeeEscalation = mulDiv( + escalationMetrics.openLedgerFeeLevel, loadBaseServer, + escalationMetrics.referenceFeeLevel).second; auto const loadFactor = std::max(safe_cast(loadFactorServer), - mulDiv(loadFactorFeeEscalation, loadBaseServer, - loadBaseFeeEscalation).second); + loadFactorFeeEscalation); if (!human) { @@ -2252,11 +2253,11 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin, bool counters) that high. */ info[jss::load_factor_fee_escalation] = - loadFactorFeeEscalation.json(); + escalationMetrics.openLedgerFeeLevel.json(); info[jss::load_factor_fee_queue] = escalationMetrics.minProcessingFeeLevel.json(); info[jss::load_factor_fee_reference] = - loadBaseFeeEscalation.json(); + escalationMetrics.referenceFeeLevel.json(); } else { @@ -2281,13 +2282,14 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin, bool counters) info[jss::load_factor_cluster] = static_cast (fee) / loadBaseServer; } - if (loadFactorFeeEscalation != + if (escalationMetrics.openLedgerFeeLevel != escalationMetrics.referenceFeeLevel && (admin || - loadFactorFeeEscalation != FeeLevel64{ loadFactor })) + loadFactorFeeEscalation != loadFactor)) info[jss::load_factor_fee_escalation] = - static_cast(loadFactorFeeEscalation) / - escalationMetrics.referenceFeeLevel; + static_cast( + escalationMetrics.openLedgerFeeLevel) / + escalationMetrics.referenceFeeLevel; if (escalationMetrics.minProcessingFeeLevel != escalationMetrics.referenceFeeLevel) info[jss::load_factor_fee_queue] = @@ -2324,16 +2326,16 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin, bool counters) { // Make a local specialization of the TaggedFee class, using // XRPAmount as the "unit" to make some of the math here easier. - using DropsDouble = units::TaggedFee; + using XRPDouble = feeunit::TaggedFee; l[jss::base_fee_xrp] = - static_cast(baseFee) / + static_cast(baseFee) / DROPS_PER_XRP; l[jss::reserve_base_xrp] = - static_cast( + static_cast( lpClosed->fees().accountReserve(0)) / DROPS_PER_XRP; l[jss::reserve_inc_xrp] = - static_cast( + static_cast( lpClosed->fees().increment) / DROPS_PER_XRP; auto const nowOffset = app_.timeKeeper().nowOffset(); diff --git a/src/ripple/app/misc/impl/LoadFeeTrack.cpp b/src/ripple/app/misc/impl/LoadFeeTrack.cpp index ea75b0f113c..f82e342f0bf 100644 --- a/src/ripple/app/misc/impl/LoadFeeTrack.cpp +++ b/src/ripple/app/misc/impl/LoadFeeTrack.cpp @@ -127,7 +127,7 @@ namespace detail struct xrp_unit_product_tag; using xrp_unit_product = - units::TaggedFee; + feeunit::TaggedFee; } // detail diff --git a/src/ripple/app/paths/Credit.h b/src/ripple/app/paths/Credit.h index 9d1cfc2cfc8..8e55bbe6729 100644 --- a/src/ripple/app/paths/Credit.h +++ b/src/ripple/app/paths/Credit.h @@ -20,9 +20,9 @@ #ifndef RIPPLE_APP_PATHS_CREDIT_H_INCLUDED #define RIPPLE_APP_PATHS_CREDIT_H_INCLUDED +#include #include #include -#include namespace ripple { diff --git a/src/ripple/app/paths/Flow.cpp b/src/ripple/app/paths/Flow.cpp index 0393cd9eb57..75d15126cd6 100644 --- a/src/ripple/app/paths/Flow.cpp +++ b/src/ripple/app/paths/Flow.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/ripple/app/paths/impl/AmountSpec.h b/src/ripple/app/paths/impl/AmountSpec.h index 0192ea36c97..315b4cde782 100644 --- a/src/ripple/app/paths/impl/AmountSpec.h +++ b/src/ripple/app/paths/impl/AmountSpec.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_PATH_IMPL_AMOUNTSPEC_H_INCLUDED #define RIPPLE_PATH_IMPL_AMOUNTSPEC_H_INCLUDED -#include +#include #include #include diff --git a/src/ripple/app/paths/impl/BookStep.cpp b/src/ripple/app/paths/impl/BookStep.cpp index 350e8ecb621..9accfa48954 100644 --- a/src/ripple/app/paths/impl/BookStep.cpp +++ b/src/ripple/app/paths/impl/BookStep.cpp @@ -23,14 +23,14 @@ #include #include #include +#include #include +#include #include #include #include #include -#include #include -#include #include diff --git a/src/ripple/app/paths/impl/DirectStep.cpp b/src/ripple/app/paths/impl/DirectStep.cpp index ab5627f68f4..4a87bbf9b2d 100644 --- a/src/ripple/app/paths/impl/DirectStep.cpp +++ b/src/ripple/app/paths/impl/DirectStep.cpp @@ -20,9 +20,9 @@ #include #include #include +#include #include #include -#include #include #include diff --git a/src/ripple/app/paths/impl/FlowDebugInfo.h b/src/ripple/app/paths/impl/FlowDebugInfo.h index 3ccdfac843e..f1437785678 100644 --- a/src/ripple/app/paths/impl/FlowDebugInfo.h +++ b/src/ripple/app/paths/impl/FlowDebugInfo.h @@ -21,9 +21,9 @@ #define RIPPLE_PATH_IMPL_FLOWDEBUGINFO_H_INCLUDED #include -#include -#include +#include #include +#include #include #include diff --git a/src/ripple/app/paths/impl/PaySteps.cpp b/src/ripple/app/paths/impl/PaySteps.cpp index 0bf72bf2a8f..a4516bc870b 100644 --- a/src/ripple/app/paths/impl/PaySteps.cpp +++ b/src/ripple/app/paths/impl/PaySteps.cpp @@ -19,11 +19,11 @@ #include #include +#include +#include #include #include #include -#include -#include #include #include diff --git a/src/ripple/app/paths/impl/StrandFlow.h b/src/ripple/app/paths/impl/StrandFlow.h index 3d2b33c7f39..672d321eb40 100644 --- a/src/ripple/app/paths/impl/StrandFlow.h +++ b/src/ripple/app/paths/impl/StrandFlow.h @@ -26,9 +26,9 @@ #include #include #include -#include -#include +#include #include +#include #include diff --git a/src/ripple/app/paths/impl/XRPEndpointStep.cpp b/src/ripple/app/paths/impl/XRPEndpointStep.cpp index b2b0eb8bf84..0142161bcc5 100644 --- a/src/ripple/app/paths/impl/XRPEndpointStep.cpp +++ b/src/ripple/app/paths/impl/XRPEndpointStep.cpp @@ -21,11 +21,11 @@ #include #include #include +#include #include +#include #include -#include #include -#include #include diff --git a/src/ripple/app/tx/impl/ApplyContext.h b/src/ripple/app/tx/impl/ApplyContext.h index 0fb8a69dd88..350615c819a 100644 --- a/src/ripple/app/tx/impl/ApplyContext.h +++ b/src/ripple/app/tx/impl/ApplyContext.h @@ -22,9 +22,9 @@ #include #include +#include #include #include -#include #include #include #include diff --git a/src/ripple/app/tx/impl/Escrow.cpp b/src/ripple/app/tx/impl/Escrow.cpp index d986e0119c2..fc24065a6f1 100644 --- a/src/ripple/app/tx/impl/Escrow.cpp +++ b/src/ripple/app/tx/impl/Escrow.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include // During an EscrowFinish, the transaction must specify both // a condition and a fulfillment. We track whether that diff --git a/src/ripple/app/tx/impl/PayChan.cpp b/src/ripple/app/tx/impl/PayChan.cpp index aae29f8d0ff..0645f618ccc 100644 --- a/src/ripple/app/tx/impl/PayChan.cpp +++ b/src/ripple/app/tx/impl/PayChan.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,6 @@ #include #include #include -#include namespace ripple { diff --git a/src/ripple/protocol/IOUAmount.h b/src/ripple/basics/IOUAmount.h similarity index 97% rename from src/ripple/protocol/IOUAmount.h rename to src/ripple/basics/IOUAmount.h index 5ae3e5d1457..c888c158077 100644 --- a/src/ripple/protocol/IOUAmount.h +++ b/src/ripple/basics/IOUAmount.h @@ -17,8 +17,8 @@ */ //============================================================================== -#ifndef RIPPLE_PROTOCOL_IOUAMOUNT_H_INCLUDED -#define RIPPLE_PROTOCOL_IOUAMOUNT_H_INCLUDED +#ifndef RIPPLE_BASICS_IOUAMOUNT_H_INCLUDED +#define RIPPLE_BASICS_IOUAMOUNT_H_INCLUDED #include #include diff --git a/src/ripple/basics/feeunits.h b/src/ripple/basics/feeunits.h index 3ba10edb75c..051ced35583 100644 --- a/src/ripple/basics/feeunits.h +++ b/src/ripple/basics/feeunits.h @@ -37,7 +37,7 @@ namespace ripple { -namespace units { +namespace feeunit { struct feeunit_tag; struct feelevel_tag; @@ -52,9 +52,9 @@ using enable_if_unit_t = typename std::enable_if_t< template > constexpr bool is_usable_unit_v = - std::is_same_v || - std::is_same_v || - std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || std::is_same_v; @@ -433,37 +433,37 @@ mulDivU(Source1 value, Dest mul, Source2 div) return { true, Dest{ static_cast(quotient) } }; } -} // units +} // feeunit template -using FeeUnit = units::TaggedFee; +using FeeUnit = feeunit::TaggedFee; using FeeUnit32 = FeeUnit; using FeeUnit64 = FeeUnit; template -using FeeLevel = units::TaggedFee; +using FeeLevel = feeunit::TaggedFee; using FeeLevel64 = FeeLevel; using FeeLevelDouble = FeeLevel; template > + class = feeunit::enable_muldiv_t > std::pair mulDiv(Source1 value, Dest mul, Source2 div) { - return units::mulDivU(value, mul, div); + return feeunit::mulDivU(value, mul, div); } template > + class = feeunit::enable_muldiv_commute_t > std::pair mulDiv(Dest value, Source1 mul, Source2 div) { // Multiplication is commutative - return units::mulDivU(mul, value, div); + return feeunit::mulDivU(mul, value, div); } template > + class = feeunit::enable_muldiv_dest_t > std::pair mulDiv(std::uint64_t value, Dest mul, @@ -471,11 +471,11 @@ mulDiv(std::uint64_t value, { // Give the scalars a non-tag so the // unit-handling version gets called. - return units::mulDivU(units::scalar(value), mul, units::scalar(div)); + return feeunit::mulDivU(feeunit::scalar(value), mul, feeunit::scalar(div)); } template > + class = feeunit::enable_muldiv_dest_t > std::pair mulDiv(Dest value, std::uint64_t mul, std::uint64_t div) { @@ -484,7 +484,7 @@ mulDiv(Dest value, std::uint64_t mul, std::uint64_t div) } template > + class = feeunit::enable_muldiv_sources_t > std::pair mulDiv(Source1 value, std::uint64_t mul, @@ -492,12 +492,12 @@ mulDiv(Source1 value, { // Give the scalars a dimensionless unit so the // unit-handling version gets called. - auto unitresult = units::mulDivU(value, units::scalar(mul), div); + auto unitresult = feeunit::mulDivU(value, feeunit::scalar(mul), div); return { unitresult.first, unitresult.second.value() }; } template > + class = feeunit::enable_muldiv_sources_t > std::pair mulDiv(std::uint64_t value, Source1 mul, Source2 div) { diff --git a/src/ripple/protocol/impl/IOUAmount.cpp b/src/ripple/basics/impl/IOUAmount.cpp similarity index 99% rename from src/ripple/protocol/impl/IOUAmount.cpp rename to src/ripple/basics/impl/IOUAmount.cpp index aaa5d8b108e..7a2806f8f6c 100644 --- a/src/ripple/protocol/impl/IOUAmount.cpp +++ b/src/ripple/basics/impl/IOUAmount.cpp @@ -18,7 +18,7 @@ //============================================================================== #include -#include +#include #include #include #include diff --git a/src/ripple/ledger/ReadView.h b/src/ripple/ledger/ReadView.h index f4328654b69..9b6ec799ba5 100644 --- a/src/ripple/ledger/ReadView.h +++ b/src/ripple/ledger/ReadView.h @@ -23,12 +23,12 @@ #include #include #include +#include +#include #include -#include #include #include #include -#include #include #include #include diff --git a/src/ripple/ledger/detail/ApplyStateTable.h b/src/ripple/ledger/detail/ApplyStateTable.h index ab9ff4b3ee5..38fde05d051 100644 --- a/src/ripple/ledger/detail/ApplyStateTable.h +++ b/src/ripple/ledger/detail/ApplyStateTable.h @@ -24,8 +24,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/src/ripple/protocol/AmountConversions.h b/src/ripple/protocol/AmountConversions.h index 5de7bc92714..86e7c36e80a 100644 --- a/src/ripple/protocol/AmountConversions.h +++ b/src/ripple/protocol/AmountConversions.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_PROTOCOL_AMOUNTCONVERSION_H_INCLUDED #define RIPPLE_PROTOCOL_AMOUNTCONVERSION_H_INCLUDED -#include +#include #include #include diff --git a/src/ripple/protocol/PayChan.h b/src/ripple/protocol/PayChan.h index 0525ee61a93..5957668e7e1 100644 --- a/src/ripple/protocol/PayChan.h +++ b/src/ripple/protocol/PayChan.h @@ -21,9 +21,9 @@ #define RIPPLE_PROTOCOL_PAYCHAN_H_INCLUDED #include +#include #include #include -#include namespace ripple { diff --git a/src/ripple/protocol/Quality.h b/src/ripple/protocol/Quality.h index 07fe336a6ff..893049c6d59 100644 --- a/src/ripple/protocol/Quality.h +++ b/src/ripple/protocol/Quality.h @@ -20,10 +20,10 @@ #ifndef RIPPLE_PROTOCOL_QUALITY_H_INCLUDED #define RIPPLE_PROTOCOL_QUALITY_H_INCLUDED +#include +#include #include -#include #include -#include #include #include diff --git a/src/ripple/protocol/STAmount.h b/src/ripple/protocol/STAmount.h index 80e6b2bcac5..f8994bcc705 100644 --- a/src/ripple/protocol/STAmount.h +++ b/src/ripple/protocol/STAmount.h @@ -21,13 +21,13 @@ #define RIPPLE_PROTOCOL_STAMOUNT_H_INCLUDED #include +#include #include +#include #include #include #include #include -#include -#include #include namespace ripple { diff --git a/src/ripple/protocol/STObject.h b/src/ripple/protocol/STObject.h index 0be43eb62bc..7541e0e2569 100644 --- a/src/ripple/protocol/STObject.h +++ b/src/ripple/protocol/STObject.h @@ -88,7 +88,7 @@ class STObject template std::enable_if_t< - units::is_usable_unit_v && + feeunit::is_usable_unit_v && std::is_assignable_v, ValueProxy&> operator= (Fee const& u); @@ -223,7 +223,7 @@ class STObject template std::enable_if_t< - units::is_usable_unit_v && + feeunit::is_usable_unit_v && std::is_assignable_v, OptionalProxy&> operator= (Fee const& u); @@ -754,7 +754,7 @@ STObject::ValueProxy::operator= (U&& u) template template std::enable_if_t< - units::is_usable_unit_v && + feeunit::is_usable_unit_v && std::is_assignable_v, STObject::ValueProxy&> STObject::ValueProxy::operator= (Fee const& u) @@ -853,7 +853,7 @@ STObject::OptionalProxy::operator=(U&& u) template template std::enable_if_t< - units::is_usable_unit_v && + feeunit::is_usable_unit_v && std::is_assignable_v, STObject::OptionalProxy&> STObject::OptionalProxy::operator= (Fee const& u) diff --git a/src/ripple/unity/basics1.cpp b/src/ripple/unity/basics1.cpp index 5b1eab270e4..852523dc50a 100644 --- a/src/ripple/unity/basics1.cpp +++ b/src/ripple/unity/basics1.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/src/ripple/unity/protocol.cpp b/src/ripple/unity/protocol.cpp index 867557f821a..db5f5a4e5c1 100644 --- a/src/ripple/unity/protocol.cpp +++ b/src/ripple/unity/protocol.cpp @@ -58,7 +58,6 @@ #include #include #include -#include #if DOXYGEN #include diff --git a/src/test/protocol/IOUAmount_test.cpp b/src/test/basics/IOUAmount_test.cpp similarity index 99% rename from src/test/protocol/IOUAmount_test.cpp rename to src/test/basics/IOUAmount_test.cpp index a3ba5c32ca2..c7e685c3546 100644 --- a/src/test/protocol/IOUAmount_test.cpp +++ b/src/test/basics/IOUAmount_test.cpp @@ -17,7 +17,7 @@ */ //============================================================================== -#include +#include #include namespace ripple { diff --git a/src/test/protocol/XRPAmount_test.cpp b/src/test/basics/XRPAmount_test.cpp similarity index 100% rename from src/test/protocol/XRPAmount_test.cpp rename to src/test/basics/XRPAmount_test.cpp diff --git a/src/test/basics/feeunits_test.cpp b/src/test/basics/feeunits_test.cpp index e058ccd63a8..9ba9cc876b6 100644 --- a/src/test/basics/feeunits_test.cpp +++ b/src/test/basics/feeunits_test.cpp @@ -84,12 +84,12 @@ class feeunits_test FeeLevel64 x{ 1024 }; BEAST_EXPECT(x.value() == 1024); BEAST_EXPECT((std::is_same_v)); + feeunit::feelevel_tag>)); std::uint64_t m = 4; auto y = m * x; BEAST_EXPECT(y.value() == 4096); BEAST_EXPECT((std::is_same_v)); + feeunit::feelevel_tag>)); XRPAmount basefee{ 10 }; FeeLevel64 referencefee{ 256 }; diff --git a/src/test/unity/basics_test_unity.cpp b/src/test/unity/basics_test_unity.cpp index 623e1562ef3..0022a48d200 100644 --- a/src/test/unity/basics_test_unity.cpp +++ b/src/test/unity/basics_test_unity.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -35,3 +36,4 @@ #include #include #include +#include diff --git a/src/test/unity/protocol_test_unity.cpp b/src/test/unity/protocol_test_unity.cpp index ab1aecfc1d8..52ca621b928 100644 --- a/src/test/unity/protocol_test_unity.cpp +++ b/src/test/unity/protocol_test_unity.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -34,4 +33,3 @@ #include #include #include -#include