From 3c4c1facdf80183fe4e84720f9d676cc33fe0599 Mon Sep 17 00:00:00 2001 From: gregtatcam Date: Thu, 6 Jun 2024 20:24:20 -0400 Subject: [PATCH] Fix AMM delete on withdraw --- src/ripple/app/misc/impl/AMMUtils.cpp | 34 ++++++++++++----------- src/ripple/app/tx/impl/InvariantCheck.cpp | 3 +- src/test/app/MPToken_test.cpp | 1 + 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/ripple/app/misc/impl/AMMUtils.cpp b/src/ripple/app/misc/impl/AMMUtils.cpp index 570ef2dc5ff..eb077944327 100644 --- a/src/ripple/app/misc/impl/AMMUtils.cpp +++ b/src/ripple/app/misc/impl/AMMUtils.cpp @@ -211,8 +211,10 @@ deleteAMMTrustLines( [&](LedgerEntryType nodeType, uint256 const&, std::shared_ptr& sleItem) -> std::pair { - // Skip AMM - if (nodeType == LedgerEntryType::ltAMM) + // Skip AMM and MPT + if (nodeType == LedgerEntryType::ltAMM || + nodeType != LedgerEntryType::ltMPTOKEN || + nodeType != LedgerEntryType::ltMPTOKEN_ISSUANCE) return {tesSUCCESS, SkipEntry::Yes}; // Should only have the trustlines if (nodeType != LedgerEntryType::ltRIPPLE_STATE) @@ -269,20 +271,6 @@ deleteAMMAccount( ter != tesSUCCESS) return ter; - auto const ownerDirKeylet = keylet::ownerDir(ammAccountID); - if (!sb.dirRemove( - ownerDirKeylet, (*ammSle)[sfOwnerNode], ammSle->key(), false)) - { - JLOG(j.error()) << "deleteAMMAccount: failed to remove dir link"; - return tecINTERNAL; - } - if (sb.exists(ownerDirKeylet) && !sb.emptyDirDelete(ownerDirKeylet)) - { - JLOG(j.error()) << "deleteAMMAccount: cannot delete root dir node of " - << toBase58(ammAccountID); - return tecINTERNAL; - } - auto checkDeleteMPToken = [&](Asset const& asset_) -> TER { if (asset_.isMPT()) { @@ -314,6 +302,20 @@ deleteAMMAccount( if (auto const err = checkDeleteMPToken(asset2)) return err; + auto const ownerDirKeylet = keylet::ownerDir(ammAccountID); + if (!sb.dirRemove( + ownerDirKeylet, (*ammSle)[sfOwnerNode], ammSle->key(), false)) + { + JLOG(j.error()) << "deleteAMMAccount: failed to remove dir link"; + return tecINTERNAL; + } + if (sb.exists(ownerDirKeylet) && !sb.emptyDirDelete(ownerDirKeylet)) + { + JLOG(j.error()) << "deleteAMMAccount: cannot delete root dir node of " + << toBase58(ammAccountID); + return tecINTERNAL; + } + sb.erase(ammSle); sb.erase(sleAMMRoot); diff --git a/src/ripple/app/tx/impl/InvariantCheck.cpp b/src/ripple/app/tx/impl/InvariantCheck.cpp index c3ba3561980..e9ea90157e1 100644 --- a/src/ripple/app/tx/impl/InvariantCheck.cpp +++ b/src/ripple/app/tx/impl/InvariantCheck.cpp @@ -994,7 +994,8 @@ ValidMPTIssuance::finalize( mptokensCreated_ <= 2 && mptokensDeleted_ == 0; } - if (tx.getTxnType() == ttAMM_DELETE) + if (tx.getTxnType() == ttAMM_DELETE || + tx.getTxnType() == ttAMM_WITHDRAW) { if (mptIssuancesDeleted_ > 0) { diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index 689ef3a2c5c..c01da94bdfe 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -1545,6 +1545,7 @@ class MPToken_test : public beast::unit_test::suite void testPath(FeatureBitset features) { + testcase("Path"); using namespace test::jtx; Account const gw{"gw"}; Account const gw1{"gw1"};