Skip to content

Commit

Permalink
Fix AMM delete on withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Jun 7, 2024
1 parent b94b7e2 commit 3c4c1fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
34 changes: 18 additions & 16 deletions src/ripple/app/misc/impl/AMMUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ deleteAMMTrustLines(
[&](LedgerEntryType nodeType,
uint256 const&,
std::shared_ptr<SLE>& sleItem) -> std::pair<TER, SkipEntry> {
// 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)
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/ripple/app/tx/impl/InvariantCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down

0 comments on commit 3c4c1fa

Please sign in to comment.