Skip to content

Commit 87a2879

Browse files
committed
[FOLD] Revert AuthAccounts change and other fixes
* Create AuctionSlot on AMMCreate and update on AMMDeposit * Add assert to check for AuctionSlot
1 parent aa5c20a commit 87a2879

File tree

6 files changed

+51
-81
lines changed

6 files changed

+51
-81
lines changed

src/ripple/app/misc/impl/AMMUtils.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ std::uint16_t
138138
getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account)
139139
{
140140
using namespace std::chrono;
141+
// should not happen
142+
assert(
143+
!view.rules().enabled(fixInnerObjTemplate) ||
144+
ammSle.isFieldPresent(sfAuctionSlot));
141145
if (ammSle.isFieldPresent(sfAuctionSlot))
142146
{
143147
auto const& auctionSlot =
@@ -298,18 +302,14 @@ initializeFeeAuctionVote(
298302
voteSlots.push_back(voteEntry);
299303
ammSle->setFieldArray(sfVoteSlots, voteSlots);
300304
// AMM creator gets the auction slot for free.
301-
STObject auctionSlot = STObject::makeInnerObject(sfAuctionSlot, rules);
302-
if (!rules.enabled(fixInnerObjTemplate) &&
303-
ammSle->isFieldPresent(sfAuctionSlot))
305+
// AuctionSlot is created on AMMCreate and updated on AMMDeposit
306+
// when AMM is in an empty state
307+
if (!ammSle->isFieldPresent(sfAuctionSlot))
304308
{
305-
auto const& origAuctionSlot = ammSle->peekFieldObject(sfAuctionSlot);
306-
// this is executed on deposit from empty state.
307-
// pre-amendment code re-uses AuthAccounts
308-
// post-amendment code resets AuthAccounts
309-
if (origAuctionSlot.isFieldPresent(sfAuthAccounts))
310-
auctionSlot.setFieldArray(
311-
sfAuthAccounts, origAuctionSlot.getFieldArray(sfAuthAccounts));
309+
STObject auctionSlot = STObject::makeInnerObject(sfAuctionSlot, rules);
310+
ammSle->set(&auctionSlot);
312311
}
312+
STObject& auctionSlot = ammSle->peekFieldObject(sfAuctionSlot);
313313
auctionSlot.setAccountID(sfAccount, account);
314314
// current + sec in 24h
315315
auto const expiration = std::chrono::duration_cast<std::chrono::seconds>(
@@ -327,7 +327,6 @@ initializeFeeAuctionVote(
327327
auctionSlot.setFieldU16(sfDiscountedFee, dfee);
328328
else if (auctionSlot.isFieldPresent(sfDiscountedFee))
329329
auctionSlot.makeFieldAbsent(sfDiscountedFee);
330-
ammSle->set(&auctionSlot);
331330
}
332331

333332
} // namespace ripple

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,16 @@ applyBid(
173173
return {tecINTERNAL, false};
174174
STAmount const lptAMMBalance = (*ammSle)[sfLPTokenBalance];
175175
auto const lpTokens = ammLPHolds(sb, *ammSle, account_, ctx_.journal);
176+
// should not happen
177+
assert(
178+
!ctx_.view().rules().enabled(fixInnerObjTemplate) ||
179+
ammSle->isFieldPresent(sfAuctionSlot));
176180
if (!ammSle->isFieldPresent(sfAuctionSlot))
177-
ammSle->makeFieldPresent(sfAuctionSlot);
181+
{
182+
STObject auctionSlot =
183+
STObject::makeInnerObject(sfAuctionSlot, ctx_.view().rules());
184+
ammSle->set(&auctionSlot);
185+
}
178186
auto& auctionSlot = ammSle->peekFieldObject(sfAuctionSlot);
179187
auto const current =
180188
duration_cast<seconds>(

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

+5
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ applyVote(
200200
}
201201
}
202202

203+
// should not happen
204+
assert(
205+
!ctx_.view().rules().enabled(fixInnerObjTemplate) ||
206+
ammSle->isFieldPresent(sfAuctionSlot));
207+
203208
// Update the vote entries and the trading/discounted fee.
204209
ammSle->setFieldArray(sfVoteSlots, updatedVoteSlots);
205210
if (auto const fee = static_cast<std::int64_t>(num / den))

src/ripple/rpc/handlers/AMMInfo.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ doAMMInfo(RPC::JsonContext& context)
200200
}
201201
if (voteSlots.size() > 0)
202202
ammResult[jss::vote_slots] = std::move(voteSlots);
203+
// should not happen
204+
assert(
205+
!ledger->rules().enabled(fixInnerObjTemplate) ||
206+
amm->isFieldPresent(sfAuctionSlot));
203207
if (amm->isFieldPresent(sfAuctionSlot))
204208
{
205209
auto const& auctionSlot =

src/test/app/AMM_test.cpp

-55
Original file line numberDiff line numberDiff line change
@@ -4887,61 +4887,6 @@ struct AMM_test : public jtx::AMMTest
48874887
tesSUCCESS,
48884888
9,
48894889
false);
4890-
4891-
auto testDepositOnEmpty = [&](FeatureBitset features, TER const& err) {
4892-
Env env(
4893-
*this,
4894-
envconfig([](std::unique_ptr<Config> cfg) {
4895-
cfg->FEES.reference_fee = XRPAmount(1);
4896-
return cfg;
4897-
}),
4898-
features);
4899-
fund(env, gw, {alice, bob}, XRP(20'000), {USD(10'000)});
4900-
AMM amm(env, gw, XRP(10'000), USD(10'000));
4901-
for (auto i = 0; i < maxDeletableAMMTrustLines + 10; ++i)
4902-
{
4903-
Account const a{std::to_string(i)};
4904-
env.fund(XRP(1'000), a);
4905-
env(trust(a, STAmount{amm.lptIssue(), 10'000}));
4906-
env.close();
4907-
}
4908-
amm.bid(BidArg{.authAccounts = {bob, alice}});
4909-
// The trustlines are partially deleted,
4910-
// AMM is set to an empty state.
4911-
amm.withdrawAll(gw);
4912-
amm.setClose(false);
4913-
amm.deposit(DepositArg{
4914-
.account = alice,
4915-
.asset1In = XRP(10'000),
4916-
.asset2In = USD(10'000),
4917-
.flags = tfTwoAssetIfEmpty,
4918-
.tfee = 0});
4919-
// AuthAccounts is reset post-amendment
4920-
if (features[fixInnerObjTemplate])
4921-
BEAST_EXPECT(amm.expectAuctionSlot({}));
4922-
// AuthAccounts is re-used pre-amendment
4923-
else
4924-
BEAST_EXPECT(amm.expectAuctionSlot({bob, alice}));
4925-
// repeat some fail/success scenarios
4926-
amm.vote(VoteArg{.account = alice, .tfee = 0, .err = ter(err)});
4927-
amm.withdraw(WithdrawArg{
4928-
.account = alice, .asset1Out = USD(1), .err = ter(err)});
4929-
amm.vote(VoteArg{.account = alice, .tfee = 20, .err = ter(err)});
4930-
amm.withdraw(WithdrawArg{
4931-
.account = alice, .asset1Out = USD(2), .err = ter(err)});
4932-
env.close();
4933-
amm.vote(VoteArg{.account = alice, .tfee = 0});
4934-
amm.vote(VoteArg{.account = alice, .tfee = 0, .err = ter(err)});
4935-
amm.withdraw(WithdrawArg{.account = alice, .asset1Out = USD(3)});
4936-
amm.deposit(DepositArg{
4937-
.account = bob, .asset1In = XRP(100), .asset2In = USD(100)});
4938-
amm.bid(BidArg{.account = bob});
4939-
amm.withdraw(WithdrawArg{.account = bob, .asset1Out = USD(4)});
4940-
amm.vote(VoteArg{.account = bob, .tfee = 10, .err = ter(err)});
4941-
};
4942-
4943-
testDepositOnEmpty(all, tesSUCCESS);
4944-
testDepositOnEmpty(all - fixInnerObjTemplate, tefEXCEPTION);
49454890
}
49464891

49474892
void

src/test/jtx/impl/AMM.cpp

+23-14
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ AMM::bid(
670670
if (auto const amm =
671671
env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue())))
672672
{
673+
assert(
674+
!env_.current()->rules().enabled(fixInnerObjTemplate) ||
675+
amm->isFieldPresent(sfAuctionSlot));
673676
if (amm->isFieldPresent(sfAuctionSlot))
674677
{
675678
auto const& auctionSlot =
@@ -773,22 +776,28 @@ bool
773776
AMM::expectAuctionSlot(auto&& cb) const
774777
{
775778
if (auto const amm =
776-
env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue()));
777-
amm && amm->isFieldPresent(sfAuctionSlot))
779+
env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue())))
778780
{
779-
auto const& auctionSlot =
780-
static_cast<STObject const&>(amm->peekAtField(sfAuctionSlot));
781-
if (auctionSlot.isFieldPresent(sfAccount))
781+
assert(
782+
!env_.current()->rules().enabled(fixInnerObjTemplate) ||
783+
amm->isFieldPresent(sfAuctionSlot));
784+
if (amm->isFieldPresent(sfAuctionSlot))
782785
{
783-
// this could fail in pre-fixInnerObjTemplate test if one
784-
// the fail-cases. access as optional to avoid the failure
785-
auto const slotFee = auctionSlot[~sfDiscountedFee].value_or(0);
786-
auto const slotInterval = ammAuctionTimeSlot(
787-
env_.app().timeKeeper().now().time_since_epoch().count(),
788-
auctionSlot);
789-
auto const slotPrice = auctionSlot[sfPrice].iou();
790-
auto const authAccounts = auctionSlot.getFieldArray(sfAuthAccounts);
791-
return cb(slotFee, slotInterval, slotPrice, authAccounts);
786+
auto const& auctionSlot =
787+
static_cast<STObject const&>(amm->peekAtField(sfAuctionSlot));
788+
if (auctionSlot.isFieldPresent(sfAccount))
789+
{
790+
// this could fail in pre-fixInnerObjTemplate test if one
791+
// the fail-cases. access as optional to avoid the failure
792+
auto const slotFee = auctionSlot[~sfDiscountedFee].value_or(0);
793+
auto const slotInterval = ammAuctionTimeSlot(
794+
env_.app().timeKeeper().now().time_since_epoch().count(),
795+
auctionSlot);
796+
auto const slotPrice = auctionSlot[sfPrice].iou();
797+
auto const authAccounts =
798+
auctionSlot.getFieldArray(sfAuthAccounts);
799+
return cb(slotFee, slotInterval, slotPrice, authAccounts);
800+
}
792801
}
793802
}
794803
return false;

0 commit comments

Comments
 (0)