xrpld
Loading...
Searching...
No Matches
InvariantCheck.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/protocol/STTx.h>
7#include <xrpl/protocol/TER.h>
8#include <xrpl/tx/invariants/AMMInvariant.h>
9#include <xrpl/tx/invariants/DirectoryInvariant.h>
10#include <xrpl/tx/invariants/FreezeInvariant.h>
11#include <xrpl/tx/invariants/LoanBrokerInvariant.h>
12#include <xrpl/tx/invariants/LoanInvariant.h>
13#include <xrpl/tx/invariants/MPTInvariant.h>
14#include <xrpl/tx/invariants/NFTInvariant.h>
15#include <xrpl/tx/invariants/PermissionedDEXInvariant.h>
16#include <xrpl/tx/invariants/PermissionedDomainInvariant.h>
17#include <xrpl/tx/invariants/VaultInvariant.h>
18
19#include <cstdint>
20#include <tuple>
21
22namespace xrpl {
23
24#if GENERATING_DOCS
61{
62public:
63 explicit InvariantChecker_PROTOTYPE() = default;
64
72 void
74
91 bool
93 STTx const& tx,
94 TER const tec,
95 XRPAmount const fee,
96 ReadView const& view,
97 beast::Journal const& j);
98};
99#endif
100
108{
109public:
110 void
112
113 static bool
114 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
115};
116
126{
128
129public:
130 void
132
133 [[nodiscard]] bool
134 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
135};
136
146{
148
149public:
150 void
152
153 [[nodiscard]] bool
154 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
155};
156
168{
169 // Pair is <before, after>. Before is used for most of the checks, so that
170 // if, for example, an object ID field is cleared, but the object is not
171 // deleted, it can still be found. After is used specifically for any checks
172 // that are expected as part of the deletion, such as zeroing out the
173 // balance.
175
176public:
177 void
179
180 bool
181 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
182};
183
192{
193 bool bad_ = false;
194
195public:
196 void
198
199 [[nodiscard]] bool
200 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
201};
202
208{
209 bool typeMismatch_ = false;
210 bool invalidTypeAdded_ = false;
211
212public:
213 void
215
216 [[nodiscard]] bool
217 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
218};
219
227{
228 bool xrpTrustLine_ = false;
229
230public:
231 void
233
234 [[nodiscard]] bool
235 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
236};
237
246{
248
249public:
250 void
252
253 [[nodiscard]] bool
254 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
255};
256
265{
266 bool bad_ = false;
267
268public:
269 void
271
272 [[nodiscard]] bool
273 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
274};
275
281{
282 bool bad_ = false;
283
284public:
285 void
287
288 [[nodiscard]] bool
289 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
290};
291
298{
301 bool pseudoAccount_ = false;
303
304public:
305 void
307
308 [[nodiscard]] bool
309 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
310};
311
321{
324
325public:
326 void
328
329 [[nodiscard]] bool
330 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
331};
332
342{
344
345public:
346 void
348
349 bool
350 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
351};
352
361{
362 // Pair is <before, after>.
364
365public:
366 void
368
369 bool
370 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
371};
372
377{
379
380public:
381 void
383
384 [[nodiscard]] bool
385 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
386};
387
388// additional invariant checks can be declared above and then added to this
389// tuple
410 ValidAMM,
414 ValidLoan,
420
429inline InvariantChecks
431{
432 return InvariantChecks{};
433}
434
435} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Invariant: a deleted account must not have any objects left.
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::vector< std::pair< SLE::const_pointer, SLE::const_pointer > > accountsDeleted_
Invariant: we cannot remove an account ledger entry.
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
bool finalize(STTx const &tx, TER const tec, XRPAmount const fee, ReadView const &view, beast::Journal const &j)
called after all ledger entries have been visited to determine the final status of the check.
void visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
called for each ledger entry in the current transaction.
Invariant: corresponding modified ledger entries should match in type and added entries should be a v...
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Invariant: Validates counts of NFTokens after all transaction types.
Invariant: offers should be for non-negative amounts and must not be XRP to XRP.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
Invariant: Trust lines with deep freeze flag are not allowed if normal freeze flag is not set.
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Invariants: Some fields are unmodifiable.
std::set< std::pair< SLE::const_pointer, SLE::const_pointer > > changedEntries_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
Invariant: Trust lines using XRP are not allowed.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
Invariant: an escrow entry must take a value between 0 and INITIAL_XRP drops exclusive.
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
A view into a ledger.
Definition ReadView.h:31
std::shared_ptr< STLedgerEntry const > const & const_ref
Invariant: We should never charge a transaction a negative fee or a fee that is larger than what the ...
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
static bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Invariant: frozen trust line balance change is not allowed.
Verify that MPT/XRP STAmounts are canonical in any ledger entries left after the transaction applies.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::vector< std::shared_ptr< SLE const > > afterEntries_
Invariant: Token holder's trustline balance cannot be negative after Clawback.
std::uint32_t mptokensChanged_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
std::uint32_t trustlinesChanged_
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
Invariants: Confidential MPToken consistency.
Invariants: Loan brokers are internally consistent.
Invariants: Loans are internally consistent.
Verify public MPT amount and outstanding amount accounting.
Invariant: Validates several invariants for NFToken pages.
Invariant: a new account root must be the consequence of a payment, must have the right starting sequ...
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
Invariants: Permissioned Domains must have some rules and AcceptedCredentials must have length betwee...
Invariants: Pseudo-accounts have valid and consistent properties.
std::vector< std::string > errors_
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Invariant: An account XRP balance must be in XRP and take a value between 0 and INITIAL_XRP drops,...
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
Invariant: A transaction must not create XRP and should only destroy the XRP fee.
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
InvariantChecks getInvariantChecks()
get a tuple of all invariant checks
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:554
TERSubset< CanCvtToTER > TER
Definition TER.h:634
std::tuple< TransactionFeeCheck, AccountRootsNotDeleted, AccountRootsDeletedClean, LedgerEntryTypesMatch, XRPBalanceChecks, XRPNotCreated, NoXRPTrustLines, NoDeepFreezeTrustLinesWithoutFreeze, TransfersNotFrozen, NoBadOffers, NoZeroEscrow, ValidNewAccountRoot, ValidNFTokenPage, NFTokenCountTracking, ValidClawback, ValidMPTIssuance, ValidPermissionedDomain, ValidPermissionedDEX, ValidBookDirectory, ValidAMM, NoModifiedUnmodifiableFields, ValidPseudoAccounts, ValidLoanBroker, ValidLoan, ValidVault, ValidConfidentialMPToken, ValidMPTPayment, ValidAmounts, ValidMPTTransfer > InvariantChecks