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#include <unordered_set>
32
33namespace ripple {
34
35class ReadView;
36
37#if GENERATING_DOCS
47{
48public:
49 explicit InvariantChecker_PROTOTYPE() = default;
50
58 void
60 bool isDelete,
61 std::shared_ptr<SLE const> const& before,
63
76 bool
78 STTx const& tx,
79 TER const tec,
80 XRPAmount const fee,
81 ReadView const& view,
82 beast::Journal const& j);
83};
84#endif
85
93{
94public:
95 void
97 bool,
100
101 bool
102 finalize(
103 STTx const&,
104 TER const,
105 XRPAmount const,
106 ReadView const&,
107 beast::Journal const&);
108};
109
119{
121
122public:
123 void
125 bool,
128
129 bool
130 finalize(
131 STTx const&,
132 TER const,
133 XRPAmount const,
134 ReadView const&,
135 beast::Journal const&);
136};
137
147{
149
150public:
151 void
153 bool,
156
157 bool
158 finalize(
159 STTx const&,
160 TER const,
161 XRPAmount const,
162 ReadView const&,
163 beast::Journal const&);
164};
165
177{
179
180public:
181 void
183 bool,
186
187 bool
188 finalize(
189 STTx const&,
190 TER const,
191 XRPAmount const,
192 ReadView const&,
193 beast::Journal const&);
194};
195
204{
205 bool bad_ = false;
206
207public:
208 void
210 bool,
213
214 bool
215 finalize(
216 STTx const&,
217 TER const,
218 XRPAmount const,
219 ReadView const&,
220 beast::Journal const&);
221};
222
228{
229 bool typeMismatch_ = false;
230 bool invalidTypeAdded_ = false;
231
232public:
233 void
235 bool,
238
239 bool
240 finalize(
241 STTx const&,
242 TER const,
243 XRPAmount const,
244 ReadView const&,
245 beast::Journal const&);
246};
247
255{
256 bool xrpTrustLine_ = false;
257
258public:
259 void
261 bool,
264
265 bool
266 finalize(
267 STTx const&,
268 TER const,
269 XRPAmount const,
270 ReadView const&,
271 beast::Journal const&);
272};
273
282{
284
285public:
286 void
288 bool,
291
292 bool
293 finalize(
294 STTx const&,
295 TER const,
296 XRPAmount const,
297 ReadView const&,
298 beast::Journal const&);
299};
300
308{
314
320
323
325
326public:
327 void
329 bool,
332
333 bool
334 finalize(
335 STTx const&,
336 TER const,
337 XRPAmount const,
338 ReadView const&,
339 beast::Journal const&);
340
341private:
342 bool
344 std::shared_ptr<SLE const> const& before,
346
349 std::shared_ptr<SLE const> const& before,
351 bool isDelete);
352
353 void
354 recordBalance(Issue const& issue, BalanceChange change);
355
356 void
359 STAmount const& balanceChange);
360
362 findIssuer(AccountID const& issuerID, ReadView const& view);
363
364 bool
366 std::shared_ptr<SLE const> const& issuer,
367 IssuerChanges const& changes,
368 STTx const& tx,
369 beast::Journal const& j,
370 bool enforce);
371
372 bool
374 BalanceChange const& change,
375 bool high,
376 STTx const& tx,
377 beast::Journal const& j,
378 bool enforce,
379 bool globalFreeze);
380};
381
390{
391 bool bad_ = false;
392
393public:
394 void
396 bool,
399
400 bool
401 finalize(
402 STTx const&,
403 TER const,
404 XRPAmount const,
405 ReadView const&,
406 beast::Journal const&);
407};
408
414{
415 bool bad_ = false;
416
417public:
418 void
420 bool,
423
424 bool
425 finalize(
426 STTx const&,
427 TER const,
428 XRPAmount const,
429 ReadView const&,
430 beast::Journal const&);
431};
432
439{
442 bool pseudoAccount_ = false;
444
445public:
446 void
448 bool,
451
452 bool
453 finalize(
454 STTx const&,
455 TER const,
456 XRPAmount const,
457 ReadView const&,
458 beast::Journal const&);
459};
460
473{
474 bool badEntry_ = false;
475 bool badLink_ = false;
476 bool badSort_ = false;
477 bool badURI_ = false;
478 bool invalidSize_ = false;
479 bool deletedFinalPage_ = false;
480 bool deletedLink_ = false;
481
482public:
483 void
485 bool,
488
489 bool
490 finalize(
491 STTx const&,
492 TER const,
493 XRPAmount const,
494 ReadView const&,
495 beast::Journal const&);
496};
497
512{
517
518public:
519 void
521 bool,
524
525 bool
526 finalize(
527 STTx const&,
528 TER const,
529 XRPAmount const,
530 ReadView const&,
531 beast::Journal const&);
532};
533
543{
546
547public:
548 void
550 bool,
553
554 bool
555 finalize(
556 STTx const&,
557 TER const,
558 XRPAmount const,
559 ReadView const&,
560 beast::Journal const&);
561};
562
564{
567
570
571public:
572 void
574 bool,
577
578 bool
579 finalize(
580 STTx const&,
581 TER const,
582 XRPAmount const,
583 ReadView const&,
584 beast::Journal const&);
585};
586
598{
600 {
602 bool isSorted_ = false, isUnique_ = false;
603 };
605
606public:
607 void
609 bool,
612
613 bool
614 finalize(
615 STTx const&,
616 TER const,
617 XRPAmount const,
618 ReadView const&,
619 beast::Journal const&);
620};
621
631{
633
634public:
635 void
637 bool,
640
641 bool
642 finalize(
643 STTx const&,
644 TER const,
645 XRPAmount const,
646 ReadView const&,
647 beast::Journal const&);
648};
649
651{
652 bool regularOffers_ = false;
653 bool badHybrids_ = false;
655
656public:
657 void
659 bool,
662
663 bool
664 finalize(
665 STTx const&,
666 TER const,
667 XRPAmount const,
668 ReadView const&,
669 beast::Journal const&);
670};
671
673{
678
679public:
680 enum class ZeroAllowed : bool { No = false, Yes = true };
681
683 {
684 }
685 void
687 bool,
690
691 bool
692 finalize(
693 STTx const&,
694 TER const,
695 XRPAmount const,
696 ReadView const&,
697 beast::Journal const&);
698
699private:
700 bool
701 finalizeBid(bool enforce, beast::Journal const&) const;
702 bool
703 finalizeVote(bool enforce, beast::Journal const&) const;
704 bool
706 STTx const&,
707 ReadView const&,
708 bool enforce,
709 beast::Journal const&) const;
710 bool
711 finalizeDelete(bool enforce, TER res, beast::Journal const&) const;
712 bool
714 STTx const&,
715 ReadView const&,
716 bool enforce,
717 beast::Journal const&) const;
718 // Includes clawback
719 bool
721 STTx const&,
722 ReadView const&,
723 bool enforce,
724 beast::Journal const&) const;
725 bool
726 finalizeDEX(bool enforce, beast::Journal const&) const;
727 bool
729 STTx const&,
730 ReadView const&,
731 ZeroAllowed zeroAllowed,
732 beast::Journal const&) const;
733};
734
735// additional invariant checks can be declared above and then added to this
736// tuple
756 ValidAMM,
758
767inline InvariantChecks
769{
770 return InvariantChecks{};
771}
772
773} // namespace ripple
774
775#endif
A generic endpoint for log messages.
Definition Journal.h:60
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
A currency issued by an account.
Definition Issue.h:33
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 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 &)
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:51
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: frozen trust line balance change is not allowed.
std::map< AccountID, std::shared_ptr< SLE const > const > possibleIssuers_
bool isValidEntry(std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)
void recordBalance(Issue const &issue, BalanceChange change)
std::shared_ptr< SLE const > findIssuer(AccountID const &issuerID, ReadView const &view)
bool validateIssuerChanges(std::shared_ptr< SLE const > const &issuer, IssuerChanges const &changes, STTx const &tx, beast::Journal const &j, bool enforce)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
STAmount calculateBalanceChange(std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after, bool isDelete)
void recordBalanceChanges(std::shared_ptr< SLE const > const &after, STAmount const &balanceChange)
bool validateFrozenState(BalanceChange const &change, bool high, STTx const &tx, beast::Journal const &j, bool enforce, bool globalFreeze)
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 &)
bool finalizeWithdraw(STTx const &, ReadView const &, bool enforce, beast::Journal const &) const
bool finalizeDEX(bool enforce, beast::Journal const &) const
std::optional< STAmount > lptAMMBalanceAfter_
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalizeBid(bool enforce, beast::Journal const &) const
std::optional< AccountID > ammAccount_
bool finalizeDelete(bool enforce, TER res, beast::Journal const &) const
bool finalizeCreate(STTx const &, ReadView const &, bool enforce, beast::Journal const &) const
bool finalizeVote(bool enforce, beast::Journal const &) const
bool finalizeDeposit(STTx const &, ReadView const &, bool enforce, beast::Journal const &) const
bool generalInvariant(STTx const &, ReadView const &, ZeroAllowed zeroAllowed, beast::Journal const &) const
std::optional< STAmount > lptAMMBalanceBefore_
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 mptIssuancesDeleted_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
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 &)
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 &)
hash_set< uint256 > domains_
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 &)
Invariants: Pseudo-accounts have valid and consisent properties.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::vector< std::string > errors_
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > 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:25
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:3239
InvariantChecks getInvariantChecks()
get a tuple of all invariant checks
std::shared_ptr< SLE const > const line
std::vector< BalanceChange > receivers
std::vector< BalanceChange > senders