Compare commits

..

5 Commits

Author SHA1 Message Date
Richard Holland
a4e6dd2d3e clang 2024-10-12 18:49:14 +11:00
Richard Holland
e305c6b52a use std::lexicographical_compare_three_way for uint spaceship operator 2024-10-12 17:05:21 +11:00
Richard Holland
d921c87c88 also update max transactions for tx queue 2024-10-11 09:59:04 +11:00
RichardAH
7b94d3d99d increase txn in ledger target to 1000 (#372) 2024-10-11 08:21:23 +10:00
Denis Angell
79d83bd424 fix240911 (#363) 2024-09-11 13:43:03 +10:00
9 changed files with 580 additions and 8 deletions

View File

@@ -30,7 +30,7 @@ jobs:
git diff --exit-code | tee "clang-format.patch" git diff --exit-code | tee "clang-format.patch"
- name: Upload patch - name: Upload patch
if: failure() && steps.assert.outcome == 'failure' if: failure() && steps.assert.outcome == 'failure'
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v3
continue-on-error: true continue-on-error: true
with: with:
name: clang-format.patch name: clang-format.patch

View File

@@ -18,7 +18,7 @@ jobs:
git diff --exit-code | tee "levelization.patch" git diff --exit-code | tee "levelization.patch"
- name: Upload patch - name: Upload patch
if: failure() && steps.assert.outcome == 'failure' if: failure() && steps.assert.outcome == 'failure'
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v3
continue-on-error: true continue-on-error: true
with: with:
name: levelization.patch name: levelization.patch

View File

@@ -111,7 +111,7 @@ public:
std::uint32_t minimumTxnInLedgerSA = 1000; std::uint32_t minimumTxnInLedgerSA = 1000;
/// Number of transactions per ledger that fee escalation "works /// Number of transactions per ledger that fee escalation "works
/// towards". /// towards".
std::uint32_t targetTxnInLedger = 256; std::uint32_t targetTxnInLedger = 1000;
/** Optional maximum allowed value of transactions per ledger before /** Optional maximum allowed value of transactions per ledger before
fee escalation kicks in. By default, the maximum is an emergent fee escalation kicks in. By default, the maximum is an emergent
property of network, validator, and consensus performance. This property of network, validator, and consensus performance. This

View File

@@ -1923,6 +1923,7 @@ Transactor::operator()()
uint32_t lgrCur = view().seq(); uint32_t lgrCur = view().seq();
bool const has240819 = view().rules().enabled(fix240819); bool const has240819 = view().rules().enabled(fix240819);
bool const has240911 = view().rules().enabled(fix240911);
auto const& sfRewardFields = auto const& sfRewardFields =
*(ripple::SField::knownCodeToField.at(917511 - has240819)); *(ripple::SField::knownCodeToField.at(917511 - has240819));
@@ -1971,7 +1972,11 @@ Transactor::operator()()
uint32_t lgrElapsed = lgrCur - lgrLast; uint32_t lgrElapsed = lgrCur - lgrLast;
// overflow safety // overflow safety
if (lgrElapsed > lgrCur || lgrElapsed > lgrLast || lgrElapsed == 0) if (!has240911 &&
(lgrElapsed > lgrCur || lgrElapsed > lgrLast ||
lgrElapsed == 0))
continue;
if (has240911 && (lgrElapsed > lgrCur || lgrElapsed == 0))
continue; continue;
uint64_t accum = sle->getFieldU64(sfRewardAccumulator); uint64_t accum = sle->getFieldU64(sfRewardAccumulator);

View File

@@ -549,7 +549,8 @@ using uint128 = base_uint<128>;
using uint160 = base_uint<160>; using uint160 = base_uint<160>;
using uint256 = base_uint<256>; using uint256 = base_uint<256>;
template <std::size_t Bits, class Tag> /*
* template <std::size_t Bits, class Tag>
[[nodiscard]] inline constexpr std::strong_ordering [[nodiscard]] inline constexpr std::strong_ordering
operator<=>(base_uint<Bits, Tag> const& lhs, base_uint<Bits, Tag> const& rhs) operator<=>(base_uint<Bits, Tag> const& lhs, base_uint<Bits, Tag> const& rhs)
{ {
@@ -570,6 +571,19 @@ operator<=>(base_uint<Bits, Tag> const& lhs, base_uint<Bits, Tag> const& rhs)
return (*ret.first > *ret.second) ? std::strong_ordering::greater return (*ret.first > *ret.second) ? std::strong_ordering::greater
: std::strong_ordering::less; : std::strong_ordering::less;
} }
*/
template <std::size_t Bits, class Tag>
[[nodiscard]] inline constexpr std::strong_ordering
operator<=>(base_uint<Bits, Tag> const& lhs, base_uint<Bits, Tag> const& rhs)
{
return std::lexicographical_compare_three_way(
lhs.cbegin(),
lhs.cend(),
rhs.cbegin(),
rhs.cend(),
std::compare_three_way{});
}
template <std::size_t Bits, typename Tag> template <std::size_t Bits, typename Tag>
[[nodiscard]] inline constexpr bool [[nodiscard]] inline constexpr bool

View File

@@ -240,7 +240,7 @@ public:
bool LEDGER_REPLAY = false; bool LEDGER_REPLAY = false;
// Work queue limits // Work queue limits
int MAX_TRANSACTIONS = 250; int MAX_TRANSACTIONS = 1000;
static constexpr int MAX_JOB_QUEUE_TX = 1000; static constexpr int MAX_JOB_QUEUE_TX = 1000;
static constexpr int MIN_JOB_QUEUE_TX = 100; static constexpr int MIN_JOB_QUEUE_TX = 100;

View File

@@ -74,7 +74,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how // 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 // 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. // the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 72; static constexpr std::size_t numFeatures = 73;
/** Amendments that this server supports and the default voting behavior. /** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated Whether they are enabled depends on the Rules defined in the validated
@@ -360,6 +360,7 @@ extern uint256 const featureZeroB2M;
extern uint256 const fixNSDelete; extern uint256 const fixNSDelete;
extern uint256 const fix240819; extern uint256 const fix240819;
extern uint256 const fixPageCap; extern uint256 const fixPageCap;
extern uint256 const fix240911;
} // namespace ripple } // namespace ripple

View File

@@ -466,6 +466,7 @@ REGISTER_FEATURE(ZeroB2M, Supported::yes, VoteBehavior::De
REGISTER_FIX (fixNSDelete, Supported::yes, VoteBehavior::DefaultNo); REGISTER_FIX (fixNSDelete, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fix240819, Supported::yes, VoteBehavior::DefaultYes); REGISTER_FIX (fix240819, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fixPageCap, Supported::yes, VoteBehavior::DefaultYes); REGISTER_FIX (fixPageCap, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fix240911, Supported::yes, VoteBehavior::DefaultYes);
// The following amendments are obsolete, but must remain supported // The following amendments are obsolete, but must remain supported
// because they could potentially get enabled. // because they could potentially get enabled.

View File

@@ -5020,6 +5020,550 @@ struct XahauGenesis_test : public beast::unit_test::suite
BEAST_EXPECT(asPercent == 4); BEAST_EXPECT(asPercent == 4);
} }
void
testDeposit(FeatureBitset features)
{
using namespace jtx;
using namespace std::chrono_literals;
testcase("test deposit");
Env env{*this, envconfig(), features - featureXahauGenesis};
double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
auto const user = Account("user");
env.fund(XRP(1000), user);
env.close();
// setup governance
auto const alice = Account("alice");
auto const bob = Account("bob");
auto const carol = Account("carol");
auto const david = Account("david");
auto const edward = Account("edward");
env.fund(XRP(10000), alice, bob, carol, david, edward);
env.close();
std::vector<AccountID> initial_members_ids{
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
setupGov(env, initial_members_ids);
// update reward delay
{
// this will be the new reward delay
// 100
std::vector<uint8_t> vote_data{
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
updateTopic(
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
}
// verify unl report does not exist
BEAST_EXPECT(hasUNLReport(env) == false);
// opt in claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
env(pay(alice, user, XRP(1000)));
env.close();
// close ledgers
for (int i = 0; i < 10; ++i)
{
env.close(10s);
}
// close claim ledger & time
STAmount const preUser = env.balance(user);
NetClock::time_point const preTime = lastClose(env);
std::uint32_t const preLedger = env.current()->seq();
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
// claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// trigger emitted txn
env.close();
// calculate rewards
bool const has240819 = env.current()->rules().enabled(fix240819);
STAmount const netReward =
rewardUserAmount(*acctSle, preLedger, rateDrops);
BEAST_EXPECT(netReward == (has240819 ? XRP(6.383333) : XRP(6.663333)));
// validate account fields
STAmount const postUser = preUser + netReward;
BEAST_EXPECT(expectAccountFields(
env,
user,
preLedger,
preLedger + 1,
has240819 ? (preUser - feesXRP) : postUser,
preTime));
BEAST_EXPECT(
postUser == (has240819 ? XRP(2005.383333) : XRP(2005.663333)));
}
void
testDepositWithdraw(FeatureBitset features)
{
using namespace jtx;
using namespace std::chrono_literals;
testcase("test deposit withdraw");
Env env{*this, envconfig(), features - featureXahauGenesis};
double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
auto const user = Account("user");
env.fund(XRP(1000), user);
env.close();
// setup governance
auto const alice = Account("alice");
auto const bob = Account("bob");
auto const carol = Account("carol");
auto const david = Account("david");
auto const edward = Account("edward");
env.fund(XRP(10000), alice, bob, carol, david, edward);
env.close();
std::vector<AccountID> initial_members_ids{
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
setupGov(env, initial_members_ids);
// update reward delay
{
// this will be the new reward delay
// 100
std::vector<uint8_t> vote_data{
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
updateTopic(
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
}
// verify unl report does not exist
BEAST_EXPECT(hasUNLReport(env) == false);
// opt in claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
env(pay(alice, user, XRP(1000)));
env.close();
env(pay(user, alice, XRP(1000)));
env.close();
// close ledgers
for (int i = 0; i < 10; ++i)
{
env.close(10s);
}
// close claim ledger & time
STAmount const preUser = env.balance(user);
NetClock::time_point const preTime = lastClose(env);
std::uint32_t const preLedger = env.current()->seq();
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
// claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// trigger emitted txn
env.close();
// calculate rewards
bool const has240819 = env.current()->rules().enabled(fix240819);
STAmount const netReward =
rewardUserAmount(*acctSle, preLedger, rateDrops);
BEAST_EXPECT(netReward == XRP(3.583333));
// validate account fields
STAmount const postUser = preUser + netReward;
BEAST_EXPECT(expectAccountFields(
env,
user,
preLedger,
preLedger + 1,
has240819 ? (preUser - feesXRP) : postUser,
preTime));
BEAST_EXPECT(postUser == XRP(1002.583323));
}
void
testDepositLate(FeatureBitset features)
{
using namespace jtx;
using namespace std::chrono_literals;
testcase("test deposit late");
Env env{*this, envconfig(), features - featureXahauGenesis};
double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
auto const user = Account("user");
env.fund(XRP(1000), user);
env.close();
// setup governance
auto const alice = Account("alice");
auto const bob = Account("bob");
auto const carol = Account("carol");
auto const david = Account("david");
auto const edward = Account("edward");
env.fund(XRP(10000), alice, bob, carol, david, edward);
env.close();
std::vector<AccountID> initial_members_ids{
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
setupGov(env, initial_members_ids);
// update reward delay
{
// this will be the new reward delay
// 100
std::vector<uint8_t> vote_data{
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
updateTopic(
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
}
// verify unl report does not exist
BEAST_EXPECT(hasUNLReport(env) == false);
// opt in claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// close ledgers
for (int i = 0; i < 10; ++i)
{
env.close(10s);
}
env(pay(alice, user, XRP(1000)));
env.close();
// close claim ledger & time
STAmount const preUser = env.balance(user);
NetClock::time_point const preTime = lastClose(env);
std::uint32_t const preLedger = env.current()->seq();
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
// claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// trigger emitted txn
env.close();
// calculate rewards
bool const has240819 = env.current()->rules().enabled(fix240819);
STAmount const netReward =
rewardUserAmount(*acctSle, preLedger, rateDrops);
BEAST_EXPECT(netReward == (has240819 ? XRP(3.606666) : XRP(6.663333)));
// validate account fields
STAmount const postUser = preUser + netReward;
BEAST_EXPECT(expectAccountFields(
env,
user,
preLedger,
preLedger + 1,
has240819 ? (preUser - feesXRP) : postUser,
preTime));
BEAST_EXPECT(
postUser == (has240819 ? XRP(2002.606666) : XRP(2005.663333)));
}
void
testDepositWithdrawLate(FeatureBitset features)
{
using namespace jtx;
using namespace std::chrono_literals;
testcase("test deposit late withdraw");
Env env{*this, envconfig(), features - featureXahauGenesis};
double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
auto const user = Account("user");
env.fund(XRP(1000), user);
env.close();
// setup governance
auto const alice = Account("alice");
auto const bob = Account("bob");
auto const carol = Account("carol");
auto const david = Account("david");
auto const edward = Account("edward");
env.fund(XRP(10000), alice, bob, carol, david, edward);
env.close();
std::vector<AccountID> initial_members_ids{
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
setupGov(env, initial_members_ids);
// update reward delay
{
// this will be the new reward delay
// 100
std::vector<uint8_t> vote_data{
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
updateTopic(
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
}
// verify unl report does not exist
BEAST_EXPECT(hasUNLReport(env) == false);
// opt in claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// close ledgers
for (int i = 0; i < 10; ++i)
{
env.close(10s);
}
env(pay(alice, user, XRP(1000)));
env.close();
env(pay(user, alice, XRP(1000)));
env.close();
// close claim ledger & time
STAmount const preUser = env.balance(user);
NetClock::time_point const preTime = lastClose(env);
std::uint32_t const preLedger = env.current()->seq();
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
// claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// trigger emitted txn
env.close();
// calculate rewards
bool const has240819 = env.current()->rules().enabled(fix240819);
STAmount const netReward =
rewardUserAmount(*acctSle, preLedger, rateDrops);
BEAST_EXPECT(netReward == (has240819 ? XRP(3.583333) : XRP(6.149999)));
// validate account fields
STAmount const postUser = preUser + netReward;
BEAST_EXPECT(expectAccountFields(
env,
user,
preLedger,
preLedger + 1,
has240819 ? (preUser - feesXRP) : postUser,
preTime));
BEAST_EXPECT(
postUser == (has240819 ? XRP(1002.583323) : XRP(1005.149989)));
}
void
testNoClaim(FeatureBitset features)
{
using namespace jtx;
using namespace std::chrono_literals;
testcase("test no claim");
Env env{*this, envconfig(), features - featureXahauGenesis};
double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
auto const user = Account("user");
env.fund(XRP(1000), user);
env.close();
// setup governance
auto const alice = Account("alice");
auto const bob = Account("bob");
auto const carol = Account("carol");
auto const david = Account("david");
auto const edward = Account("edward");
env.fund(XRP(10000), alice, bob, carol, david, edward);
env.close();
std::vector<AccountID> initial_members_ids{
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
setupGov(env, initial_members_ids);
// update reward delay
{
// this will be the new reward delay
// 100
std::vector<uint8_t> vote_data{
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
updateTopic(
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
}
// verify unl report does not exist
BEAST_EXPECT(hasUNLReport(env) == false);
// opt in claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// close ledgers (2 cycles)
for (int i = 0; i < 20; ++i)
{
env.close(10s);
}
// close claim ledger & time
STAmount const preUser = env.balance(user);
NetClock::time_point const preTime = lastClose(env);
std::uint32_t const preLedger = env.current()->seq();
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
// claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// trigger emitted txn
env.close();
// calculate rewards
bool const hasFix = env.current()->rules().enabled(fix240819) &&
env.current()->rules().enabled(fix240911);
STAmount const netReward =
rewardUserAmount(*acctSle, preLedger, rateDrops);
BEAST_EXPECT(netReward == (hasFix ? XRP(3.329999) : XRP(3.329999)));
// validate account fields
STAmount const postUser = preUser + netReward;
BEAST_EXPECT(expectAccountFields(
env,
user,
preLedger,
preLedger + 1,
hasFix ? (preUser - feesXRP) : postUser,
preTime));
BEAST_EXPECT(
postUser == (hasFix ? XRP(1002.329999) : XRP(1002.329999)));
}
void
testNoClaimLate(FeatureBitset features)
{
using namespace jtx;
using namespace std::chrono_literals;
testcase("test no claim late");
Env env{*this, envconfig(), features - featureXahauGenesis};
double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
auto const user = Account("user");
env.fund(XRP(1000), user);
env.close();
// setup governance
auto const alice = Account("alice");
auto const bob = Account("bob");
auto const carol = Account("carol");
auto const david = Account("david");
auto const edward = Account("edward");
env.fund(XRP(10000), alice, bob, carol, david, edward);
env.close();
std::vector<AccountID> initial_members_ids{
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
setupGov(env, initial_members_ids);
// update reward delay
{
// this will be the new reward delay
// 100
std::vector<uint8_t> vote_data{
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
updateTopic(
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
}
// verify unl report does not exist
BEAST_EXPECT(hasUNLReport(env) == false);
// opt in claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// close ledgers (2 cycles)
for (int i = 0; i < 20; ++i)
{
env.close(10s);
}
env(pay(alice, user, XRP(1000)));
env.close();
// close claim ledger & time
STAmount const preUser = env.balance(user);
NetClock::time_point const preTime = lastClose(env);
std::uint32_t const preLedger = env.current()->seq();
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
// claim reward
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
env.close();
// trigger emitted txn
env.close();
// calculate rewards
bool const hasFix = env.current()->rules().enabled(fix240819) &&
env.current()->rules().enabled(fix240911);
STAmount const netReward =
rewardUserAmount(*acctSle, preLedger, rateDrops);
BEAST_EXPECT(netReward == (hasFix ? XRP(3.479999) : XRP(6.663333)));
// validate account fields
STAmount const postUser = preUser + netReward;
BEAST_EXPECT(expectAccountFields(
env,
user,
preLedger,
preLedger + 1,
hasFix ? (preUser - feesXRP) : postUser,
preTime));
BEAST_EXPECT(
postUser == (hasFix ? XRP(2002.479999) : XRP(2005.663333)));
}
void void
testRewardHookWithFeats(FeatureBitset features) testRewardHookWithFeats(FeatureBitset features)
{ {
@@ -5038,6 +5582,12 @@ struct XahauGenesis_test : public beast::unit_test::suite
testInvalidElapsed0(features); testInvalidElapsed0(features);
testInvalidElapsedNegative(features); testInvalidElapsedNegative(features);
testCompoundInterest(features); testCompoundInterest(features);
testDeposit(features);
testDepositWithdraw(features);
testDepositLate(features);
testDepositWithdrawLate(features);
testNoClaim(features);
testNoClaimLate(features);
} }
void void
@@ -5056,8 +5606,9 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace test::jtx; using namespace test::jtx;
auto const sa = supported_amendments(); auto const sa = supported_amendments();
testGovernHookWithFeats(sa); testGovernHookWithFeats(sa);
testRewardHookWithFeats(sa - fix240819);
testRewardHookWithFeats(sa); testRewardHookWithFeats(sa);
testRewardHookWithFeats(sa - fix240819);
testRewardHookWithFeats(sa - fix240819 - fix240911);
} }
}; };