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.";
242 STTx const stx =
STTx{std::move(rb)};
244 if (!uniqueHashes.
emplace(hash).second)
246 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
247 <<
"duplicate Txn found. "
254 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
255 <<
"batch cannot have an inner batch txn. "
263 <<
"BatchTrace[" << parentBatchId <<
"]: "
264 <<
"inner txn must have the tfInnerBatchTxn flag. "
271 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
272 <<
"inner txn cannot include TxnSignature. "
279 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
280 <<
"inner txn cannot include Signers. "
287 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
288 <<
"inner txn SigningPubKey must be empty. "
298 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
299 <<
"inner txn preflight failed: "
307 !fee.native() || fee.xrp() != beast::zero)
309 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
310 <<
"inner txn must have a fee of 0. "
320 <<
"BatchTrace[" << parentBatchId <<
"]: "
321 <<
"inner txn must have exactly one of Sequence and "
331 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
332 <<
"inner txn must have either Sequence or "
341 if (
auto const seq = stx.
getFieldU32(sfSequence); seq != 0)
343 if (!accountSeqTicket[innerAccount].insert(seq).second)
346 <<
"BatchTrace[" << parentBatchId <<
"]: "
347 <<
"duplicate sequence found: "
355 if (
auto const ticket = stx.
getFieldU32(sfTicketSequence);
356 !accountSeqTicket[innerAccount].
insert(ticket).second)
359 <<
"BatchTrace[" << parentBatchId <<
"]: "
360 <<
"duplicate ticket found: "
382 auto const innerAccount = rb.getAccountID(sfAccount);
386 if (innerAccount != outerAccount)
387 requiredSigners.
insert(innerAccount);
399 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
400 <<
"signers array exceeds 8 entries.";
409 for (
auto const& signer : signers)
411 AccountID const signerAccount = signer.getAccountID(sfAccount);
412 if (signerAccount == outerAccount)
415 <<
"BatchTrace[" << parentBatchId <<
"]: "
416 <<
"signer cannot be the outer account: " << signerAccount;
420 if (!batchSigners.
insert(signerAccount).second)
423 <<
"BatchTrace[" << parentBatchId <<
"]: "
424 <<
"duplicate signer found: " << signerAccount;
430 if (requiredSigners.
erase(signerAccount) == 0)
432 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
433 <<
"no account signature for inner txn.";
445 <<
"BatchTrace[" << parentBatchId <<
"]: "
446 <<
"invalid batch txn signature: " << sigResult.error();
451 if (!requiredSigners.
empty())
453 JLOG(ctx.
j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: "
454 <<
"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
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.
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.