1#include <xrpl/tx/invariants/InvariantRunner.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/ServiceRegistry.h>
8#include <xrpl/json/to_string.h>
9#include <xrpl/protocol/TER.h>
10#include <xrpl/protocol/XRPAmount.h>
11#include <xrpl/tx/ApplyContext.h>
12#include <xrpl/tx/invariants/InvariantCheck.h>
28failInvariantCheck(
TER const result)
35template <std::size_t... Is>
41 std::optional<std::reference_wrapper<TxInvariantCheck>> txCheck,
42 std::index_sequence<Is...>)
52 txCheck->get().visitEntry(isDelete, before,
after);
53 (..., std::get<Is>(checkers).visitEntry(isDelete, before,
after));
58 if (!txCheck->get().finalize(ctx.tx, result, fee, ctx.view(), ctx.journal))
60 JLOG(ctx.journal.fatal())
61 <<
"Transaction has failed one or more transaction invariants: "
72 std::array<bool,
sizeof...(Is)>
const finalizers{
73 {std::get<Is>(checkers).finalize(ctx.tx, result, fee, ctx.view(), ctx.journal)...}};
75 if (!
std::all_of(finalizers.cbegin(), finalizers.cend(), [](
auto const& b) { return b; }))
77 JLOG(ctx.journal.fatal()) <<
"Transaction has failed one or more global invariants: "
82 catch (std::exception
const& ex)
84 JLOG(ctx.journal.fatal()) <<
"Transaction caused an exception during invariant checks"
85 <<
", ex: " << ex.
what() <<
", tx: "
87 return failInvariantCheck(result);
90 return allOk ? result : failInvariantCheck(result);
104 "xrpl::checkInvariants : is tesSUCCESS or tecCLAIM");
106 return checkInvariantsHelper(
State information when applying a tx.
std::shared_ptr< STLedgerEntry const > const & ConstRef
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
InvariantChecks getInvariantChecks()
get a tuple of all invariant checks
std::string to_string(BaseUInt< Bits, Tag > const &a)
TER checkInvariants(ApplyContext &ctx, TER result, XRPAmount fee, std::optional< std::reference_wrapper< TxInvariantCheck > > txCheck)
Run all protocol invariant checks plus the transaction-specific check in a single pass over the modif...
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
bool isTecClaim(TER x) noexcept