xrpld
Loading...
Searching...
No Matches
InvariantCheck.h
1#pragma once
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/ledger/ReadView.h>
5#include <xrpl/protocol/STLedgerEntry.h>
6#include <xrpl/protocol/STTx.h>
7#include <xrpl/protocol/TER.h>
8#include <xrpl/protocol/XRPAmount.h>
9#include <xrpl/tx/invariants/AMMInvariant.h>
10#include <xrpl/tx/invariants/DirectoryInvariant.h>
11#include <xrpl/tx/invariants/FreezeInvariant.h>
12#include <xrpl/tx/invariants/LoanBrokerInvariant.h>
13#include <xrpl/tx/invariants/LoanInvariant.h>
14#include <xrpl/tx/invariants/MPTInvariant.h>
15#include <xrpl/tx/invariants/NFTInvariant.h>
16#include <xrpl/tx/invariants/PermissionedDEXInvariant.h>
17#include <xrpl/tx/invariants/PermissionedDomainInvariant.h>
18#include <xrpl/tx/invariants/SponsorshipInvariant.h>
19#include <xrpl/tx/invariants/VaultInvariant.h>
20
21#include <cstdint>
22#include <set>
23#include <string>
24#include <tuple>
25#include <utility>
26#include <vector>
27
28namespace xrpl {
29
30#if GENERATING_DOCS
67{
68public:
69 explicit InvariantChecker_PROTOTYPE() = default;
70
87 void
89
106 bool
108 STTx const& tx,
109 TER const tec,
110 XRPAmount const fee,
111 ReadView const& view,
112 beast::Journal const& j);
113};
114#endif
115
123{
124public:
125 void
127
128 static bool
129 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
130};
131
141{
143
144public:
145 void
147
148 [[nodiscard]] bool
149 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
150};
151
161{
163
164public:
165 void
167
168 [[nodiscard]] bool
169 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
170};
171
183{
184 // Pair is <before, after>. Before is used for most of the checks, so that
185 // if, for example, an object ID field is cleared, but the object is not
186 // deleted, it can still be found. After is used specifically for any checks
187 // that are expected as part of the deletion, such as zeroing out the
188 // balance.
190
191public:
192 void
194
195 bool
196 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
197};
198
207{
208 bool bad_ = false;
209
210public:
211 void
213
214 [[nodiscard]] bool
215 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
216};
217
223{
224 bool typeMismatch_ = false;
225 bool invalidTypeAdded_ = false;
226
227public:
228 void
230
231 [[nodiscard]] bool
232 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
233};
234
242{
243 bool xrpTrustLine_ = false;
244
245public:
246 void
248
249 [[nodiscard]] bool
250 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
251};
252
261{
263
264public:
265 void
267
268 [[nodiscard]] bool
269 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
270};
271
280{
281 bool bad_ = false;
282
283public:
284 void
286
287 [[nodiscard]] bool
288 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
289};
290
296{
297 bool bad_ = false;
298
299public:
300 void
302
303 [[nodiscard]] bool
304 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
305};
306
313{
316 bool pseudoAccount_ = false;
318
319public:
320 void
322
323 [[nodiscard]] bool
324 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
325};
326
337{
343
348
349public:
350 void
352
353 [[nodiscard]] bool
354 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
355};
356
366{
368
369public:
370 void
372
373 bool
374 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
375};
376
385{
386 // Pair is <before, after>.
388
389public:
390 void
392
393 bool
394 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
395};
396
402{
404
405public:
406 void
408
409 [[nodiscard]] bool
410 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
411};
412
413/*
414 * Verify that when an object with an associated pseudo-account is deleted,
415 * its pseudo-account is also deleted.
416 *
417 * The reverse (pseudo-account deleted → object deleted) is enforced by
418 * AccountRootsDeletedClean via getPseudoAccountFields().
419 */
421{
422public:
423 void
425
426 [[nodiscard]] bool
427 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
428
429private:
431};
432// additional invariant checks can be declared above and then added to this
433// tuple
454 ValidAMM,
458 ValidLoan,
467
476inline InvariantChecks
478{
479 return InvariantChecks{};
480}
481
482} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
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 kInitialXRP 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
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
std::vector< SLE::const_pointer > deletedObjSles_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry const > const & const_ref
std::shared_ptr< STLedgerEntry const > const_pointer
Invariant: Sponsoring account relationships tracked consistently.
Invariant: Sponsored owner counts are balanced.
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.
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
std::vector< SLE::const_pointer > afterEntries_
Invariant: Token holder's trustline/MPT balance cannot be invalid 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 &)
Invariants: Vault object and MPTokenIssuance for vault shares.
Invariant: An account XRP balance must be in XRP and take a value between 0 and kInitialXRP 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:572
TERSubset< CanCvtToTER > TER
Definition TER.h:647
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, ValidMPTBalanceChanges, ValidAmounts, ValidMPTTransfer, ObjectHasPseudoAccount, SponsorshipOwnerCountsMatch, SponsorshipAccountCountMatchesField > InvariantChecks