rippled
Loading...
Searching...
No Matches
InvariantCheck.h
1#ifndef XRPL_APP_TX_INVARIANTCHECK_H_INCLUDED
2#define XRPL_APP_TX_INVARIANTCHECK_H_INCLUDED
3
4#include <xrpl/basics/Number.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/protocol/MPTIssue.h>
8#include <xrpl/protocol/STLedgerEntry.h>
9#include <xrpl/protocol/STTx.h>
10#include <xrpl/protocol/TER.h>
11
12#include <cstdint>
13#include <tuple>
14#include <unordered_set>
15
16namespace ripple {
17
18class ReadView;
19
20#if GENERATING_DOCS
30{
31public:
32 explicit InvariantChecker_PROTOTYPE() = default;
33
41 void
43 bool isDelete,
44 std::shared_ptr<SLE const> const& before,
46
59 bool
61 STTx const& tx,
62 TER const tec,
63 XRPAmount const fee,
64 ReadView const& view,
65 beast::Journal const& j);
66};
67#endif
68
76{
77public:
78 void
80 bool,
83
84 bool
86 STTx const&,
87 TER const,
88 XRPAmount const,
89 ReadView const&,
90 beast::Journal const&);
91};
92
102{
104
105public:
106 void
108 bool,
111
112 bool
113 finalize(
114 STTx const&,
115 TER const,
116 XRPAmount const,
117 ReadView const&,
118 beast::Journal const&);
119};
120
130{
132
133public:
134 void
136 bool,
139
140 bool
141 finalize(
142 STTx const&,
143 TER const,
144 XRPAmount const,
145 ReadView const&,
146 beast::Journal const&);
147};
148
160{
162
163public:
164 void
166 bool,
169
170 bool
171 finalize(
172 STTx const&,
173 TER const,
174 XRPAmount const,
175 ReadView const&,
176 beast::Journal const&);
177};
178
187{
188 bool bad_ = false;
189
190public:
191 void
193 bool,
196
197 bool
198 finalize(
199 STTx const&,
200 TER const,
201 XRPAmount const,
202 ReadView const&,
203 beast::Journal const&);
204};
205
211{
212 bool typeMismatch_ = false;
213 bool invalidTypeAdded_ = false;
214
215public:
216 void
218 bool,
221
222 bool
223 finalize(
224 STTx const&,
225 TER const,
226 XRPAmount const,
227 ReadView const&,
228 beast::Journal const&);
229};
230
238{
239 bool xrpTrustLine_ = false;
240
241public:
242 void
244 bool,
247
248 bool
249 finalize(
250 STTx const&,
251 TER const,
252 XRPAmount const,
253 ReadView const&,
254 beast::Journal const&);
255};
256
265{
267
268public:
269 void
271 bool,
274
275 bool
276 finalize(
277 STTx const&,
278 TER const,
279 XRPAmount const,
280 ReadView const&,
281 beast::Journal const&);
282};
283
291{
297
303
306
308
309public:
310 void
312 bool,
315
316 bool
317 finalize(
318 STTx const&,
319 TER const,
320 XRPAmount const,
321 ReadView const&,
322 beast::Journal const&);
323
324private:
325 bool
327 std::shared_ptr<SLE const> const& before,
329
332 std::shared_ptr<SLE const> const& before,
334 bool isDelete);
335
336 void
337 recordBalance(Issue const& issue, BalanceChange change);
338
339 void
342 STAmount const& balanceChange);
343
345 findIssuer(AccountID const& issuerID, ReadView const& view);
346
347 bool
349 std::shared_ptr<SLE const> const& issuer,
350 IssuerChanges const& changes,
351 STTx const& tx,
352 beast::Journal const& j,
353 bool enforce);
354
355 bool
357 BalanceChange const& change,
358 bool high,
359 STTx const& tx,
360 beast::Journal const& j,
361 bool enforce,
362 bool globalFreeze);
363};
364
373{
374 bool bad_ = false;
375
376public:
377 void
379 bool,
382
383 bool
384 finalize(
385 STTx const&,
386 TER const,
387 XRPAmount const,
388 ReadView const&,
389 beast::Journal const&);
390};
391
397{
398 bool bad_ = false;
399
400public:
401 void
403 bool,
406
407 bool
408 finalize(
409 STTx const&,
410 TER const,
411 XRPAmount const,
412 ReadView const&,
413 beast::Journal const&);
414};
415
422{
425 bool pseudoAccount_ = false;
427
428public:
429 void
431 bool,
434
435 bool
436 finalize(
437 STTx const&,
438 TER const,
439 XRPAmount const,
440 ReadView const&,
441 beast::Journal const&);
442};
443
456{
457 bool badEntry_ = false;
458 bool badLink_ = false;
459 bool badSort_ = false;
460 bool badURI_ = false;
461 bool invalidSize_ = false;
462 bool deletedFinalPage_ = false;
463 bool deletedLink_ = false;
464
465public:
466 void
468 bool,
471
472 bool
473 finalize(
474 STTx const&,
475 TER const,
476 XRPAmount const,
477 ReadView const&,
478 beast::Journal const&);
479};
480
495{
500
501public:
502 void
504 bool,
507
508 bool
509 finalize(
510 STTx const&,
511 TER const,
512 XRPAmount const,
513 ReadView const&,
514 beast::Journal const&);
515};
516
526{
529
530public:
531 void
533 bool,
536
537 bool
538 finalize(
539 STTx const&,
540 TER const,
541 XRPAmount const,
542 ReadView const&,
543 beast::Journal const&);
544};
545
547{
550
553
554public:
555 void
557 bool,
560
561 bool
562 finalize(
563 STTx const&,
564 TER const,
565 XRPAmount const,
566 ReadView const&,
567 beast::Journal const&);
568};
569
581{
583 {
585 bool isSorted_ = false, isUnique_ = false;
586 };
588
589public:
590 void
592 bool,
595
596 bool
597 finalize(
598 STTx const&,
599 TER const,
600 XRPAmount const,
601 ReadView const&,
602 beast::Journal const&);
603};
604
614{
616
617public:
618 void
620 bool,
623
624 bool
625 finalize(
626 STTx const&,
627 TER const,
628 XRPAmount const,
629 ReadView const&,
630 beast::Journal const&);
631};
632
634{
635 bool regularOffers_ = false;
636 bool badHybrids_ = false;
638
639public:
640 void
642 bool,
645
646 bool
647 finalize(
648 STTx const&,
649 TER const,
650 XRPAmount const,
651 ReadView const&,
652 beast::Journal const&);
653};
654
656{
661
662public:
663 enum class ZeroAllowed : bool { No = false, Yes = true };
664
666 {
667 }
668 void
670 bool,
673
674 bool
675 finalize(
676 STTx const&,
677 TER const,
678 XRPAmount const,
679 ReadView const&,
680 beast::Journal const&);
681
682private:
683 bool
684 finalizeBid(bool enforce, beast::Journal const&) const;
685 bool
686 finalizeVote(bool enforce, beast::Journal const&) const;
687 bool
689 STTx const&,
690 ReadView const&,
691 bool enforce,
692 beast::Journal const&) const;
693 bool
694 finalizeDelete(bool enforce, TER res, beast::Journal const&) const;
695 bool
697 STTx const&,
698 ReadView const&,
699 bool enforce,
700 beast::Journal const&) const;
701 // Includes clawback
702 bool
704 STTx const&,
705 ReadView const&,
706 bool enforce,
707 beast::Journal const&) const;
708 bool
709 finalizeDEX(bool enforce, beast::Journal const&) const;
710 bool
712 STTx const&,
713 ReadView const&,
714 ZeroAllowed zeroAllowed,
715 beast::Journal const&) const;
716};
717
738{
739 Number static constexpr zero{};
740
741 struct Vault final
742 {
743 uint256 key = beast::zero;
746 uint192 shareMPTID = beast::zero;
751
752 Vault static make(SLE const&);
753 };
754
755 struct Shares final
756 {
760
761 Shares static make(SLE const&);
762 };
763
769
770public:
771 void
773 bool,
776
777 bool
778 finalize(
779 STTx const&,
780 TER const,
781 XRPAmount const,
782 ReadView const&,
783 beast::Journal const&);
784};
785
786// additional invariant checks can be declared above and then added to this
787// tuple
807 ValidAMM,
809 ValidVault>;
810
819inline InvariantChecks
821{
822 return InvariantChecks{};
823}
824
825} // namespace ripple
826
827#endif
A generic endpoint for log messages.
Definition Journal.h:41
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:14
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:32
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:6
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:3247
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 &)