1#include <xrpl/tx/apply.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/core/HashRouter.h>
8#include <xrpl/core/ServiceRegistry.h>
9#include <xrpl/ledger/ApplyView.h>
10#include <xrpl/ledger/OpenView.h>
11#include <xrpl/protocol/Feature.h>
12#include <xrpl/protocol/Rules.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/STObject.h>
15#include <xrpl/protocol/STTx.h>
16#include <xrpl/protocol/TER.h>
17#include <xrpl/protocol/TxFlags.h>
18#include <xrpl/protocol/TxFormats.h>
19#include <xrpl/tx/applySteps.h>
40 auto const flags = router.
getFlags(
id);
53 bool const neverValid = rules.
enabled(fixBatchInnerSigs);
76 auto const sigVerify = tx.
checkSign(rules);
131template <
typename PreflightChecks>
135 return doApply(
preclaim(preflightChecks(), registry, view), registry, view);
142 registry, view, [&]()
mutable {
return preflight(registry, view.
rules(), tx, flags, j); });
154 return apply(registry, view, [&]()
mutable {
155 return preflight(registry, view.
rules(), parentBatchId, tx, flags, j);
163 STTx const& batchTxn,
168 "Batch transaction missing sfRawTransactions");
171 auto const mode = batchTxn.
getFlags();
173 auto applyOneTransaction = [®istry, &j, &parentBatchId, &batchView](
STTx const& tx) {
176 auto const ret =
apply(registry, perTxBatchView, parentBatchId, tx,
TapBatch, j);
179 "Inner transaction should not be applied");
181 JLOG(j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: " << tx.getTransactionID() <<
" "
182 << (ret.applied ?
"applied" :
"failure") <<
": " <<
transToken(ret.ter);
187 perTxBatchView.
apply(batchView);
196 auto const result = applyOneTransaction(
STTx{std::move(rb)});
199 "Outer Batch failure, inner transaction should not be applied");
206 if ((mode & tfAllOrNothing) != 0u)
209 if ((mode & tfUntilFailure) != 0u)
212 else if ((mode & tfOnlyOne) != 0u)
238 auto const result =
apply(registry, view, txn, flags, j);
251 wholeBatchView.
apply(view);
269 JLOG(j.
warn()) <<
"Throws: " << ex.
what();
A generic endpoint for log messages.
Routing table for objects identified by hash.
HashRouterFlags getFlags(uint256 const &key)
bool setFlags(uint256 const &key, HashRouterFlags flags)
Set the flags on a hash.
Writable ledger view that accumulates state and tx changes.
void apply(TxsRawView &to) const
Apply changes.
Rules const & rules() const override
Returns the tx processing rules.
Rules controlling protocol behavior.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
STArray const & getFieldArray(SField const &field) const
bool isFlag(std::uint32_t) const
bool isFieldPresent(SField const &field) const
std::uint32_t getFlags() const
std::expected< void, std::string > checkSign(Rules const &rules) const
Check the signature.
TxType getTxnType() const
Blob getSigningPubKey() const
uint256 getTransactionID() const
Service registry for dependency injection.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr HashRouterFlags kSfSigbad
constexpr FlagValue tfInnerBatchTxn
PreflightResult preflight(ServiceRegistry ®istry, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
PreclaimResult preclaim(PreflightResult const &preflightResult, ServiceRegistry ®istry, OpenView const &view)
Gate a transaction based on static ledger information.
Validity
Describes the pre-processing validity of a transaction.
@ SigBad
Signature is bad. Didn't do local checks.
@ Valid
Signature and local checks are good / passed.
@ SigGoodOnly
Signature is good, but local checks fail.
ApplyResult apply(ServiceRegistry ®istry, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
constexpr struct xrpl::BatchViewT kBatchView
ApplyTransactionResult applyTransaction(ServiceRegistry ®istry, OpenView &view, STTx const &tx, bool retryAssured, ApplyFlags flags, beast::Journal journal)
Transaction application helper.
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules)
Checks transaction signature and local checks.
constexpr HashRouterFlags kSfSiggood
ApplyTransactionResult
Enum class for return value from applyTransaction.
@ Success
Applied to this ledger.
@ Retry
Should be retried in this ledger.
@ Fail
Should not be retried in this ledger.
std::string transHuman(TER code)
std::string transToken(TER code)
bool isTefFailure(TER x) noexcept
bool passesLocalChecks(STObject const &st, std::string &)
static bool applyBatchTransactions(ServiceRegistry ®istry, OpenView &batchView, STTx const &batchTxn, beast::Journal j)
bool isTelLocal(TER x) noexcept
bool isTesSuccess(TER x) noexcept
bool isTecClaim(TER x) noexcept
void forceValidity(HashRouter &router, uint256 const &txid, Validity validity)
Sets the validity of a given transaction in the cache.
ApplyResult doApply(PreclaimResult const &preclaimResult, ServiceRegistry ®istry, OpenView &view)
Apply a prechecked transaction to an OpenView.
constexpr HashRouterFlags kSfLocalgood
bool isTemMalformed(TER x) noexcept
constexpr bool any(HashRouterFlags flags)
constexpr HashRouterFlags kSfLocalbad