Introduce support for deletable accounts:

The XRP Ledger utilizes an account model. Unlike systems based on a UTXO
model, XRP Ledger accounts are first-class objects. This design choice
allows the XRP Ledger to offer rich functionality, including the ability
to own objects (offers, escrows, checks, signer lists) as well as other
advanced features, such as key rotation and configurable multi-signing
without needing to change a destination address.

The trade-off is that accounts must be stored on ledger. The XRP Ledger
applies reserve requirements, in XRP, to protect the shared global ledger
from growing excessively large as the result of spam or malicious usage.

Prior to this commit, accounts had been permanent objects; once created,
they could never be deleted.

This commit introduces a new amendment "DeletableAccounts" which, if
enabled, will allow account objects to be deleted by executing the new
"AccountDelete" transaction. Any funds remaining in the account will
be transferred to an account specified in the deletion transaction.

The amendment changes the mechanics of account creation; previously
a new account would have an initial sequence number of 1. Accounts
created after the amendment will have an initial sequence number that
is equal to the ledger in which the account was created.

Accounts can only be deleted if they are not associated with any
obligations (like RippleStates, Escrows, or PayChannels) and if the
current ledger sequence number exceeds the account's sequence number
by at least 256 so that, if recreated, the account can be protected
from transaction replay.
This commit is contained in:
Nik Bougalis
2018-11-01 19:58:04 -07:00
committed by Manoj doshi
parent 7e7664c29a
commit a3a9dc26b4
69 changed files with 2859 additions and 500 deletions

View File

@@ -2178,8 +2178,12 @@ public:
BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-101");
}
// Helper function that validates a *defaulted* trustline. If the
// trustline is not defaulted then the tests will not pass.
// Helper function that validates a *defaulted* trustline: one that has
// no unusual flags set and doesn't have high or low limits set. Such a
// trustline may have an actual balance (it can be created automatically
// if a user places an offer to acquire an IOU for which they don't have
// a trust line defined). If the trustline is not defaulted then the tests
// will not pass.
void
verifyDefaultTrustline (jtx::Env& env,
jtx::Account const& account, jtx::PrettyAmount const& expectBalance)
@@ -2487,6 +2491,7 @@ public:
env.fund (reserve (env, 3) + (fee * 3), alice);
env.fund (reserve (env, 3) + (fee * 2), bob);
env.close();
env (trust(alice, usdOffer));
env (trust(bob, eurOffer));
env.close();
@@ -2494,6 +2499,7 @@ public:
env (pay(gw, alice, usdOffer));
env (pay(gw, bob, eurOffer));
env.close();
env.require (
balance (alice, usdOffer),
balance (bob, eurOffer));
@@ -2510,34 +2516,44 @@ public:
balance (bob, usdOffer),
offers (alice, 0),
offers (bob, 0));
// Alice's offer crossing created a default EUR trustline and
// Bob's offer crossing created a default USD trustline:
verifyDefaultTrustline (env, alice, eurOffer);
verifyDefaultTrustline (env, bob, usdOffer);
// Make two more offers that leave one of the offers non-dry.
env (offer (alice, USD(999), eurOffer));
// Guarantee the order of application by putting a close()
// between them.
env (offer (bob, eurOffer, usdOffer));
env.close();
env (offer (alice, USD(999), eurOffer));
env.close();
env.require (offers (alice, 0));
env.require (offers (bob, 1));
env.require (balance (alice, USD(999)));
env.require (balance (alice, EUR(1)));
env.require (balance (bob, USD(1)));
env.require (balance (bob, EUR(999)));
env.require (offers (alice, 0));
verifyDefaultTrustline (env, alice, EUR(1));
verifyDefaultTrustline (env, bob, USD(1));
{
auto bobsOffers = offersOnAccount (env, bob);
BEAST_EXPECT (bobsOffers.size() == 1);
auto const& bobsOffer = *(bobsOffers.front());
if (BEAST_EXPECT(bobsOffers.size() == 1))
{
auto const& bobsOffer = *(bobsOffers.front());
BEAST_EXPECT (bobsOffer[sfTakerGets] == USD (1));
BEAST_EXPECT (bobsOffer[sfTakerPays] == EUR (1));
BEAST_EXPECT (bobsOffer[sfTakerGets] == USD(1));
BEAST_EXPECT (bobsOffer[sfTakerPays] == EUR(1));
}
}
// alice makes one more offer that cleans out bob's offer.
env (offer (alice, USD(1), EUR(1)));
env.close();
env.require (balance (alice, USD(1000)));
env.require (balance (alice, EUR(none)));
env.require (balance (bob, USD(none)));
@@ -2548,6 +2564,22 @@ public:
// The two trustlines that were generated by offers should be gone.
BEAST_EXPECT (! env.le (keylet::line (alice.id(), EUR.issue())));
BEAST_EXPECT (! env.le (keylet::line (bob.id(), USD.issue())));
// Make two more offers that leave one of the offers non-dry. We
// need to properly sequence the transactions:
env (offer (alice, EUR(999), usdOffer));
env.close();
env (offer (bob, usdOffer, eurOffer));
env.close();
env.require (offers (alice, 0));
env.require (offers (bob, 0));
env.require (balance (alice, USD(0)));
env.require (balance (alice, EUR(999)));
env.require (balance (bob, USD(1000)));
env.require (balance (bob, EUR(1)));
}
void
@@ -4542,6 +4574,112 @@ public:
env.require (offers (gw, 0));
}
void testDeletedOfferIssuer (FeatureBitset features)
{
// Show that an offer who's issuer has been deleted cannot be crossed.
using namespace jtx;
testcase("Deleted offer issuer");
auto trustLineExists = [](jtx::Env const& env,
jtx::Account const& src,
jtx::Account const& dst,
Currency const& cur) -> bool {
return bool(env.le(keylet::line(src, dst, cur)));
};
Account const alice("alice");
Account const becky("becky");
Account const carol("carol");
Account const gw("gateway");
auto const USD = gw["USD"];
auto const BUX = alice["BUX"];
Env env{*this, features};
env.fund (XRP(10000), alice, becky, carol, noripple (gw));
env.trust (USD(1000), becky);
env (pay (gw, becky, USD(5)));
env.close();
BEAST_EXPECT(trustLineExists(env, gw, becky, USD.currency));
// Make offers that produce USD and can be crossed two ways:
// direct XRP -> USD
// direct BUX -> USD
env (offer (becky, XRP(2), USD(2)), txflags(tfPassive));
std::uint32_t const beckyBuxUsdSeq {env.seq (becky)};
env (offer (becky, BUX(3), USD(3)), txflags(tfPassive));
env.close();
// becky keeps the offers, but removes the trustline.
env(pay(becky, gw, USD(5)));
env.trust(USD(0), becky);
env.close();
BEAST_EXPECT(!trustLineExists(env, gw, becky, USD.currency));
BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2)));
BEAST_EXPECT(isOffer(env, becky, BUX(3), USD(3)));
// Delete gw's account.
{
// The ledger sequence needs to far enough ahead of the account
// sequence before the account can be deleted.
int const delta =
[&env, &gw, openLedgerSeq = env.current()->seq()]() -> int
{
std::uint32_t const gwSeq {env.seq(gw)};
if (gwSeq + 255 > openLedgerSeq)
return gwSeq - openLedgerSeq + 255;
return 0;
}();
for (int i = 0; i < delta; ++i)
env.close();
// Account deletion has a high fee. Account for that.
env(acctdelete(gw, alice),
fee(drops(env.current()->fees().increment)));
env.close();
// Verify that gw's account root is gone from the ledger.
BEAST_EXPECT(!env.closed()->exists(keylet::account(gw.id())));
}
// alice crosses becky's first offer. The offer create fails because
// the USD issuer is not in the ledger.
env (offer (alice, USD(2), XRP(2)), ter (tecNO_ISSUER));
env.close();
env.require (offers (alice, 0));
BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2)));
BEAST_EXPECT(isOffer(env, becky, BUX(3), USD(3)));
// alice crosses becky's second offer. Again, the offer create fails
// because the USD issuer is not in the ledger.
env (offer (alice, USD(3), BUX(3)), ter (tecNO_ISSUER));
env.require (offers (alice, 0));
BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2)));
BEAST_EXPECT(isOffer(env, becky, BUX(3), USD(3)));
// Cancel becky's BUX -> USD offer so we can try auto-bridging.
env (offer_cancel (becky, beckyBuxUsdSeq));
env.close();
BEAST_EXPECT(!isOffer(env, becky, BUX(3), USD(3)));
// alice creates an offer that can be auto-bridged with becky's
// remaining offer.
env.trust (BUX(1000), carol);
env (pay (alice, carol, BUX(2)));
env (offer (alice, BUX(2), XRP(2)));
env.close();
// carol attempts the auto-bridge. Again, the offer create fails
// because the USD issuer is not in the ledger.
env (offer (carol, USD(2), BUX(2)), ter (tecNO_ISSUER));
env.close();
BEAST_EXPECT(isOffer(env, alice, BUX(2), XRP(2)));
BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2)));
}
void testTickSize (FeatureBitset features)
{
testcase ("Tick Size");
@@ -4719,6 +4857,7 @@ public:
testMissingAuth (features);
testRCSmoketest (features);
testSelfAuth (features);
testDeletedOfferIssuer (features);
testTickSize (features | featureTickSize);
}