From 8cfea5a9d1aafdc80f8461cabdc86ed46bb16463 Mon Sep 17 00:00:00 2001 From: Scott Determan Date: Fri, 22 Mar 2024 17:02:17 -0400 Subject: [PATCH] fixXChainRewardRounding: round reward shares down: (#4933) When calculating reward shares, the amount should always be rounded down. If the `fixUniversalNumber` amendment is not active, this works correctly. If it is not active, then the amount is incorrectly rounded up. This patch introduces an amendment so it will be rounded down. --- src/ripple/app/tx/impl/XChainBridge.cpp | 8 +++++++- src/ripple/protocol/Feature.h | 3 ++- src/ripple/protocol/impl/Feature.cpp | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ripple/app/tx/impl/XChainBridge.cpp b/src/ripple/app/tx/impl/XChainBridge.cpp index 934a88f55..c952aef23 100644 --- a/src/ripple/app/tx/impl/XChainBridge.cpp +++ b/src/ripple/app/tx/impl/XChainBridge.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,6 @@ #include #include #include - #include #include @@ -675,6 +675,12 @@ finalizeClaimHelper( // if the transfer failed, distribute the pool for "OnTransferFail" // cases (the attesters did their job) STAmount const share = [&] { + auto const round_mode = + innerSb.rules().enabled(fixXChainRewardRounding) + ? Number::rounding_mode::downward + : Number::getround(); + saveNumberRoundMode _{Number::setround(round_mode)}; + STAmount const den{rewardAccounts.size()}; return divide(rewardPool, den, rewardPool.issue()); }(); diff --git a/src/ripple/protocol/Feature.h b/src/ripple/protocol/Feature.h index 87c4806ab..e29db1ac7 100644 --- a/src/ripple/protocol/Feature.h +++ b/src/ripple/protocol/Feature.h @@ -74,7 +74,7 @@ namespace detail { // Feature.cpp. Because it's only used to reserve storage, and determine how // large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than // the actual number of amendments. A LogicError on startup will verify this. -static constexpr std::size_t numFeatures = 93; +static constexpr std::size_t numFeatures = 94; /** Amendments that this server supports and the default voting behavior. Whether they are enabled depends on the Rules defined in the validated @@ -381,6 +381,7 @@ extern uint256 const fixInnerObjTemplate; extern uint256 const fixAMMOverflowOffer; extern uint256 const featurePriceOracle; extern uint256 const fixEmptyDID; +extern uint256 const fixXChainRewardRounding; } // namespace ripple diff --git a/src/ripple/protocol/impl/Feature.cpp b/src/ripple/protocol/impl/Feature.cpp index f6174c23c..7b239e13b 100644 --- a/src/ripple/protocol/impl/Feature.cpp +++ b/src/ripple/protocol/impl/Feature.cpp @@ -487,6 +487,7 @@ REGISTER_FIX (fixInnerObjTemplate, Supported::yes, VoteBehavior::De REGISTER_FIX (fixAMMOverflowOffer, Supported::yes, VoteBehavior::DefaultYes); REGISTER_FEATURE(PriceOracle, Supported::yes, VoteBehavior::DefaultNo); REGISTER_FIX (fixEmptyDID, Supported::yes, VoteBehavior::DefaultNo); +REGISTER_FIX (fixXChainRewardRounding, Supported::yes, VoteBehavior::DefaultNo); // The following amendments are obsolete, but must remain supported // because they could potentially get enabled.