chore: Set ColumnLimit to 120 in clang-format (#6288)

This change updates the ColumnLimit from 80 to 120, and applies clang-format to reformat the code.
This commit is contained in:
Ayaz Salikhov
2026-01-28 18:09:50 +00:00
committed by GitHub
parent 92046785d1
commit 5f638f5553
1016 changed files with 26918 additions and 66660 deletions

View File

@@ -12,36 +12,24 @@ namespace test {
class ReducedOffer_test : public beast::unit_test::suite
{
static auto
ledgerEntryOffer(
jtx::Env& env,
jtx::Account const& acct,
std::uint32_t offer_seq)
ledgerEntryOffer(jtx::Env& env, jtx::Account const& acct, std::uint32_t offer_seq)
{
Json::Value jvParams;
jvParams[jss::offer][jss::account] = acct.human();
jvParams[jss::offer][jss::seq] = offer_seq;
return env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
return env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
}
static bool
offerInLedger(
jtx::Env& env,
jtx::Account const& acct,
std::uint32_t offerSeq)
offerInLedger(jtx::Env& env, jtx::Account const& acct, std::uint32_t offerSeq)
{
Json::Value ledgerOffer = ledgerEntryOffer(env, acct, offerSeq);
return !(
ledgerOffer.isMember(jss::error) &&
ledgerOffer[jss::error].asString() == "entryNotFound");
return !(ledgerOffer.isMember(jss::error) && ledgerOffer[jss::error].asString() == "entryNotFound");
}
// Common code to clean up unneeded offers.
static void
cleanupOldOffers(
jtx::Env& env,
std::initializer_list<std::pair<jtx::Account const&, std::uint32_t>>
list)
cleanupOldOffers(jtx::Env& env, std::initializer_list<std::pair<jtx::Account const&, std::uint32_t>> list)
{
for (auto [acct, offerSeq] : list)
env(offer_cancel(acct, offerSeq));
@@ -80,10 +68,8 @@ public:
// 2. Collects the results, and
// 3. Cleans up for the next offer pair.
// Returns 1 if the crossed offer has a bad rate for the book.
auto exerciseOfferPair =
[this, &env, &alice, &bob](
Amounts const& inLedger,
Amounts const& newOffer) -> unsigned int {
auto exerciseOfferPair = [this, &env, &alice, &bob](
Amounts const& inLedger, Amounts const& newOffer) -> unsigned int {
// Put inLedger offer in the ledger so newOffer can cross it.
std::uint32_t const aliceOfferSeq = env.seq(alice);
env(offer(alice, inLedger.in, inLedger.out));
@@ -94,8 +80,7 @@ public:
std::uint32_t const bobOfferSeq = env.seq(bob);
STAmount const bobInitialBalance = env.balance(bob);
STAmount const bobsFee = env.current()->fees().base;
env(offer(bob, newOffer.in, newOffer.out, tfSell),
fee(bobsFee));
env(offer(bob, newOffer.in, newOffer.out, tfSell), fee(bobsFee));
env.close();
STAmount const bobFinalBalance = env.balance(bob);
@@ -109,20 +94,16 @@ public:
// bob's offer should be in the ledger, but reduced in size.
unsigned int badRate = 1;
{
Json::Value bobOffer =
ledgerEntryOffer(env, bob, bobOfferSeq);
Json::Value bobOffer = ledgerEntryOffer(env, bob, bobOfferSeq);
STAmount const reducedTakerGets = amountFromJson(
sfTakerGets, bobOffer[jss::node][sfTakerGets.jsonName]);
STAmount const reducedTakerPays = amountFromJson(
sfTakerPays, bobOffer[jss::node][sfTakerPays.jsonName]);
STAmount const bobGot =
env.balance(bob) + bobsFee - bobInitialBalance;
STAmount const reducedTakerGets =
amountFromJson(sfTakerGets, bobOffer[jss::node][sfTakerGets.jsonName]);
STAmount const reducedTakerPays =
amountFromJson(sfTakerPays, bobOffer[jss::node][sfTakerPays.jsonName]);
STAmount const bobGot = env.balance(bob) + bobsFee - bobInitialBalance;
BEAST_EXPECT(reducedTakerPays < newOffer.in);
BEAST_EXPECT(reducedTakerGets < newOffer.out);
STAmount const inLedgerRate =
Quality(Amounts{reducedTakerPays, reducedTakerGets})
.rate();
STAmount const inLedgerRate = Quality(Amounts{reducedTakerPays, reducedTakerGets}).rate();
badRate = inLedgerRate > initialRate ? 1 : 0;
@@ -133,11 +114,8 @@ public:
// was computed.
if (badRate == 0)
{
STAmount const tweakedTakerPays =
reducedTakerPays + drops(1);
STAmount const tweakedRate =
Quality(Amounts{tweakedTakerPays, reducedTakerGets})
.rate();
STAmount const tweakedTakerPays = reducedTakerPays + drops(1);
STAmount const tweakedRate = Quality(Amounts{tweakedTakerPays, reducedTakerGets}).rate();
BEAST_EXPECT(tweakedRate > initialRate);
}
#if 0
@@ -158,29 +136,23 @@ public:
// In preparation for the next iteration make sure the two
// offers are gone from the ledger.
cleanupOldOffers(
env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
cleanupOldOffers(env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
return badRate;
};
// bob's offer (the new offer) is the same every time:
Amounts const bobsOffer{
STAmount(XRP(1)), STAmount(USD.issue(), 1, 0)};
Amounts const bobsOffer{STAmount(XRP(1)), STAmount(USD.issue(), 1, 0)};
// alice's offer has a slightly smaller TakerPays with each
// iteration. This should mean that the size of the offer bob
// places in the ledger should increase with each iteration.
unsigned int blockedCount = 0;
for (std::uint64_t mantissaReduce = 1'000'000'000ull;
mantissaReduce <= 5'000'000'000ull;
for (std::uint64_t mantissaReduce = 1'000'000'000ull; mantissaReduce <= 5'000'000'000ull;
mantissaReduce += 20'000'000ull)
{
STAmount aliceUSD{
bobsOffer.out.issue(),
bobsOffer.out.mantissa() - mantissaReduce,
bobsOffer.out.exponent()};
STAmount aliceXRP{
bobsOffer.in.issue(), bobsOffer.in.mantissa() - 1};
bobsOffer.out.issue(), bobsOffer.out.mantissa() - mantissaReduce, bobsOffer.out.exponent()};
STAmount aliceXRP{bobsOffer.in.issue(), bobsOffer.in.mantissa() - 1};
Amounts alicesOffer{aliceUSD, aliceXRP};
blockedCount += exerciseOfferPair(alicesOffer, bobsOffer);
}
@@ -220,10 +192,8 @@ public:
// 1. Exercises one offer pair,
// 2. Collects the results, and
// 3. Cleans up for the next offer pair.
auto exerciseOfferPair =
[this, &env, &alice, &bob](
Amounts const& inLedger,
Amounts const& newOffer) -> unsigned int {
auto exerciseOfferPair = [this, &env, &alice, &bob](
Amounts const& inLedger, Amounts const& newOffer) -> unsigned int {
// Get the inLedger offer into the ledger so newOffer can cross
// it.
STAmount const initialRate = Quality(inLedger).rate();
@@ -243,30 +213,23 @@ public:
{
// If the in-ledger offer was not consumed then further
// results are meaningless.
cleanupOldOffers(
env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
cleanupOldOffers(env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
return 1;
}
// alice's offer should still be in the ledger, but reduced in
// size.
unsigned int badRate = 1;
{
Json::Value aliceOffer =
ledgerEntryOffer(env, alice, aliceOfferSeq);
Json::Value aliceOffer = ledgerEntryOffer(env, alice, aliceOfferSeq);
STAmount const reducedTakerGets = amountFromJson(
sfTakerGets,
aliceOffer[jss::node][sfTakerGets.jsonName]);
STAmount const reducedTakerPays = amountFromJson(
sfTakerPays,
aliceOffer[jss::node][sfTakerPays.jsonName]);
STAmount const aliceGot =
env.balance(alice) - aliceInitialBalance;
STAmount const reducedTakerGets =
amountFromJson(sfTakerGets, aliceOffer[jss::node][sfTakerGets.jsonName]);
STAmount const reducedTakerPays =
amountFromJson(sfTakerPays, aliceOffer[jss::node][sfTakerPays.jsonName]);
STAmount const aliceGot = env.balance(alice) - aliceInitialBalance;
BEAST_EXPECT(reducedTakerPays < inLedger.in);
BEAST_EXPECT(reducedTakerGets < inLedger.out);
STAmount const inLedgerRate =
Quality(Amounts{reducedTakerPays, reducedTakerGets})
.rate();
STAmount const inLedgerRate = Quality(Amounts{reducedTakerPays, reducedTakerGets}).rate();
badRate = inLedgerRate > initialRate ? 1 : 0;
// If the inLedgerRate is less than initial rate, then
@@ -276,11 +239,8 @@ public:
// was computed.
if (badRate == 0)
{
STAmount const tweakedTakerPays =
reducedTakerPays + drops(1);
STAmount const tweakedRate =
Quality(Amounts{tweakedTakerPays, reducedTakerGets})
.rate();
STAmount const tweakedTakerPays = reducedTakerPays + drops(1);
STAmount const tweakedRate = Quality(Amounts{tweakedTakerPays, reducedTakerGets}).rate();
BEAST_EXPECT(tweakedRate > initialRate);
}
#if 0
@@ -302,29 +262,23 @@ public:
// In preparation for the next iteration make sure the two
// offers are gone from the ledger.
cleanupOldOffers(
env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
cleanupOldOffers(env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
return badRate;
};
// alice's offer (the old offer) is the same every time:
Amounts const aliceOffer{
STAmount(XRP(1)), STAmount(USD.issue(), 1, 0)};
Amounts const aliceOffer{STAmount(XRP(1)), STAmount(USD.issue(), 1, 0)};
// bob's offer has a slightly smaller TakerPays with each iteration.
// This should mean that the size of the offer alice leaves in the
// ledger should increase with each iteration.
unsigned int blockedCount = 0;
for (std::uint64_t mantissaReduce = 1'000'000'000ull;
mantissaReduce <= 4'000'000'000ull;
for (std::uint64_t mantissaReduce = 1'000'000'000ull; mantissaReduce <= 4'000'000'000ull;
mantissaReduce += 20'000'000ull)
{
STAmount bobUSD{
aliceOffer.out.issue(),
aliceOffer.out.mantissa() - mantissaReduce,
aliceOffer.out.exponent()};
STAmount bobXRP{
aliceOffer.in.issue(), aliceOffer.in.mantissa() - 1};
aliceOffer.out.issue(), aliceOffer.out.mantissa() - mantissaReduce, aliceOffer.out.exponent()};
STAmount bobXRP{aliceOffer.in.issue(), aliceOffer.in.mantissa() - 1};
Amounts bobsOffer{bobUSD, bobXRP};
blockedCount += exerciseOfferPair(aliceOffer, bobsOffer);
@@ -357,8 +311,7 @@ public:
env.trust(USD(1000), alice, bob);
int blockedOrderBookCount = 0;
for (STAmount initialBobUSD = USD(0.45); initialBobUSD <= USD(1);
initialBobUSD += USD(0.025))
for (STAmount initialBobUSD = USD(0.45); initialBobUSD <= USD(1); initialBobUSD += USD(0.025))
{
// underfund bob's offer
env(pay(gw, bob, initialBobUSD));
@@ -380,8 +333,7 @@ public:
// then we use that as evidence that bob's offer blocked the
// order book.
{
bool const bobsOfferGone =
!offerInLedger(env, bob, bobOfferSeq);
bool const bobsOfferGone = !offerInLedger(env, bob, bobOfferSeq);
STAmount const aliceBalanceUSD = env.balance(alice, USD);
// Sanity check the ledger if alice got USD.
@@ -400,16 +352,13 @@ public:
// In preparation for the next iteration clean up any
// leftover offers.
cleanupOldOffers(
env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
cleanupOldOffers(env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
// Zero out alice's and bob's USD balances.
if (STAmount const aliceBalance = env.balance(alice, USD);
aliceBalance.signum() > 0)
if (STAmount const aliceBalance = env.balance(alice, USD); aliceBalance.signum() > 0)
env(pay(alice, gw, aliceBalance));
if (STAmount const bobBalance = env.balance(bob, USD);
bobBalance.signum() > 0)
if (STAmount const bobBalance = env.balance(bob, USD); bobBalance.signum() > 0)
env(pay(bob, gw, bobBalance));
env.close();
@@ -448,17 +397,13 @@ public:
env.trust(USD(1000), alice, bob);
env.trust(EUR(1000), alice, bob);
STAmount const eurOffer(
EUR.issue(), /*mantissa*/ 2957, /*exponent*/ -76);
STAmount const usdOffer(
USD.issue(), /*mantissa*/ 7109, /*exponent*/ -76);
STAmount const eurOffer(EUR.issue(), /*mantissa*/ 2957, /*exponent*/ -76);
STAmount const usdOffer(USD.issue(), /*mantissa*/ 7109, /*exponent*/ -76);
STAmount const endLoop(
USD.issue(), /*mantissa*/ 50, /*exponent*/ -81);
STAmount const endLoop(USD.issue(), /*mantissa*/ 50, /*exponent*/ -81);
int blockedOrderBookCount = 0;
for (STAmount initialBobUSD = tinyUSD; initialBobUSD <= endLoop;
initialBobUSD += tinyUSD)
for (STAmount initialBobUSD = tinyUSD; initialBobUSD <= endLoop; initialBobUSD += tinyUSD)
{
// underfund bob's offer
env(pay(gw, bob, initialBobUSD));
@@ -478,8 +423,7 @@ public:
// Examine the aftermath of alice's offer.
{
bool const bobsOfferGone =
!offerInLedger(env, bob, bobOfferSeq);
bool const bobsOfferGone = !offerInLedger(env, bob, bobOfferSeq);
STAmount aliceBalanceUSD = env.balance(alice, USD);
#if 0
std::cout
@@ -505,14 +449,11 @@ public:
// In preparation for the next iteration clean up any
// leftover offers.
cleanupOldOffers(
env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
cleanupOldOffers(env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}});
// Zero out alice's and bob's IOU balances.
auto zeroBalance = [&env, &gw](
Account const& acct, IOU const& iou) {
if (STAmount const balance = env.balance(acct, iou);
balance.signum() > 0)
auto zeroBalance = [&env, &gw](Account const& acct, IOU const& iou) {
if (STAmount const balance = env.balance(acct, iou); balance.signum() > 0)
env(pay(acct, gw, balance));
};
@@ -532,10 +473,8 @@ public:
Amounts
jsonOfferToAmounts(Json::Value const& json)
{
STAmount const in =
amountFromJson(sfTakerPays, json[sfTakerPays.jsonName]);
STAmount const out =
amountFromJson(sfTakerGets, json[sfTakerGets.jsonName]);
STAmount const in = amountFromJson(sfTakerPays, json[sfTakerPays.jsonName]);
STAmount const out = amountFromJson(sfTakerGets, json[sfTakerGets.jsonName]);
return {in, out};
}
@@ -558,8 +497,7 @@ public:
// Make one test run without fixReducedOffersV2 and one with.
for (FeatureBitset features :
{testable_amendments() - fixReducedOffersV2,
testable_amendments() | fixReducedOffersV2})
{testable_amendments() - fixReducedOffersV2, testable_amendments() | fixReducedOffersV2})
{
// Make sure none of the offers we generate are under funded.
Env env{*this, features};
@@ -581,17 +519,14 @@ public:
// 2. Collects the results, and
// 3. Cleans up for the next offer trio.
auto exerciseOfferTrio =
[this, &env, &alice, &bob, &carol, &USD](
Amounts const& carolOffer) -> unsigned int {
[this, &env, &alice, &bob, &carol, &USD](Amounts const& carolOffer) -> unsigned int {
// alice submits an offer that may become a blocker.
std::uint32_t const aliceOfferSeq = env.seq(alice);
static Amounts const aliceInitialOffer(USD(2), drops(3382562));
env(offer(alice, aliceInitialOffer.in, aliceInitialOffer.out));
env.close();
STAmount const initialRate =
Quality(jsonOfferToAmounts(ledgerEntryOffer(
env, alice, aliceOfferSeq)[jss::node]))
.rate();
Quality(jsonOfferToAmounts(ledgerEntryOffer(env, alice, aliceOfferSeq)[jss::node])).rate();
// bob submits an offer that is more desirable than alice's
std::uint32_t const bobOfferSeq = env.seq(bob);
@@ -601,39 +536,29 @@ public:
// Now carol's offer consumes bob's and partially crosses
// alice's. The tfSell flag is important.
std::uint32_t const carolOfferSeq = env.seq(carol);
env(offer(carol, carolOffer.in, carolOffer.out),
txflags(tfSell));
env(offer(carol, carolOffer.in, carolOffer.out), txflags(tfSell));
env.close();
// carol's offer should not have made it into the ledger and
// bob's offer should be fully consumed.
if (!BEAST_EXPECT(
!offerInLedger(env, carol, carolOfferSeq) &&
!offerInLedger(env, bob, bobOfferSeq)))
if (!BEAST_EXPECT(!offerInLedger(env, carol, carolOfferSeq) && !offerInLedger(env, bob, bobOfferSeq)))
{
// If carol's or bob's offers are still in the ledger then
// further results are meaningless.
cleanupOldOffers(
env,
{{alice, aliceOfferSeq},
{bob, bobOfferSeq},
{carol, carolOfferSeq}});
cleanupOldOffers(env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}, {carol, carolOfferSeq}});
return 1;
}
// alice's offer should still be in the ledger, but reduced in
// size.
unsigned int badRate = 1;
{
Json::Value aliceOffer =
ledgerEntryOffer(env, alice, aliceOfferSeq);
Json::Value aliceOffer = ledgerEntryOffer(env, alice, aliceOfferSeq);
Amounts aliceReducedOffer =
jsonOfferToAmounts(aliceOffer[jss::node]);
Amounts aliceReducedOffer = jsonOfferToAmounts(aliceOffer[jss::node]);
BEAST_EXPECT(aliceReducedOffer.in < aliceInitialOffer.in);
BEAST_EXPECT(aliceReducedOffer.out < aliceInitialOffer.out);
STAmount const inLedgerRate =
Quality(aliceReducedOffer).rate();
STAmount const inLedgerRate = Quality(aliceReducedOffer).rate();
badRate = inLedgerRate > initialRate ? 1 : 0;
// If the inLedgerRate is less than initial rate, then
@@ -648,10 +573,7 @@ public:
aliceReducedOffer.in.mantissa() + 1,
aliceReducedOffer.in.exponent(),
aliceReducedOffer.in.negative());
STAmount const tweakedRate =
Quality(
Amounts{aliceReducedOffer.in, tweakedTakerGets})
.rate();
STAmount const tweakedRate = Quality(Amounts{aliceReducedOffer.in, tweakedTakerGets}).rate();
BEAST_EXPECT(tweakedRate > initialRate);
}
#if 0
@@ -671,11 +593,7 @@ public:
// In preparation for the next iteration make sure all three
// offers are gone from the ledger.
cleanupOldOffers(
env,
{{alice, aliceOfferSeq},
{bob, bobOfferSeq},
{carol, carolOfferSeq}});
cleanupOldOffers(env, {{alice, aliceOfferSeq}, {bob, bobOfferSeq}, {carol, carolOfferSeq}});
return badRate;
};
@@ -686,8 +604,7 @@ public:
STAmount const step(increaseGets.issue(), 1, -8);
for (unsigned int i = 0; i < loopCount; ++i)
{
blockedCount += exerciseOfferTrio(
Amounts(drops(1642020), USD(1) + increaseGets));
blockedCount += exerciseOfferTrio(Amounts(drops(1642020), USD(1) + increaseGets));
increaseGets += step;
}
}