From 4e6f21045e915cc694b0520170abfbb2ae5d1ecc Mon Sep 17 00:00:00 2001 From: Gregory Tsipenyuk Date: Tue, 6 Feb 2024 19:16:31 -0500 Subject: [PATCH] [FOLD] Address @seelabs feedback * Remove comments * Refactor amendment changed code --- src/ripple/app/misc/impl/AMMUtils.cpp | 23 ++++++++++++++++------- src/ripple/app/tx/impl/AMMBid.cpp | 18 ++++++++++-------- src/ripple/app/tx/impl/AMMVote.cpp | 1 - src/ripple/rpc/handlers/AMMInfo.cpp | 1 - 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/ripple/app/misc/impl/AMMUtils.cpp b/src/ripple/app/misc/impl/AMMUtils.cpp index 4f6971896ea..2511240bfcd 100644 --- a/src/ripple/app/misc/impl/AMMUtils.cpp +++ b/src/ripple/app/misc/impl/AMMUtils.cpp @@ -138,7 +138,6 @@ std::uint16_t getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account) { using namespace std::chrono; - // should not happen assert( !view.rules().enabled(fixInnerObjTemplate) || ammSle.isFieldPresent(sfAuctionSlot)); @@ -304,12 +303,22 @@ initializeFeeAuctionVote( // AMM creator gets the auction slot for free. // AuctionSlot is created on AMMCreate and updated on AMMDeposit // when AMM is in an empty state - if (!ammSle->isFieldPresent(sfAuctionSlot)) - { - STObject auctionSlot = STObject::makeInnerObject(sfAuctionSlot, rules); - ammSle->set(&auctionSlot); - } - STObject& auctionSlot = ammSle->peekFieldObject(sfAuctionSlot); + STObject& auctionSlot = [&]() -> STObject& { + if (!rules.enabled(fixInnerObjTemplate)) + { + return ammSle->peekFieldObject(sfAuctionSlot); + } + else + { + if (!ammSle->isFieldPresent(sfAuctionSlot)) + { + STObject auctionSlot = + STObject::makeInnerObject(sfAuctionSlot, rules); + ammSle->set(&auctionSlot); + } + return ammSle->peekFieldObject(sfAuctionSlot); + } + }(); auctionSlot.setAccountID(sfAccount, account); // current + sec in 24h auto const expiration = std::chrono::duration_cast( diff --git a/src/ripple/app/tx/impl/AMMBid.cpp b/src/ripple/app/tx/impl/AMMBid.cpp index c8c3c144f90..e49c378ceeb 100644 --- a/src/ripple/app/tx/impl/AMMBid.cpp +++ b/src/ripple/app/tx/impl/AMMBid.cpp @@ -173,15 +173,17 @@ applyBid( return {tecINTERNAL, false}; STAmount const lptAMMBalance = (*ammSle)[sfLPTokenBalance]; auto const lpTokens = ammLPHolds(sb, *ammSle, account_, ctx_.journal); - // should not happen - assert( - !ctx_.view().rules().enabled(fixInnerObjTemplate) || - ammSle->isFieldPresent(sfAuctionSlot)); - if (!ammSle->isFieldPresent(sfAuctionSlot)) + auto const& rules = ctx_.view().rules(); + if (!rules.enabled(fixInnerObjTemplate)) { - STObject auctionSlot = - STObject::makeInnerObject(sfAuctionSlot, ctx_.view().rules()); - ammSle->set(&auctionSlot); + if (!ammSle->isFieldPresent(sfAuctionSlot)) + ammSle->makeFieldPresent(sfAuctionSlot); + } + else + { + assert(ammSle->isFieldPresent(sfAuctionSlot)); + if (!ammSle->isFieldPresent(sfAuctionSlot)) + return {tecINTERNAL, false}; } auto& auctionSlot = ammSle->peekFieldObject(sfAuctionSlot); auto const current = diff --git a/src/ripple/app/tx/impl/AMMVote.cpp b/src/ripple/app/tx/impl/AMMVote.cpp index a36413bbc4a..d908a93c383 100644 --- a/src/ripple/app/tx/impl/AMMVote.cpp +++ b/src/ripple/app/tx/impl/AMMVote.cpp @@ -200,7 +200,6 @@ applyVote( } } - // should not happen assert( !ctx_.view().rules().enabled(fixInnerObjTemplate) || ammSle->isFieldPresent(sfAuctionSlot)); diff --git a/src/ripple/rpc/handlers/AMMInfo.cpp b/src/ripple/rpc/handlers/AMMInfo.cpp index 12b3dbd407d..c6711fa7b82 100644 --- a/src/ripple/rpc/handlers/AMMInfo.cpp +++ b/src/ripple/rpc/handlers/AMMInfo.cpp @@ -200,7 +200,6 @@ doAMMInfo(RPC::JsonContext& context) } if (voteSlots.size() > 0) ammResult[jss::vote_slots] = std::move(voteSlots); - // should not happen assert( !ledger->rules().enabled(fixInnerObjTemplate) || amm->isFieldPresent(sfAuctionSlot));