mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 21:45:52 +00:00
fixInnerObjTemplate: set inner object template (#4906)
Add `STObject` constructor to explicitly set the inner object template. This allows certain AMM transactions to apply in the same ledger: There is no issue if the trading fee is greater than or equal to 0.01%. If the trading fee is less than 0.01%, then: - After AMM create, AMM transactions must wait for one ledger to close (3-5 seconds). - After one ledger is validated, all AMM transactions succeed, as appropriate, except for AMMVote. - The first AMMVote which votes for a 0 trading fee in a ledger will succeed. Subsequent AMMVote transactions which vote for a 0 trading fee will wait for the next ledger (3-5 seconds). This behavior repeats for each ledger. This has no effect on the ultimate correctness of AMM. This amendment will allow the transactions described above to succeed as expected, even if the trading fee is 0 and the transactions are applied within one ledger (block).
This commit is contained in:
committed by
GitHub
parent
6d3c21e369
commit
be12136b8a
@@ -4789,6 +4789,106 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testFixDefaultInnerObj()
|
||||
{
|
||||
testcase("Fix Default Inner Object");
|
||||
using namespace jtx;
|
||||
FeatureBitset const all{supported_amendments()};
|
||||
|
||||
auto test = [&](FeatureBitset features,
|
||||
TER const& err1,
|
||||
TER const& err2,
|
||||
TER const& err3,
|
||||
TER const& err4,
|
||||
std::uint16_t tfee,
|
||||
bool closeLedger,
|
||||
std::optional<std::uint16_t> extra = std::nullopt) {
|
||||
Env env(*this, features);
|
||||
fund(env, gw, {alice}, XRP(1'000), {USD(10)});
|
||||
AMM amm(
|
||||
env,
|
||||
gw,
|
||||
XRP(10),
|
||||
USD(10),
|
||||
{.tfee = tfee, .close = closeLedger});
|
||||
amm.deposit(alice, USD(10), XRP(10));
|
||||
amm.vote(VoteArg{.account = alice, .tfee = tfee, .err = ter(err1)});
|
||||
amm.withdraw(WithdrawArg{
|
||||
.account = gw, .asset1Out = USD(1), .err = ter(err2)});
|
||||
// with the amendment disabled and ledger not closed,
|
||||
// second vote succeeds if the first vote sets the trading fee
|
||||
// to non-zero; if the first vote sets the trading fee to >0 && <9
|
||||
// then the second withdraw succeeds if the second vote sets
|
||||
// the trading fee so that the discounted fee is non-zero
|
||||
amm.vote(VoteArg{.account = alice, .tfee = 20, .err = ter(err3)});
|
||||
amm.withdraw(WithdrawArg{
|
||||
.account = gw, .asset1Out = USD(2), .err = ter(err4)});
|
||||
};
|
||||
|
||||
// ledger is closed after each transaction, vote/withdraw don't fail
|
||||
// regardless whether the amendment is enabled or not
|
||||
test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 0, true);
|
||||
test(
|
||||
all - fixInnerObjTemplate,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
0,
|
||||
true);
|
||||
// ledger is not closed after each transaction
|
||||
// vote/withdraw don't fail if the amendment is enabled
|
||||
test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 0, false);
|
||||
// vote/withdraw fail if the amendment is not enabled
|
||||
// second vote/withdraw still fail: second vote fails because
|
||||
// the initial trading fee is 0, consequently second withdraw fails
|
||||
// because the second vote fails
|
||||
test(
|
||||
all - fixInnerObjTemplate,
|
||||
tefEXCEPTION,
|
||||
tefEXCEPTION,
|
||||
tefEXCEPTION,
|
||||
tefEXCEPTION,
|
||||
0,
|
||||
false);
|
||||
// if non-zero trading/discounted fee then vote/withdraw
|
||||
// don't fail whether the ledger is closed or not and
|
||||
// the amendment is enabled or not
|
||||
test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 10, true);
|
||||
test(
|
||||
all - fixInnerObjTemplate,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
10,
|
||||
true);
|
||||
test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 10, false);
|
||||
test(
|
||||
all - fixInnerObjTemplate,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
10,
|
||||
false);
|
||||
// non-zero trading fee but discounted fee is 0, vote doesn't fail
|
||||
// but withdraw fails
|
||||
test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 9, false);
|
||||
// second vote sets the trading fee to non-zero, consequently
|
||||
// second withdraw doesn't fail even if the amendment is not
|
||||
// enabled and the ledger is not closed
|
||||
test(
|
||||
all - fixInnerObjTemplate,
|
||||
tesSUCCESS,
|
||||
tefEXCEPTION,
|
||||
tesSUCCESS,
|
||||
tesSUCCESS,
|
||||
9,
|
||||
false);
|
||||
}
|
||||
|
||||
void
|
||||
testCore()
|
||||
{
|
||||
@@ -4815,6 +4915,7 @@ private:
|
||||
testClawback();
|
||||
testAMMID();
|
||||
testSelection();
|
||||
testFixDefaultInnerObj();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user