mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Account for minimum reserve in potential spend:
* Relevant when deciding whether an account can queue multiple transactions. If the potential spend of the already queued transactions would dip into the reserve, the reserve is preserved for fees. * Also change several direct modifications of the owner count to call adjustOwnerCount to preserve overflow checking. * Update related unit testcase * Resolves #2251
This commit is contained in:
committed by
Nik Bougalis
parent
60dc949314
commit
e7a69cce65
@@ -912,11 +912,23 @@ TxQ::apply(Application& app, OpenView& view,
|
||||
LastLedgerSeq and MaybeTx::retriesRemaining.
|
||||
*/
|
||||
auto const balance = (*sle)[sfBalance].xrp();
|
||||
/* Get the minimum possible reserve. If fees exceed
|
||||
this amount, the transaction can't be queued.
|
||||
Considering that typical fees are several orders
|
||||
of magnitude smaller than any current or expected
|
||||
future reserve, this calculation is simpler than
|
||||
trying to figure out the potential changes to
|
||||
the ownerCount that may occur to the account
|
||||
as a result of these transactions, and removes
|
||||
any need to account for other transactions that
|
||||
may affect the owner count while these are queued.
|
||||
*/
|
||||
auto const reserve = view.fees().accountReserve(0);
|
||||
auto totalFee = multiTxn->fee;
|
||||
if (multiTxn->includeCurrentFee)
|
||||
totalFee += (*tx)[sfFee].xrp();
|
||||
if (totalFee >= balance ||
|
||||
totalFee >= view.fees().accountReserve(0))
|
||||
totalFee >= reserve)
|
||||
{
|
||||
// Drop the current transaction
|
||||
JLOG(j_.trace()) <<
|
||||
@@ -933,9 +945,12 @@ TxQ::apply(Application& app, OpenView& view,
|
||||
auto const sleBump = multiTxn->applyView->peek(
|
||||
keylet::account(account));
|
||||
|
||||
auto const potentialTotalSpend = multiTxn->fee +
|
||||
std::min(balance - std::min(balance, reserve),
|
||||
multiTxn->potentialSpend);
|
||||
assert(potentialTotalSpend > 0);
|
||||
sleBump->setFieldAmount(sfBalance,
|
||||
balance - (multiTxn->fee +
|
||||
multiTxn->potentialSpend));
|
||||
balance - potentialTotalSpend);
|
||||
sleBump->setFieldU32(sfSequence, tSeq);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ EscrowCreate::doApply()
|
||||
|
||||
// Deduct owner's balance, increment owner count
|
||||
(*sle)[sfBalance] = (*sle)[sfBalance] - ctx_.tx[sfAmount];
|
||||
(*sle)[sfOwnerCount] = (*sle)[sfOwnerCount] + 1;
|
||||
adjustOwnerCount(ctx_.view(), sle, 1, ctx_.journal);
|
||||
ctx_.view().update(sle);
|
||||
|
||||
return tesSUCCESS;
|
||||
@@ -502,7 +502,7 @@ EscrowFinish::doApply()
|
||||
// Adjust source owner count
|
||||
auto const sle = ctx_.view().peek(
|
||||
keylet::account(account));
|
||||
(*sle)[sfOwnerCount] = (*sle)[sfOwnerCount] - 1;
|
||||
adjustOwnerCount(ctx_.view(), sle, -1, ctx_.journal);
|
||||
ctx_.view().update(sle);
|
||||
|
||||
// Remove escrow from ledger
|
||||
@@ -585,7 +585,7 @@ EscrowCancel::doApply()
|
||||
auto const sle = ctx_.view().peek(
|
||||
keylet::account(account));
|
||||
(*sle)[sfBalance] = (*sle)[sfBalance] + (*slep)[sfAmount];
|
||||
(*sle)[sfOwnerCount] = (*sle)[sfOwnerCount] - 1;
|
||||
adjustOwnerCount(ctx_.view(), sle, -1, ctx_.journal);
|
||||
ctx_.view().update(sle);
|
||||
|
||||
// Remove escrow from ledger
|
||||
|
||||
@@ -144,7 +144,7 @@ closeChannel (
|
||||
assert ((*slep)[sfAmount] >= (*slep)[sfBalance]);
|
||||
(*sle)[sfBalance] =
|
||||
(*sle)[sfBalance] + (*slep)[sfAmount] - (*slep)[sfBalance];
|
||||
(*sle)[sfOwnerCount] = (*sle)[sfOwnerCount] - 1;
|
||||
adjustOwnerCount(view, sle, -1, j);
|
||||
view.update (sle);
|
||||
|
||||
// Remove PayChan from ledger
|
||||
@@ -254,7 +254,7 @@ PayChanCreate::doApply()
|
||||
|
||||
// Deduct owner's balance, increment owner count
|
||||
(*sle)[sfBalance] = (*sle)[sfBalance] - ctx_.tx[sfAmount];
|
||||
(*sle)[sfOwnerCount] = (*sle)[sfOwnerCount] + 1;
|
||||
adjustOwnerCount(ctx_.view(), sle, 1, ctx_.journal);
|
||||
ctx_.view ().update (sle);
|
||||
|
||||
return tesSUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user