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;
216 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]:"
217 <<
"too many flags.";
222 if (rawTxns.size() <= 1)
224 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]:"
225 <<
"txns array must have at least 2 entries.";
231 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]:"
232 <<
"txns array exceeds 8 entries.";
240 auto checkSignatureFields = [&parentBatchId, &j = ctx.
j](
243 char const* label =
"") ->
NotTEC {
244 if (sig.isFieldPresent(sfTxnSignature))
247 <<
"BatchTrace[" << parentBatchId <<
"]: "
248 <<
"inner txn " << label <<
"cannot include TxnSignature. "
253 if (sig.isFieldPresent(sfSigners))
256 <<
"BatchTrace[" << parentBatchId <<
"]: "
257 <<
"inner txn " << label <<
" cannot include Signers. "
262 if (!sig.getFieldVL(sfSigningPubKey).empty())
265 <<
"BatchTrace[" << parentBatchId <<
"]: "
266 <<
"inner txn " << label <<
" SigningPubKey must be empty. "
275 STTx const stx =
STTx{std::move(rb)};
277 if (!uniqueHashes.
emplace(hash).second)
279 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
280 <<
"duplicate Txn found. "
287 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
288 <<
"batch cannot have an inner batch txn. "
296 <<
"BatchTrace[" << parentBatchId <<
"]: "
297 <<
"inner txn must have the tfInnerBatchTxn flag. "
302 if (
auto const ret = checkSignatureFields(stx, hash))
325 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
326 <<
"inner txn preflight failed: "
334 !fee.native() || fee.xrp() != beast::zero)
336 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
337 <<
"inner txn must have a fee of 0. "
347 <<
"BatchTrace[" << parentBatchId <<
"]: "
348 <<
"inner txn must have exactly one of Sequence and "
358 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
359 <<
"inner txn must have either Sequence or "
368 if (
auto const seq = stx.
getFieldU32(sfSequence); seq != 0)
370 if (!accountSeqTicket[innerAccount].insert(seq).second)
373 <<
"BatchTrace[" << parentBatchId <<
"]: "
374 <<
"duplicate sequence found: "
382 if (
auto const ticket = stx.
getFieldU32(sfTicketSequence);
383 !accountSeqTicket[innerAccount].
insert(ticket).second)
386 <<
"BatchTrace[" << parentBatchId <<
"]: "
387 <<
"duplicate ticket found: "
409 auto const innerAccount = rb.getAccountID(sfAccount);
413 if (innerAccount != outerAccount)
414 requiredSigners.
insert(innerAccount);
433 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
434 <<
"signers array exceeds 8 entries.";
443 for (
auto const& signer : signers)
445 AccountID const signerAccount = signer.getAccountID(sfAccount);
446 if (signerAccount == outerAccount)
449 <<
"BatchTrace[" << parentBatchId <<
"]: "
450 <<
"signer cannot be the outer account: " << signerAccount;
454 if (!batchSigners.
insert(signerAccount).second)
457 <<
"BatchTrace[" << parentBatchId <<
"]: "
458 <<
"duplicate signer found: " << signerAccount;
464 if (requiredSigners.
erase(signerAccount) == 0)
466 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
467 <<
"no account signature for inner txn.";
479 <<
"BatchTrace[" << parentBatchId <<
"]: "
480 <<
"invalid batch txn signature: " << sigResult.error();
485 if (!requiredSigners.
empty())
487 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
488 <<
"invalid batch signers.";
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
TER doApply() override
Applies the outer batch transaction.
static NotTEC preflight(PreflightContext const &ctx)
Performs preflight validation checks for a Batch transaction.
static NotTEC preflightSigValidated(PreflightContext const &ctx)
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.
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
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.
constexpr std::uint32_t tfUntilFailure
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.