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/Number.h>
24#include <xrpl/basics/base_uint.h>
25#include <xrpl/beast/utility/Journal.h>
26#include <xrpl/protocol/MPTIssue.h>
27#include <xrpl/protocol/STLedgerEntry.h>
28#include <xrpl/protocol/STTx.h>
29#include <xrpl/protocol/TER.h>
30
31#include <cstdint>
32#include <tuple>
33#include <unordered_set>
34
35namespace ripple {
36
37class ReadView;
38
39#if GENERATING_DOCS
49{
50public:
51 explicit InvariantChecker_PROTOTYPE() = default;
52
60 void
62 bool isDelete,
63 std::shared_ptr<SLE const> const& before,
65
78 bool
80 STTx const& tx,
81 TER const tec,
82 XRPAmount const fee,
83 ReadView const& view,
84 beast::Journal const& j);
85};
86#endif
87
95{
96public:
97 void
99 bool,
102
103 bool
104 finalize(
105 STTx const&,
106 TER const,
107 XRPAmount const,
108 ReadView const&,
109 beast::Journal const&);
110};
111
121{
123
124public:
125 void
127 bool,
130
131 bool
132 finalize(
133 STTx const&,
134 TER const,
135 XRPAmount const,
136 ReadView const&,
137 beast::Journal const&);
138};
139
149{
151
152public:
153 void
155 bool,
158
159 bool
160 finalize(
161 STTx const&,
162 TER const,
163 XRPAmount const,
164 ReadView const&,
165 beast::Journal const&);
166};
167
179{
181
182public:
183 void
185 bool,
188
189 bool
190 finalize(
191 STTx const&,
192 TER const,
193 XRPAmount const,
194 ReadView const&,
195 beast::Journal const&);
196};
197
206{
207 bool bad_ = false;
208
209public:
210 void
212 bool,
215
216 bool
217 finalize(
218 STTx const&,
219 TER const,
220 XRPAmount const,
221 ReadView const&,
222 beast::Journal const&);
223};
224
230{
231 bool typeMismatch_ = false;
232 bool invalidTypeAdded_ = false;
233
234public:
235 void
237 bool,
240
241 bool
242 finalize(
243 STTx const&,
244 TER const,
245 XRPAmount const,
246 ReadView const&,
247 beast::Journal const&);
248};
249
257{
258 bool xrpTrustLine_ = false;
259
260public:
261 void
263 bool,
266
267 bool
268 finalize(
269 STTx const&,
270 TER const,
271 XRPAmount const,
272 ReadView const&,
273 beast::Journal const&);
274};
275
284{
286
287public:
288 void
290 bool,
293
294 bool
295 finalize(
296 STTx const&,
297 TER const,
298 XRPAmount const,
299 ReadView const&,
300 beast::Journal const&);
301};
302
310{
316
322
325
327
328public:
329 void
331 bool,
334
335 bool
336 finalize(
337 STTx const&,
338 TER const,
339 XRPAmount const,
340 ReadView const&,
341 beast::Journal const&);
342
343private:
344 bool
346 std::shared_ptr<SLE const> const& before,
348
351 std::shared_ptr<SLE const> const& before,
353 bool isDelete);
354
355 void
356 recordBalance(Issue const& issue, BalanceChange change);
357
358 void
361 STAmount const& balanceChange);
362
364 findIssuer(AccountID const& issuerID, ReadView const& view);
365
366 bool
368 std::shared_ptr<SLE const> const& issuer,
369 IssuerChanges const& changes,
370 STTx const& tx,
371 beast::Journal const& j,
372 bool enforce);
373
374 bool
376 BalanceChange const& change,
377 bool high,
378 STTx const& tx,
379 beast::Journal const& j,
380 bool enforce,
381 bool globalFreeze);
382};
383
392{
393 bool bad_ = false;
394
395public:
396 void
398 bool,
401
402 bool
403 finalize(
404 STTx const&,
405 TER const,
406 XRPAmount const,
407 ReadView const&,
408 beast::Journal const&);
409};
410
416{
417 bool bad_ = false;
418
419public:
420 void
422 bool,
425
426 bool
427 finalize(
428 STTx const&,
429 TER const,
430 XRPAmount const,
431 ReadView const&,
432 beast::Journal const&);
433};
434
441{
444 bool pseudoAccount_ = false;
446
447public:
448 void
450 bool,
453
454 bool
455 finalize(
456 STTx const&,
457 TER const,
458 XRPAmount const,
459 ReadView const&,
460 beast::Journal const&);
461};
462
475{
476 bool badEntry_ = false;
477 bool badLink_ = false;
478 bool badSort_ = false;
479 bool badURI_ = false;
480 bool invalidSize_ = false;
481 bool deletedFinalPage_ = false;
482 bool deletedLink_ = false;
483
484public:
485 void
487 bool,
490
491 bool
492 finalize(
493 STTx const&,
494 TER const,
495 XRPAmount const,
496 ReadView const&,
497 beast::Journal const&);
498};
499
514{
519
520public:
521 void
523 bool,
526
527 bool
528 finalize(
529 STTx const&,
530 TER const,
531 XRPAmount const,
532 ReadView const&,
533 beast::Journal const&);
534};
535
545{
548
549public:
550 void
552 bool,
555
556 bool
557 finalize(
558 STTx const&,
559 TER const,
560 XRPAmount const,
561 ReadView const&,
562 beast::Journal const&);
563};
564
566{
569
572
573public:
574 void
576 bool,
579
580 bool
581 finalize(
582 STTx const&,
583 TER const,
584 XRPAmount const,
585 ReadView const&,
586 beast::Journal const&);
587};
588
600{
602 {
604 bool isSorted_ = false, isUnique_ = false;
605 };
607
608public:
609 void
611 bool,
614
615 bool
616 finalize(
617 STTx const&,
618 TER const,
619 XRPAmount const,
620 ReadView const&,
621 beast::Journal const&);
622};
623
633{
635
636public:
637 void
639 bool,
642
643 bool
644 finalize(
645 STTx const&,
646 TER const,
647 XRPAmount const,
648 ReadView const&,
649 beast::Journal const&);
650};
651
653{
654 bool regularOffers_ = false;
655 bool badHybrids_ = false;
657
658public:
659 void
661 bool,
664
665 bool
666 finalize(
667 STTx const&,
668 TER const,
669 XRPAmount const,
670 ReadView const&,
671 beast::Journal const&);
672};
673
675{
680
681public:
682 enum class ZeroAllowed : bool { No = false, Yes = true };
683
685 {
686 }
687 void
689 bool,
692
693 bool
694 finalize(
695 STTx const&,
696 TER const,
697 XRPAmount const,
698 ReadView const&,
699 beast::Journal const&);
700
701private:
702 bool
703 finalizeBid(bool enforce, beast::Journal const&) const;
704 bool
705 finalizeVote(bool enforce, beast::Journal const&) const;
706 bool
708 STTx const&,
709 ReadView const&,
710 bool enforce,
711 beast::Journal const&) const;
712 bool
713 finalizeDelete(bool enforce, TER res, beast::Journal const&) const;
714 bool
716 STTx const&,
717 ReadView const&,
718 bool enforce,
719 beast::Journal const&) const;
720 // Includes clawback
721 bool
723 STTx const&,
724 ReadView const&,
725 bool enforce,
726 beast::Journal const&) const;
727 bool
728 finalizeDEX(bool enforce, beast::Journal const&) const;
729 bool
731 STTx const&,
732 ReadView const&,
733 ZeroAllowed zeroAllowed,
734 beast::Journal const&) const;
735};
736
757{
758 Number static constexpr zero{};
759
760 struct Vault final
761 {
762 uint256 key = beast::zero;
765 uint192 shareMPTID = beast::zero;
770
771 Vault static make(SLE const&);
772 };
773
774 struct Shares final
775 {
779
780 Shares static make(SLE const&);
781 };
782
788
789public:
790 void
792 bool,
795
796 bool
797 finalize(
798 STTx const&,
799 TER const,
800 XRPAmount const,
801 ReadView const&,
802 beast::Journal const&);
803};
804
805// additional invariant checks can be declared above and then added to this
806// tuple
826 ValidAMM,
828 ValidVault>;
829
838inline InvariantChecks
840{
841 return InvariantChecks{};
842}
843
844} // namespace ripple
845
846#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 &)
Invariants: Vault object and MPTokenIssuance for vault shares.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::vector< Shares > beforeMPTs_
std::vector< Vault > beforeVault_
std::unordered_map< uint256, Number > deltas_
static Number constexpr zero
std::vector< Shares > afterMPTs_
std::vector< Vault > afterVault_
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:3266
InvariantChecks getInvariantChecks()
get a tuple of all invariant checks
std::shared_ptr< SLE const > const line
std::vector< BalanceChange > receivers
std::vector< BalanceChange > senders
static Shares make(SLE const &)
static Vault make(SLE const &)