rippled
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/FreezeInvariant.h>
10#include <xrpl/tx/invariants/LoanBrokerInvariant.h>
11#include <xrpl/tx/invariants/LoanInvariant.h>
12#include <xrpl/tx/invariants/MPTInvariant.h>
13#include <xrpl/tx/invariants/NFTInvariant.h>
14#include <xrpl/tx/invariants/PermissionedDEXInvariant.h>
15#include <xrpl/tx/invariants/PermissionedDomainInvariant.h>
16#include <xrpl/tx/invariants/VaultInvariant.h>
17
18#include <cstdint>
19#include <tuple>
20
21namespace xrpl {
22
23#if GENERATING_DOCS
60{
61public:
62 explicit InvariantChecker_PROTOTYPE() = default;
63
71 void
73 bool isDelete,
74 std::shared_ptr<SLE const> const& before,
76
93 bool
95 STTx const& tx,
96 TER const tec,
97 XRPAmount const fee,
98 ReadView const& view,
99 beast::Journal const& j);
100};
101#endif
102
110{
111public:
112 void
114
115 static bool
116 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
117};
118
128{
130
131public:
132 void
134
135 bool
136 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
137};
138
148{
150
151public:
152 void
154
155 bool
156 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
157};
158
170{
171 // Pair is <before, after>. Before is used for most of the checks, so that
172 // if, for example, an object ID field is cleared, but the object is not
173 // deleted, it can still be found. After is used specifically for any checks
174 // that are expected as part of the deletion, such as zeroing out the
175 // balance.
177
178public:
179 void
181
182 bool
183 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
184};
185
194{
195 bool bad_ = false;
196
197public:
198 void
200
201 bool
202 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
203};
204
210{
211 bool typeMismatch_ = false;
212 bool invalidTypeAdded_ = false;
213
214public:
215 void
217
218 bool
219 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
220};
221
229{
230 bool xrpTrustLine_ = false;
231
232public:
233 void
235
236 bool
237 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
238};
239
248{
250
251public:
252 void
254
255 bool
256 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
257};
258
267{
268 bool bad_ = false;
269
270public:
271 void
273
274 bool
275 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
276};
277
283{
284 bool bad_ = false;
285
286public:
287 void
289
290 bool
291 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
292};
293
300{
303 bool pseudoAccount_ = false;
305
306public:
307 void
309
310 bool
311 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
312};
313
323{
326
327public:
328 void
330
331 bool
332 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
333};
334
344{
346
347public:
348 void
350
351 bool
352 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
353};
354
363{
364 // Pair is <before, after>.
366
367public:
368 void
370
371 bool
372 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
373};
374
375// additional invariant checks can be declared above and then added to this
376// tuple
396 ValidAMM,
400 ValidLoan,
401 ValidVault>;
402
411inline InvariantChecks
413{
414 return InvariantChecks{};
415}
416
417} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Invariant: a deleted account must not have any objects left.
std::vector< std::pair< std::shared_ptr< SLE const >, std::shared_ptr< SLE const > > > accountsDeleted_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Invariant: we cannot remove an account ledger entry.
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Prototype for invariant check implementations.
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, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &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, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
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, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Invariant: Trust lines with deep freeze flag are not allowed if normal freeze flag is not set.
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Invariants: Some fields are unmodifiable.
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::set< std::pair< SLE::const_pointer, SLE::const_pointer > > changedEntries_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Invariant: Trust lines using XRP are not allowed.
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Invariant: an escrow entry must take a value between 0 and INITIAL_XRP drops exclusive.
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 &)
A view into a ledger.
Definition ReadView.h:31
Invariant: We should never charge a transaction a negative fee or a fee that is larger than what the ...
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
static bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Invariant: frozen trust line balance change is not allowed.
Invariant: Token holder's trustline balance cannot be negative after Clawback.
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::uint32_t trustlinesChanged
std::uint32_t mptokensChanged
Invariants: Loan brokers are internally consistent.
Invariants: Loans are internally consistent.
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, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Invariants: Permissioned Domains must have some rules and AcceptedCredentials must have length betwee...
Invariants: Pseudo-accounts have valid and consistent properties.
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::vector< std::string > errors_
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,...
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Invariant: A transaction must not create XRP and should only destroy the XRP fee.
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 &)
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:523