diff --git a/include/xrpl/protocol/Rules.h b/include/xrpl/protocol/Rules.h index 449573c36a..b34e7995d3 100644 --- a/include/xrpl/protocol/Rules.h +++ b/include/xrpl/protocol/Rules.h @@ -124,6 +124,9 @@ private: class NumberSO; +bool +useRulesGuards(Rules const& rules); + void createGuards( Rules const& rules, diff --git a/src/libxrpl/protocol/Rules.cpp b/src/libxrpl/protocol/Rules.cpp index 483b0c282e..b5861a8ebd 100644 --- a/src/libxrpl/protocol/Rules.cpp +++ b/src/libxrpl/protocol/Rules.cpp @@ -53,6 +53,9 @@ setCurrentTransactionRules(std::optional r) bool const enableCuspRoundingFix = !r || r->enabled(fixCleanup3_2_0); bool const enableVaultNumbers = enableCuspRoundingFix || (r->enabled(featureSingleAssetVault) || r->enabled(featureLendingProtocol)); + XRPL_ASSERT( + !r || useRulesGuards(*r) == (enableCuspRoundingFix || enableVaultNumbers), + "setCurrentTransactionRules : rule decisions match"); Number::setMantissaScale( enableCuspRoundingFix ? MantissaRange::MantissaScale::Large : (enableVaultNumbers ? MantissaRange::MantissaScale::LargeLegacy @@ -61,6 +64,20 @@ setCurrentTransactionRules(std::optional r) *getCurrentTransactionRulesRef() = std::move(r); } +bool +useRulesGuards(Rules const& rules) +{ + // The list of amendments used here - to decide whether to create a RulesGuard - must be a + // superset of the list used to figure out which mantissa scale to use in + // setCurrentTransactionRules. Additional amendments can be added if desired. + // + // As soon as any one of these amendments is retired, this whole function can be removed, along + // with createGuards, and any other callers, and the first set of guards can be created directly + // at the call site, without using optional. + return rules.enabled(fixCleanup3_2_0) || rules.enabled(featureSingleAssetVault) || + rules.enabled(featureLendingProtocol); +} + void createGuards( Rules const& rules, @@ -68,14 +85,7 @@ createGuards( std::optional& rulesGuard, std::optional& mantissaScaleGuard) { - // The list amendments used to decide which guard(s) to create must be a superset of the list - // used to figure out which mantissa scale to use in setCurrentTransactionRules. Additional - // amendments can be added if desired. - // - // As soon as any one of these amendments is retired, this whole function can be removed, and - // the first set of guards can be created directly at the call site, without using optional. - if (rules.enabled(fixCleanup3_2_0) || rules.enabled(featureSingleAssetVault) || - rules.enabled(featureLendingProtocol)) + if (useRulesGuards(rules)) { // raii classes for the current ledger rules. // fixUniversalNumber predates the rulesGuard and should be replaced. diff --git a/src/libxrpl/tx/applySteps.cpp b/src/libxrpl/tx/applySteps.cpp index 4ac6f49f13..d532c8e71a 100644 --- a/src/libxrpl/tx/applySteps.cpp +++ b/src/libxrpl/tx/applySteps.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/src/test/app/EscrowToken_test.cpp b/src/test/app/EscrowToken_test.cpp index bf7cf90bf2..fada0ba070 100644 --- a/src/test/app/EscrowToken_test.cpp +++ b/src/test/app/EscrowToken_test.cpp @@ -572,8 +572,7 @@ struct EscrowToken_test : public beast::unit_test::Suite env(pay(gw, bob, usd(1))); env.close(); - bool const largeMantissa = - features[featureSingleAssetVault] || features[featureLendingProtocol]; + bool const largeMantissa = useRulesGuards(env.current()->rules()); // alice cannot create escrow for 1/10 iou - precision loss env(escrow::create(alice, bob, usd(1)), @@ -2136,8 +2135,7 @@ struct EscrowToken_test : public beast::unit_test::Suite env(pay(gw, bob, usd(1))); env.close(); - bool const largeMantissa = - features[featureSingleAssetVault] || features[featureLendingProtocol]; + bool const largeMantissa = useRulesGuards(env.current()->rules()); // alice cannot create escrow for 1/10 iou - precision loss env(escrow::create(alice, bob, usd(1)),