From 2a5b1b4e17d1ca447095f2146cc776423ec98470 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Thu, 25 Jun 2026 19:02:53 -0400 Subject: [PATCH] Review feedback from @gregtatcam, plus a few extras - Rename MantissaRange::Get to MantissaRange::Access. The name doesn't really matter, but since the intent of the class is to control access to one function, this works. - Exclude the MantissaScale enum from linting for readability-enum-initial-value. clang-tidy was complaining that "error: initial values in enum 'xrpl::MantissaRange::MantissaScale' are not consistent, consider explicit initialization of all, none or only the first enumerator", but I don't care. I just need Large to match the last value. - Add a static_assert in setCurrentTransactionRules, so that if another MantissaScale is added (and Large is properly updated), the engineer won't forget to add a case for it there. --- include/xrpl/basics/Number.h | 4 +++- src/libxrpl/basics/Number.cpp | 6 +++--- src/libxrpl/protocol/Rules.cpp | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/xrpl/basics/Number.h b/include/xrpl/basics/Number.h index d0414cdbbb..45bcedcbf0 100644 --- a/include/xrpl/basics/Number.h +++ b/include/xrpl/basics/Number.h @@ -127,6 +127,7 @@ struct MantissaRange final using rep = std::uint64_t; enum class MantissaScale { + // NOLINTBEGIN(readability-enum-initial-value) - The values don't matter, except for Large // Small can be removed when either featureSingleAssetVault or featureLendingProtocol are // retired Small, @@ -140,6 +141,7 @@ struct MantissaRange final // in the extremely unlikely case that a downstream project made use of it. Note that // because the behavior changed, this may still be a breaking change. Large = Large330, + // NOLINTEND(readability-enum-initial-value) }; // This entire enum can be removed when the last relevant amendment is retired @@ -178,7 +180,7 @@ struct MantissaRange final return kScales; } - class Get + class Access { static constexpr MantissaRange const& mantissaRange(MantissaScale scale); diff --git a/src/libxrpl/basics/Number.cpp b/src/libxrpl/basics/Number.cpp index 662b21490a..dd31561142 100644 --- a/src/libxrpl/basics/Number.cpp +++ b/src/libxrpl/basics/Number.cpp @@ -30,7 +30,7 @@ namespace xrpl { thread_local Number::RoundingMode Number::mode = Number::RoundingMode::ToNearest; thread_local std::reference_wrapper Number::kRange = - MantissaRange::Get::mantissaRange(MantissaRange::MantissaScale::Large330); + MantissaRange::Access::mantissaRange(MantissaRange::MantissaScale::Large330); std::string to_string(MantissaRange::MantissaScale const& scale) @@ -69,7 +69,7 @@ to_string(Number::RoundingMode const& round) } constexpr MantissaRange const& -MantissaRange::Get::mantissaRange(MantissaScale scale) +MantissaRange::Access::mantissaRange(MantissaScale scale) { static constexpr MantissaRange kSmall{MantissaScale::Small}; static constexpr MantissaRange kLegacy{MantissaScale::LargeLegacy}; @@ -152,7 +152,7 @@ Number::setMantissaScale(MantissaRange::MantissaScale scale) { if (!MantissaRange::getAllScales().contains(scale)) logicError("Unknown mantissa scale"); - kRange = MantissaRange::Get::mantissaRange(scale); + kRange = MantissaRange::Access::mantissaRange(scale); } // Optimization equivalent to: diff --git a/src/libxrpl/protocol/Rules.cpp b/src/libxrpl/protocol/Rules.cpp index 4b8c0171a5..d71bb77f66 100644 --- a/src/libxrpl/protocol/Rules.cpp +++ b/src/libxrpl/protocol/Rules.cpp @@ -54,6 +54,8 @@ setCurrentTransactionRules(std::optional r) if (enableLargeNumbers) { + static_assert( + MantissaRange::MantissaScale::Large == MantissaRange::MantissaScale::Large330); if (!r || r->enabled(fixCleanup3_3_0)) { return MantissaRange::MantissaScale::Large330;