20#include <xrpld/app/tx/apply.h>
21#include <xrpld/app/tx/detail/Batch.h>
23#include <xrpl/basics/Log.h>
24#include <xrpl/ledger/Sandbox.h>
25#include <xrpl/ledger/View.h>
26#include <xrpl/protocol/Feature.h>
27#include <xrpl/protocol/Indexes.h>
28#include <xrpl/protocol/TER.h>
29#include <xrpl/protocol/TxFlags.h>
65 JLOG(
debugLog().error()) <<
"BatchTrace: Base fee overflow detected.";
82 <<
"BatchTrace: Raw Transactions array exceeds max entries.";
89 STTx const stx =
STTx{std::move(txn)};
95 <<
"BatchTrace: Inner Batch transaction found.";
102 if (txnFees > maxAmount - fee)
105 <<
"BatchTrace: XRPAmount overflow in txnFees calculation.";
123 <<
"BatchTrace: Batch Signers array exceeds max entries.";
128 for (
STObject const& signer : signers)
130 if (signer.isFieldPresent(sfTxnSignature))
132 else if (signer.isFieldPresent(sfSigners))
133 signerCount += signer.getFieldArray(sfSigners).size();
138 if (signerCount > 0 &&
view.
fees().
base > maxAmount / signerCount)
141 <<
"BatchTrace: XRPAmount overflow in signerCount calculation.";
149 if (signerFees > maxAmount - txnFees)
152 <<
"BatchTrace: XRPAmount overflow in signerFees calculation.";
155 if (txnFees + signerFees > maxAmount - batchBase)
158 <<
"BatchTrace: XRPAmount overflow in total fee calculation.";
164 return signerFees + txnFees + batchBase;
215 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]:"
224 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]:"
225 <<
"too many flags.";
230 if (rawTxns.size() <= 1)
232 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]:"
233 <<
"txns array must have at least 2 entries.";
239 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]:"
240 <<
"txns array exceeds 8 entries.";
251 STTx const stx =
STTx{std::move(rb)};
253 if (!uniqueHashes.
emplace(hash).second)
255 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
256 <<
"duplicate Txn found. "
263 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
264 <<
"batch cannot have an inner batch txn. "
272 <<
"BatchTrace[" << parentBatchId <<
"]: "
273 <<
"inner txn must have the tfInnerBatchTxn flag. "
280 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
281 <<
"inner txn cannot include TxnSignature. "
288 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
289 <<
"inner txn cannot include Signers. "
296 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
297 <<
"inner txn SigningPubKey must be empty. "
307 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
308 <<
"inner txn preflight failed: "
316 !fee.native() || fee.xrp() != beast::zero)
318 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
319 <<
"inner txn must have a fee of 0. "
329 <<
"BatchTrace[" << parentBatchId <<
"]: "
330 <<
"inner txn must have exactly one of Sequence and "
340 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
341 <<
"inner txn must have either Sequence or "
350 if (
auto const seq = stx.
getFieldU32(sfSequence); seq != 0)
352 if (!accountSeqTicket[innerAccount].insert(seq).second)
355 <<
"BatchTrace[" << parentBatchId <<
"]: "
356 <<
"duplicate sequence found: "
364 if (
auto const ticket = stx.
getFieldU32(sfTicketSequence);
365 !accountSeqTicket[innerAccount].
insert(ticket).second)
368 <<
"BatchTrace[" << parentBatchId <<
"]: "
369 <<
"duplicate ticket found: "
378 if (innerAccount != outerAccount)
379 requiredSigners.
insert(innerAccount);
396 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
397 <<
"signers array exceeds 8 entries.";
406 for (
auto const& signer : signers)
408 AccountID const signerAccount = signer.getAccountID(sfAccount);
409 if (signerAccount == outerAccount)
412 <<
"BatchTrace[" << parentBatchId <<
"]: "
413 <<
"signer cannot be the outer account: " << signerAccount;
417 if (!batchSigners.
insert(signerAccount).second)
420 <<
"BatchTrace[" << parentBatchId <<
"]: "
421 <<
"duplicate signer found: " << signerAccount;
427 if (requiredSigners.
erase(signerAccount) == 0)
429 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
430 <<
"no account signature for inner txn.";
442 <<
"BatchTrace[" << parentBatchId <<
"]: "
443 <<
"invalid batch txn signature: " << sigResult.error();
448 if (!requiredSigners.
empty())
450 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
451 <<
"invalid batch signers.";
TER doApply() override
Applies the outer batch transaction.
static NotTEC preflight(PreflightContext const &ctx)
Performs preflight validation checks for a Batch transaction.
static NotTEC checkSign(PreclaimContext const &ctx)
Checks the validity of signatures for a batch transaction.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Calculates the total base fee for a batch transaction.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
AccountID getAccountID(SField const &field) const
STArray const & getFieldArray(SField const &field) const
std::uint16_t getFieldU16(SField const &field) const
std::uint32_t getFieldU32(SField const &field) const
STAmount const & getFieldAmount(SField const &field) const
bool isFieldPresent(SField const &field) const
std::uint32_t getFlags() const
Blob getSigningPubKey() const
TxType getTxnType() const
uint256 getTransactionID() const
Expected< void, std::string > checkBatchSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
static NotTEC checkSign(PreclaimContext const &ctx)
static NotTEC checkBatchSign(PreclaimContext const &ctx)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string transHuman(TER code)
constexpr std::uint32_t tfAllOrNothing
constexpr std::uint32_t const tfBatchMask
PreflightResult preflight(Application &app, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
constexpr std::uint32_t tfOnlyOne
constexpr std::uint32_t tfIndependent
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
constexpr XRPAmount INITIAL_XRP
Configure the native currency.
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
constexpr std::uint32_t tfUntilFailure
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
beast::Journal debugLog()
Returns a debug journal.
bool isTesSuccess(TER x) noexcept
std::size_t constexpr maxBatchTxCount
The maximum number of transactions that can be in a batch.
constexpr std::uint32_t tfInnerBatchTxn
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.