Skip to content

Commit 61672ad

Browse files
authored
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.
1 parent cea4309 commit 61672ad

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/ripple/app/tx/impl/XChainBridge.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <ripple/app/tx/impl/Transactor.h>
2323
#include <ripple/app/tx/impl/XChainBridge.h>
2424
#include <ripple/basics/Log.h>
25+
#include <ripple/basics/Number.h>
2526
#include <ripple/basics/XRPAmount.h>
2627
#include <ripple/basics/chrono.h>
2728
#include <ripple/beast/utility/Journal.h>
@@ -41,7 +42,6 @@
4142
#include <ripple/protocol/XChainAttestations.h>
4243
#include <ripple/protocol/digest.h>
4344
#include <ripple/protocol/st.h>
44-
4545
#include <unordered_map>
4646
#include <unordered_set>
4747

@@ -672,6 +672,12 @@ finalizeClaimHelper(
672672
// if the transfer failed, distribute the pool for "OnTransferFail"
673673
// cases (the attesters did their job)
674674
STAmount const share = [&] {
675+
auto const round_mode =
676+
innerSb.rules().enabled(fixXChainRewardRounding)
677+
? Number::rounding_mode::downward
678+
: Number::getround();
679+
saveNumberRoundMode _{Number::setround(round_mode)};
680+
675681
STAmount const den{rewardAccounts.size()};
676682
return divide(rewardPool, den, rewardPool.issue());
677683
}();

src/ripple/protocol/Feature.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace detail {
7474
// Feature.cpp. Because it's only used to reserve storage, and determine how
7575
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
7676
// the actual number of amendments. A LogicError on startup will verify this.
77-
static constexpr std::size_t numFeatures = 69;
77+
static constexpr std::size_t numFeatures = 70;
7878

7979
/** Amendments that this server supports and the default voting behavior.
8080
Whether they are enabled depends on the Rules defined in the validated
@@ -356,6 +356,7 @@ extern uint256 const fixNFTokenReserve;
356356
extern uint256 const fixInnerObjTemplate;
357357
extern uint256 const featurePriceOracle;
358358
extern uint256 const fixEmptyDID;
359+
extern uint256 const fixXChainRewardRounding;
359360

360361
} // namespace ripple
361362

src/ripple/protocol/impl/Feature.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ REGISTER_FIX (fixNFTokenReserve, Supported::yes, VoteBehavior::De
463463
REGISTER_FIX (fixInnerObjTemplate, Supported::yes, VoteBehavior::DefaultNo);
464464
REGISTER_FEATURE(PriceOracle, Supported::yes, VoteBehavior::DefaultNo);
465465
REGISTER_FIX (fixEmptyDID, Supported::yes, VoteBehavior::DefaultNo);
466+
REGISTER_FIX (fixXChainRewardRounding, Supported::yes, VoteBehavior::DefaultNo);
466467

467468
// The following amendments are obsolete, but must remain supported
468469
// because they could potentially get enabled.

0 commit comments

Comments
 (0)