rippled
Loading...
Searching...
No Matches
InvariantCheck.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2017 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_TX_INVARIANTCHECK_H_INCLUDED
21#define RIPPLE_APP_TX_INVARIANTCHECK_H_INCLUDED
22
23#include <xrpl/basics/base_uint.h>
24#include <xrpl/beast/utility/Journal.h>
25#include <xrpl/protocol/STLedgerEntry.h>
26#include <xrpl/protocol/STTx.h>
27#include <xrpl/protocol/TER.h>
28
29#include <cstdint>
30#include <tuple>
31
32namespace ripple {
33
34class ReadView;
35
36#if GENERATING_DOCS
46{
47public:
48 explicit InvariantChecker_PROTOTYPE() = default;
49
57 void
59 bool isDelete,
60 std::shared_ptr<SLE const> const& before,
62
75 bool
77 STTx const& tx,
78 TER const tec,
79 XRPAmount const fee,
80 ReadView const& view,
81 beast::Journal const& j);
82};
83#endif
84
92{
93public:
94 void
96 bool,
99
100 bool
101 finalize(
102 STTx const&,
103 TER const,
104 XRPAmount const,
105 ReadView const&,
106 beast::Journal const&);
107};
108
118{
120
121public:
122 void
124 bool,
127
128 bool
129 finalize(
130 STTx const&,
131 TER const,
132 XRPAmount const,
133 ReadView const&,
134 beast::Journal const&);
135};
136
146{
148
149public:
150 void
152 bool,
155
156 bool
157 finalize(
158 STTx const&,
159 TER const,
160 XRPAmount const,
161 ReadView const&,
162 beast::Journal const&);
163};
164
176{
178
179public:
180 void
182 bool,
185
186 bool
187 finalize(
188 STTx const&,
189 TER const,
190 XRPAmount const,
191 ReadView const&,
192 beast::Journal const&);
193};
194
203{
204 bool bad_ = false;
205
206public:
207 void
209 bool,
212
213 bool
214 finalize(
215 STTx const&,
216 TER const,
217 XRPAmount const,
218 ReadView const&,
219 beast::Journal const&);
220};
221
227{
228 bool typeMismatch_ = false;
229 bool invalidTypeAdded_ = false;
230
231public:
232 void
234 bool,
237
238 bool
239 finalize(
240 STTx const&,
241 TER const,
242 XRPAmount const,
243 ReadView const&,
244 beast::Journal const&);
245};
246
254{
255 bool xrpTrustLine_ = false;
256
257public:
258 void
260 bool,
263
264 bool
265 finalize(
266 STTx const&,
267 TER const,
268 XRPAmount const,
269 ReadView const&,
270 beast::Journal const&);
271};
272
281{
282 bool bad_ = false;
283
284public:
285 void
287 bool,
290
291 bool
292 finalize(
293 STTx const&,
294 TER const,
295 XRPAmount const,
296 ReadView const&,
297 beast::Journal const&);
298};
299
305{
306 bool bad_ = false;
307
308public:
309 void
311 bool,
314
315 bool
316 finalize(
317 STTx const&,
318 TER const,
319 XRPAmount const,
320 ReadView const&,
321 beast::Journal const&);
322};
323
330{
333
334public:
335 void
337 bool,
340
341 bool
342 finalize(
343 STTx const&,
344 TER const,
345 XRPAmount const,
346 ReadView const&,
347 beast::Journal const&);
348};
349
362{
363 bool badEntry_ = false;
364 bool badLink_ = false;
365 bool badSort_ = false;
366 bool badURI_ = false;
367 bool invalidSize_ = false;
368 bool deletedFinalPage_ = false;
369 bool deletedLink_ = false;
370
371public:
372 void
374 bool,
377
378 bool
379 finalize(
380 STTx const&,
381 TER const,
382 XRPAmount const,
383 ReadView const&,
384 beast::Journal const&);
385};
386
401{
406
407public:
408 void
410 bool,
413
414 bool
415 finalize(
416 STTx const&,
417 TER const,
418 XRPAmount const,
419 ReadView const&,
420 beast::Journal const&);
421};
422
432{
435
436public:
437 void
439 bool,
442
443 bool
444 finalize(
445 STTx const&,
446 TER const,
447 XRPAmount const,
448 ReadView const&,
449 beast::Journal const&);
450};
451
453{
456
459
460public:
461 void
463 bool,
466
467 bool
468 finalize(
469 STTx const&,
470 TER const,
471 XRPAmount const,
472 ReadView const&,
473 beast::Journal const&);
474};
475
487{
489 {
491 bool isSorted_ = false, isUnique_ = false;
492 };
494
495public:
496 void
498 bool,
501
502 bool
503 finalize(
504 STTx const&,
505 TER const,
506 XRPAmount const,
507 ReadView const&,
508 beast::Journal const&);
509};
510
511// additional invariant checks can be declared above and then added to this
512// tuple
529
538inline InvariantChecks
540{
541 return InvariantChecks{};
542}
543
544} // namespace ripple
545
546#endif
A generic endpoint for log messages.
Definition: Journal.h:59
Invariant: a deleted account must not have any objects left.
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 &)
std::vector< std::shared_ptr< SLE const > > accountsDeleted_
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 &)
Prototype for invariant check implementations.
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.
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
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 &)
Invariant: Validates counts of NFTokens after all transaction types.
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: offers should be for non-negative amounts and must not be XRP to XRP.
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 &)
Invariant: Trust lines using XRP are not allowed.
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: an escrow entry must take a value between 0 and INITIAL_XRP drops exclusive.
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 &)
A view into a ledger.
Definition: ReadView.h:55
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 &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Invariant: Token holder's trustline balance cannot be negative after Clawback.
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::uint32_t trustlinesChanged
std::uint32_t mptokensChanged
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::uint32_t mptIssuancesCreated_
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::uint32_t mptokensCreated_
std::uint32_t mptIssuancesDeleted_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::uint32_t mptokensDeleted_
Invariant: Validates several invariants for NFToken pages.
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 &)
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 &)
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...
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::optional< SleStatus > sleStatus_[2]
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 &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Invariant: A transaction must not create XRP and should only destroy the XRP fee.
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 &)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
InvariantChecks getInvariantChecks()
get a tuple of all invariant checks
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:89