mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Support for lsfDepositAuth (RIPD-1487):
The DepositAuth feature allows an account to require that it signs for any funds that are deposited to the account. For the time being this limits the account to accepting only XRP, although there are plans to allow IOU payments in the future. The lsfDepositAuth protections are not extended to offers. If an account creates an offer it is in effect saying, “I will accept funds from anyone who takes this offer.” Therefore, the typical user of the lsfDepositAuth flag will choose never to create any offers. But they can if they so choose. The DepositAuth feature leaves a small gap in its protections. An XRP payment is allowed to a destination account with the lsfDepositAuth flag set if: - The Destination XRP balance is less than or equal to the base reserve and - The value of the XRP Payment is less than or equal to the base reserve. This exception is intended to make it impossible for an account to wedge itself by spending all of its XRP on fees and leave itself unable to pay the fee to get more XRP. This commit - adds featureDepositAuth, - adds the lsfDepositAuth flag, - adds support for lsfDepositAuth in SetAccount.cpp - adds support in Payment.cpp for rejecting payments that don't meet the lsfDepositAuth requirements, - adds unit tests for Payment transactions to an an account with lsfDepositAuth set. - adds Escrow and PayChan support for lsfDepositAuth along with as unit tests.
This commit is contained in:
committed by
Nikolaos D. Bougalis
parent
a307d2d03f
commit
259394029a
@@ -42,24 +42,72 @@ public:
|
||||
BEAST_EXPECT((*env.le(alice))[ sfFlags ] == 0u);
|
||||
}
|
||||
|
||||
void testSetAndReset(unsigned int flag_val, std::string const& label)
|
||||
void testMostFlags()
|
||||
{
|
||||
using namespace test::jtx;
|
||||
Env env(*this);
|
||||
Account const alice ("alice");
|
||||
|
||||
// Test without DepositAuth enabled initially.
|
||||
Env env(*this, supported_amendments() - featureDepositAuth);
|
||||
env.fund(XRP(10000), noripple(alice));
|
||||
env.memoize("eric");
|
||||
env(regkey(alice, "eric"));
|
||||
|
||||
unsigned int orig_flags = (*env.le(alice))[ sfFlags ];
|
||||
// Give alice a regular key so she can legally set and clear
|
||||
// her asfDisableMaster flag.
|
||||
Account const alie {"alie", KeyType::secp256k1};
|
||||
env(regkey (alice, alie));
|
||||
env.close();
|
||||
|
||||
env.require(nflags(alice, flag_val));
|
||||
env(fset(alice, flag_val), sig(alice));
|
||||
env.require(flags(alice, flag_val));
|
||||
env(fclear(alice, flag_val));
|
||||
env.require(nflags(alice, flag_val));
|
||||
uint32 now_flags = (*env.le(alice))[ sfFlags ];
|
||||
BEAST_EXPECT(now_flags == orig_flags);
|
||||
auto testFlags = [this, &alice, &alie, &env]
|
||||
(std::initializer_list<std::uint32_t> goodFlags)
|
||||
{
|
||||
std::uint32_t const orig_flags = (*env.le(alice))[ sfFlags ];
|
||||
for (std::uint32_t flag {1u};
|
||||
flag < std::numeric_limits<std::uint32_t>::digits; ++flag)
|
||||
{
|
||||
if (flag == asfNoFreeze)
|
||||
{
|
||||
// The asfNoFreeze flag can't be cleared. It is tested
|
||||
// elsewhere.
|
||||
continue;
|
||||
}
|
||||
else if (std::find (goodFlags.begin(), goodFlags.end(), flag) !=
|
||||
goodFlags.end())
|
||||
{
|
||||
// Good flag
|
||||
env.require(nflags(alice, flag));
|
||||
env(fset(alice, flag), sig(alice));
|
||||
env.close();
|
||||
env.require(flags(alice, flag));
|
||||
env(fclear(alice, flag), sig(alie));
|
||||
env.close();
|
||||
env.require(nflags(alice, flag));
|
||||
std::uint32_t const now_flags = (*env.le(alice))[ sfFlags ];
|
||||
BEAST_EXPECT(now_flags == orig_flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Bad flag
|
||||
BEAST_EXPECT((*env.le(alice))[ sfFlags ] == orig_flags);
|
||||
env(fset(alice, flag), sig(alice));
|
||||
env.close();
|
||||
BEAST_EXPECT((*env.le(alice))[ sfFlags ] == orig_flags);
|
||||
env(fclear(alice, flag), sig(alie));
|
||||
env.close();
|
||||
BEAST_EXPECT((*env.le(alice))[ sfFlags ] == orig_flags);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Test with featureDepositAuth disabled.
|
||||
testFlags ({asfRequireDest, asfRequireAuth, asfDisallowXRP,
|
||||
asfGlobalFreeze, asfDisableMaster, asfDefaultRipple});
|
||||
|
||||
// Enable featureDepositAuth and retest.
|
||||
env.enableFeature (featureDepositAuth);
|
||||
env.close();
|
||||
testFlags ({asfRequireDest, asfRequireAuth, asfDisallowXRP,
|
||||
asfGlobalFreeze, asfDisableMaster, asfDefaultRipple,
|
||||
asfDepositAuth});
|
||||
}
|
||||
|
||||
void testSetAndResetAccountTxnID()
|
||||
@@ -69,7 +117,7 @@ public:
|
||||
Account const alice ("alice");
|
||||
env.fund(XRP(10000), noripple(alice));
|
||||
|
||||
unsigned int orig_flags = (*env.le(alice))[ sfFlags ];
|
||||
std::uint32_t const orig_flags = (*env.le(alice))[ sfFlags ];
|
||||
|
||||
// asfAccountTxnID is special and not actually set as a flag,
|
||||
// so we check the field presence instead
|
||||
@@ -78,7 +126,7 @@ public:
|
||||
BEAST_EXPECT(env.le(alice)->isFieldPresent(sfAccountTxnID));
|
||||
env(fclear(alice, asfAccountTxnID));
|
||||
BEAST_EXPECT(! env.le(alice)->isFieldPresent(sfAccountTxnID));
|
||||
uint32 now_flags = (*env.le(alice))[ sfFlags ];
|
||||
std::uint32_t const now_flags = (*env.le(alice))[ sfFlags ];
|
||||
BEAST_EXPECT(now_flags == orig_flags);
|
||||
}
|
||||
|
||||
@@ -393,17 +441,7 @@ public:
|
||||
void run()
|
||||
{
|
||||
testNullAccountSet();
|
||||
for(auto const& flag_set : std::vector<std::pair<unsigned int, std::string>>({
|
||||
{asfRequireDest, "RequireDestTag"},
|
||||
{asfRequireAuth, "RequireAuth"},
|
||||
{asfDisallowXRP, "DisallowXRP"},
|
||||
{asfGlobalFreeze, "GlobalFreeze"},
|
||||
{asfDisableMaster, "DisableMaster"},
|
||||
{asfDefaultRipple, "DefaultRipple"}
|
||||
}))
|
||||
{
|
||||
testSetAndReset(flag_set.first, flag_set.second);
|
||||
}
|
||||
testMostFlags();
|
||||
testSetAndResetAccountTxnID();
|
||||
testSetNoFreeze();
|
||||
testDomain();
|
||||
|
||||
Reference in New Issue
Block a user