Skip to content

Commit

Permalink
fix fee
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 committed Jan 3, 2025
1 parent ca5cf6e commit 3fc6aab
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 275 deletions.
476 changes: 232 additions & 244 deletions src/test/app/Batch_test.cpp

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/test/jtx/batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ class add
Json::Value txn_;
std::uint32_t seq_;
std::optional<std::uint32_t> ticket_;
std::optional<std::uint32_t> fee_;

public:
add(Json::Value const& txn,
std::uint32_t const& sequence,
std::optional<std::uint32_t> const& ticket = std::nullopt,
std::optional<std::uint32_t> const& fee = std::nullopt)
: txn_(txn), seq_(sequence), ticket_(ticket), fee_(fee)
: txn_(txn), seq_(sequence), ticket_(ticket)
{
}

Expand Down
8 changes: 1 addition & 7 deletions src/test/jtx/impl/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,11 @@ add::operator()(Env& env, JTx& jt) const
batchTransaction[jss::RawTransaction] = txn_;
batchTransaction[jss::RawTransaction][jss::SigningPubKey] = "";
batchTransaction[jss::RawTransaction][jss::Sequence] = seq_;
batchTransaction[jss::RawTransaction][jss::Fee] = "0";
batchTransaction[jss::RawTransaction][jss::Flags] =
batchTransaction[jss::RawTransaction][jss::Flags].asUInt() |
tfInnerBatchTxn;

// Optionally set new fee
if (fee_.has_value())
batchTransaction[jss::RawTransaction][jss::Fee] = to_string(*fee_);

if (!batchTransaction[jss::RawTransaction][jss::Fee] && !fee_.has_value())
batchTransaction[jss::RawTransaction][sfFee.jsonName] = to_string(env.current()->fees().base);

// Optionally set ticket sequence
if (ticket_.has_value())
{
Expand Down
17 changes: 16 additions & 1 deletion src/xrpld/app/tx/detail/Batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,27 @@ namespace ripple {
XRPAmount
Batch::calculateBaseFee(ReadView const& view, STTx const& tx)
{
// Calculate the Inner Txn Fees
XRPAmount txnFees{0};

if (tx.isFieldPresent(sfRawTransactions))
{
XRPAmount txFees{0};
auto const& txns = tx.getFieldArray(sfRawTransactions);
for (STObject txn : txns)
{
STTx const stx = STTx{std::move(txn)};
txFees += ripple::calculateBaseFee(view, stx);
}
txnFees += txFees;
}

// Calculate the BatchSigners Fees
std::int32_t signerCount = tx.isFieldPresent(sfBatchSigners)
? tx.getFieldArray(sfBatchSigners).size()
: 0;

return ((signerCount + 2) * view.fees().base);
return ((signerCount + 2) * view.fees().base) + txnFees;
}

NotTEC
Expand Down
8 changes: 3 additions & 5 deletions src/xrpld/app/tx/detail/CreateOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ CreateOffer::preflight(PreflightContext const& ctx)

std::uint32_t const uTxFlags = tx.getFlags();

bool const bImmediateOrCancel(uTxFlags & tfImmediateOrCancel);
bool const bFillOrKill(uTxFlags & tfFillOrKill);

if (uTxFlags & tfOfferCreateMask)
{
JLOG(j.debug()) << "Malformed transaction: Invalid flags set.";
return temINVALID_FLAG;
}

bool const bImmediateOrCancel(uTxFlags & tfImmediateOrCancel);
bool const bFillOrKill(uTxFlags & tfFillOrKill);

if (bImmediateOrCancel && bFillOrKill)
{
JLOG(j.debug()) << "Malformed transaction: both IoC and FoK set.";
Expand Down Expand Up @@ -1134,10 +1134,8 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel)
if (bFillOrKill)
{
JLOG(j_.trace()) << "Fill or Kill: offer killed";

if (sb.rules().enabled(fix1578))
return {tecKILLED, false};

return {tesSUCCESS, false};
}

Expand Down
40 changes: 26 additions & 14 deletions src/xrpld/app/tx/detail/Transactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,20 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee)
return temBAD_FEE;

auto const feePaid = ctx.tx[sfFee].xrp();

if (ctx.flags & tapBATCH)
{
if (feePaid == beast::zero)
return tesSUCCESS;

JLOG(ctx.j.warn()) << "Batch: sfFee must be zero.";
return temBAD_FEE;
}

if (!isLegalAmount(feePaid) || feePaid < beast::zero)
return temBAD_FEE;

// Only check fee is sufficient when the ledger is open.
if (ctx.view.open())
{
auto const feeDue =
Expand Down Expand Up @@ -234,20 +245,19 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee)
TER
Transactor::payFee()
{
if (auto const feePaid = ctx_.tx[sfFee].xrp())
{ // Deduct the fee amount so it's not available during the transaction.
auto const sle = view().peek(keylet::account(account_));
auto const feePaid = ctx_.tx[sfFee].xrp();

if (!sle)
return tefINTERNAL;
auto const sle = view().peek(keylet::account(account_));
if (!sle)
return tefINTERNAL;

// Will only write the account back if the transaction succeeds.
// Deduct the fee, so it's not available during the transaction.
// Will only write the account back if the transaction succeeds.

mSourceBalance -= feePaid;
sle->setFieldAmount(sfBalance, mSourceBalance);
mSourceBalance -= feePaid;
sle->setFieldAmount(sfBalance, mSourceBalance);

// VFALCO Should we call view().rawDestroyXRP() here as well?
}
// VFALCO Should we call view().rawDestroyXRP() here as well?

return tesSUCCESS;
}
Expand All @@ -270,8 +280,8 @@ Transactor::checkSeqProxy(
return terNO_ACCOUNT;
}

auto const t_seqProx = tx.getSeqProxy();
auto const a_seq = SeqProxy::sequence((*sle)[sfSequence]);
SeqProxy const t_seqProx = tx.getSeqProxy();
SeqProxy const a_seq = SeqProxy::sequence((*sle)[sfSequence]);

if (t_seqProx.isSeq())
{
Expand Down Expand Up @@ -455,10 +465,12 @@ Transactor::apply()
mPriorBalance = STAmount{(*sle)[sfBalance]}.xrp();
mSourceBalance = mPriorBalance;

if (auto const result = consumeSeqProxy(sle); result != tesSUCCESS)
TER result = consumeSeqProxy(sle);
if (result != tesSUCCESS)
return result;

if (auto const result = payFee(); result != tesSUCCESS)
result = payFee();
if (result != tesSUCCESS)
return result;

if (sle->isFieldPresent(sfAccountTxnID))
Expand Down
2 changes: 0 additions & 2 deletions src/xrpld/ledger/OpenView.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class OpenView final : public ReadView, public TxsRawView
The tx list starts empty and will contain
all newly inserted tx.
*/
/** @{ */
OpenView(
open_ledger_t,
ReadView const* base,
Expand All @@ -167,7 +166,6 @@ class OpenView final : public ReadView, public TxsRawView
: OpenView(open_ledger, &*base, rules, base)
{
}
/** @} */

OpenView(batch_view_t, OpenView& base)
: OpenView(std::addressof(base))
Expand Down

0 comments on commit 3fc6aab

Please sign in to comment.