Skip to content

Commit

Permalink
Restructure the code a bit; handle AMMID
Browse files Browse the repository at this point in the history
  • Loading branch information
ximinez committed Sep 1, 2023
1 parent 29059f8 commit 19a76ae
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions src/ripple/app/tx/impl/InvariantCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,40 +377,55 @@ AccountRootsDeletedClean::finalize(
{
// This list should include all of the keylet functions that take a single
// AccountID parameter
std::array<std::function<Keylet(AccountID const& id)>, 4> keyletfuncs{
using fType = std::function<Keylet(AccountID const& id)>;
static std::array<fType, 5> const keyletfuncs{
&keylet::account,
&keylet::ownerDir,
&keylet::signers,
&keylet::nftpage_min,
&keylet::nftpage_max};

static auto const noObject = [&](auto const& keylet) {
// It may be a little unintuitive, but this function follows the same
// return paradigm as the `finalize` function. True if the check passes
// (object is NOT found). False if it fails (object IS found).
if (auto const sle = view.read(keylet))
{
// Finding the object is bad
auto const typeName = [&]() {
auto item =
LedgerFormats::getInstance().findByType(sle->getType());

if (item != nullptr)
return item->getName();
return std::to_string(sle->getType());
}();

JLOG(j.fatal())
<< "Invariant failed: account deletion left behind a "
<< typeName << " object";
return false;
}
return true;
};

for (auto const& accountSLE : accountsDeleted_)
{
auto const accountID = accountSLE->getAccountID(sfAccount);
for (auto const keyletfunc : keyletfuncs)
for (auto const& keyletfunc : keyletfuncs)
{
auto const key = std::invoke(keyletfunc, accountID);
if (auto const sle = view.read(key))
{
// Finding the object is bad
std::string const typeName = [&sle]() {
auto item =
LedgerFormats::getInstance().findByType(sle->getType());

if (item != nullptr)
return item->getName();
return std::to_string(sle->getType());
}();
if (!noObject(std::invoke(keyletfunc, accountID)))
return false;
}

JLOG(j.fatal())
<< "Invariant failed: account deletion left behind a "
<< typeName << " object";
// Keys directly stored in the AccountRoot object
if (auto const ammKey = accountSLE->at(~sfAMMID))
{
if (!noObject(keylet::amm(*ammKey)))
return false;
}
}
}

// TODO: Try to load the AMMID once the code that adds it is merged in.

return true;
}

Expand Down

0 comments on commit 19a76ae

Please sign in to comment.