refactor: Retire DepositPreAuth and DepositAuth amendments (#5978)

Amendments activated for more than 2 years can be retired. This change retires the fDepositPreAuth and DepositAuth amendments.
This commit is contained in:
Jingchen
2025-11-11 15:21:07 +00:00
committed by GitHub
parent 03704f712b
commit ff18cfef96
17 changed files with 168 additions and 389 deletions

View File

@@ -177,13 +177,7 @@ CreateOffer::preclaim(PreclaimContext const& ctx)
{
// Note that this will get checked again in applyGuts, but it saves
// us a call to checkAcceptAsset and possible false negative.
//
// The return code change is attached to featureDepositPreauth as a
// convenience, as the change is not big enough to deserve its own
// amendment.
return ctx.view.rules().enabled(featureDepositPreauth)
? TER{tecEXPIRED}
: TER{tesSUCCESS};
return tecEXPIRED;
}
// Make sure that we are authorized to hold what the taker will pay us.
@@ -235,10 +229,7 @@ CreateOffer::checkAcceptAsset(
return (flags & tapRETRY) ? TER{terNO_ACCOUNT} : TER{tecNO_ISSUER};
}
// This code is attached to the DepositPreauth amendment as a matter of
// convenience. The change is not significant enough to deserve its
// own amendment.
if (view.rules().enabled(featureDepositPreauth) && (issue.account == id))
if (issue.account == id)
// An account can always accept its own issuance.
return tesSUCCESS;
@@ -599,13 +590,7 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel)
{
// If the offer has expired, the transaction has successfully
// done nothing, so short circuit from here.
//
// The return code change is attached to featureDepositPreauth as a
// convenience. The change is not big enough to deserve a fix code.
TER const ter{
sb.rules().enabled(featureDepositPreauth) ? TER{tecEXPIRED}
: TER{tesSUCCESS}};
return {ter, true};
return {tecEXPIRED, true};
}
bool const bOpenLedger = sb.open();

View File

@@ -232,8 +232,7 @@ DeleteAccount::preclaim(PreclaimContext const& ctx)
if (!ctx.tx.isFieldPresent(sfCredentialIDs))
{
// Check whether the destination account requires deposit authorization.
if (ctx.view.rules().enabled(featureDepositAuth) &&
(sleDst->getFlags() & lsfDepositAuth))
if (sleDst->getFlags() & lsfDepositAuth)
{
if (!ctx.view.exists(keylet::depositPreauth(dst, account)))
return tecNO_PERMISSION;
@@ -353,8 +352,7 @@ DeleteAccount::doApply()
if (!src || !dst)
return tefBAD_LEDGER; // LCOV_EXCL_LINE
if (ctx_.view().rules().enabled(featureDepositAuth) &&
ctx_.tx.isFieldPresent(sfCredentialIDs))
if (ctx_.tx.isFieldPresent(sfCredentialIDs))
{
if (auto err = verifyDepositPreauth(
ctx_.tx, ctx_.view(), account_, dstID, dst, ctx_.journal);

View File

@@ -459,12 +459,6 @@ EscrowCreate::doApply()
if (((*sled)[sfFlags] & lsfRequireDestTag) &&
!ctx_.tx[~sfDestinationTag])
return tecDST_TAG_NEEDED;
// Obeying the lsfDisallowXRP flag was a bug. Piggyback on
// featureDepositAuth to remove the bug.
if (!ctx_.view().rules().enabled(featureDepositAuth) &&
((*sled)[sfFlags] & lsfDisallowXRP))
return tecNO_TARGET;
}
// Create escrow in ledger. Note that we we use the value from the
@@ -1041,13 +1035,10 @@ EscrowFinish::doApply()
if (!sled)
return tecNO_DST;
if (ctx_.view().rules().enabled(featureDepositAuth))
{
if (auto err = verifyDepositPreauth(
ctx_.tx, ctx_.view(), account_, destID, sled, ctx_.journal);
!isTesSuccess(err))
return err;
}
if (auto err = verifyDepositPreauth(
ctx_.tx, ctx_.view(), account_, destID, sled, ctx_.journal);
!isTesSuccess(err))
return err;
AccountID const account = (*slep)[sfAccount];

View File

@@ -209,12 +209,6 @@ PayChanCreate::preclaim(PreclaimContext const& ctx)
if ((flags & lsfRequireDestTag) && !ctx.tx[~sfDestinationTag])
return tecDST_TAG_NEEDED;
// Obeying the lsfDisallowXRP flag was a bug. Piggyback on
// featureDepositAuth to remove the bug.
if (!ctx.view.rules().enabled(featureDepositAuth) &&
(flags & lsfDisallowXRP))
return tecNO_TARGET;
// Pseudo-accounts cannot receive payment channels, other than native
// to their underlying ledger object - implemented in their respective
// transaction types. Note, this is not amendment-gated because all
@@ -525,20 +519,10 @@ PayChanClaim::doApply()
if (!sled)
return tecNO_DST;
// Obeying the lsfDisallowXRP flag was a bug. Piggyback on
// featureDepositAuth to remove the bug.
bool const depositAuth{ctx_.view().rules().enabled(featureDepositAuth)};
if (!depositAuth &&
(txAccount == src && (sled->getFlags() & lsfDisallowXRP)))
return tecNO_TARGET;
if (depositAuth)
{
if (auto err = verifyDepositPreauth(
ctx_.tx, ctx_.view(), txAccount, dst, sled, ctx_.journal);
!isTesSuccess(err))
return err;
}
if (auto err = verifyDepositPreauth(
ctx_.tx, ctx_.view(), txAccount, dst, sled, ctx_.journal);
!isTesSuccess(err))
return err;
(*slep)[sfBalance] = ctx_.tx[sfBalance];
XRPAmount const reqDelta = reqBalance - chanBalance;

View File

@@ -417,43 +417,28 @@ Payment::doApply()
view().update(sleDst);
}
// Determine whether the destination requires deposit authorization.
bool const depositAuth = view().rules().enabled(featureDepositAuth);
bool const reqDepositAuth =
sleDst->getFlags() & lsfDepositAuth && depositAuth;
bool const depositPreauth = view().rules().enabled(featureDepositPreauth);
bool const ripple =
(hasPaths || sendMax || !dstAmount.native()) && !mptDirect;
// If the destination has lsfDepositAuth set, then only direct XRP
// payments (no intermediate steps) are allowed to the destination.
if (!depositPreauth && ripple && reqDepositAuth)
return tecNO_PERMISSION;
if (ripple)
{
// Ripple payment with at least one intermediate step and uses
// transitive balances.
if (depositPreauth && depositAuth)
{
// If depositPreauth is enabled, then an account that requires
// authorization has two ways to get an IOU Payment in:
// 1. If Account == Destination, or
// 2. If Account is deposit preauthorized by destination.
// An account that requires authorization has two ways to get an
// IOU Payment in:
// 1. If Account == Destination, or
// 2. If Account is deposit preauthorized by destination.
if (auto err = verifyDepositPreauth(
ctx_.tx,
ctx_.view(),
account_,
dstAccountID,
sleDst,
ctx_.journal);
!isTesSuccess(err))
return err;
}
if (auto err = verifyDepositPreauth(
ctx_.tx,
ctx_.view(),
account_,
dstAccountID,
sleDst,
ctx_.journal);
!isTesSuccess(err))
return err;
path::RippleCalc::Input rcInput;
rcInput.partialPaymentAllowed = partialPaymentAllowed;
@@ -630,43 +615,40 @@ Payment::doApply()
// The source account does have enough money. Make sure the
// source account has authority to deposit to the destination.
if (depositAuth)
// An account that requires authorization has three ways to get an XRP
// Payment in:
// 1. If Account == Destination, or
// 2. If Account is deposit preauthorized by destination, or
// 3. If the destination's XRP balance is
// a. less than or equal to the base reserve and
// b. the deposit amount is less than or equal to the base reserve,
// then we allow the deposit.
//
// Rule 3 is designed to keep an account from getting wedged
// in an unusable state if it sets the lsfDepositAuth flag and
// then consumes all of its XRP. Without the rule if an
// account with lsfDepositAuth set spent all of its XRP, it
// would be unable to acquire more XRP required to pay fees.
//
// We choose the base reserve as our bound because it is
// a small number that seldom changes but is always sufficient
// to get the account un-wedged.
// Get the base reserve.
XRPAmount const dstReserve{view().fees().reserve};
if (dstAmount > dstReserve ||
sleDst->getFieldAmount(sfBalance) > dstReserve)
{
// If depositPreauth is enabled, then an account that requires
// authorization has three ways to get an XRP Payment in:
// 1. If Account == Destination, or
// 2. If Account is deposit preauthorized by destination, or
// 3. If the destination's XRP balance is
// a. less than or equal to the base reserve and
// b. the deposit amount is less than or equal to the base reserve,
// then we allow the deposit.
//
// Rule 3 is designed to keep an account from getting wedged
// in an unusable state if it sets the lsfDepositAuth flag and
// then consumes all of its XRP. Without the rule if an
// account with lsfDepositAuth set spent all of its XRP, it
// would be unable to acquire more XRP required to pay fees.
//
// We choose the base reserve as our bound because it is
// a small number that seldom changes but is always sufficient
// to get the account un-wedged.
// Get the base reserve.
XRPAmount const dstReserve{view().fees().reserve};
if (dstAmount > dstReserve ||
sleDst->getFieldAmount(sfBalance) > dstReserve)
{
if (auto err = verifyDepositPreauth(
ctx_.tx,
ctx_.view(),
account_,
dstAccountID,
sleDst,
ctx_.journal);
!isTesSuccess(err))
return err;
}
if (auto err = verifyDepositPreauth(
ctx_.tx,
ctx_.view(),
account_,
dstAccountID,
sleDst,
ctx_.journal);
!isTesSuccess(err))
return err;
}
// Do the arithmetic for the transfer and make the ledger change.

View File

@@ -463,18 +463,15 @@ SetAccount::doApply()
//
// DepositAuth
//
if (view().rules().enabled(featureDepositAuth))
if (uSetFlag == asfDepositAuth)
{
if (uSetFlag == asfDepositAuth)
{
JLOG(j_.trace()) << "Set lsfDepositAuth.";
uFlagsOut |= lsfDepositAuth;
}
else if (uClearFlag == asfDepositAuth)
{
JLOG(j_.trace()) << "Clear lsfDepositAuth.";
uFlagsOut &= ~lsfDepositAuth;
}
JLOG(j_.trace()) << "Set lsfDepositAuth.";
uFlagsOut |= lsfDepositAuth;
}
else if (uClearFlag == asfDepositAuth)
{
JLOG(j_.trace()) << "Clear lsfDepositAuth.";
uFlagsOut &= ~lsfDepositAuth;
}
//