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{
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
307{
309 {
312 };
313
315 {
318 };
319
322
324
325public:
326 void
328 bool,
331
332 bool
333 finalize(
334 STTx const&,
335 TER const,
336 XRPAmount const,
337 ReadView const&,
338 beast::Journal const&);
339
340private:
341 bool
343 std::shared_ptr<SLE const> const& before,
345
348 std::shared_ptr<SLE const> const& before,
350 bool isDelete);
351
352 void
353 recordBalance(Issue const& issue, BalanceChange change);
354
355 void
358 STAmount const& balanceChange);
359
361 findIssuer(AccountID const& issuerID, ReadView const& view);
362
363 bool
365 std::shared_ptr<SLE const> const& issuer,
366 IssuerChanges const& changes,
367 STTx const& tx,
368 beast::Journal const& j,
369 bool enforce);
370
371 bool
373 BalanceChange const& change,
374 bool high,
375 STTx const& tx,
376 beast::Journal const& j,
377 bool enforce,
378 bool globalFreeze);
379};
380
389{
390 bool bad_ = false;
391
392public:
393 void
395 bool,
398
399 bool
400 finalize(
401 STTx const&,
402 TER const,
403 XRPAmount const,
404 ReadView const&,
405 beast::Journal const&);
406};
407
413{
414 bool bad_ = false;
415
416public:
417 void
419 bool,
422
423 bool
424 finalize(
425 STTx const&,
426 TER const,
427 XRPAmount const,
428 ReadView const&,
429 beast::Journal const&);
430};
431
438{
441 bool pseudoAccount_ = false;
443
444public:
445 void
447 bool,
450
451 bool
452 finalize(
453 STTx const&,
454 TER const,
455 XRPAmount const,
456 ReadView const&,
457 beast::Journal const&);
458};
459
472{
473 bool badEntry_ = false;
474 bool badLink_ = false;
475 bool badSort_ = false;
476 bool badURI_ = false;
477 bool invalidSize_ = false;
478 bool deletedFinalPage_ = false;
479 bool deletedLink_ = false;
480
481public:
482 void
484 bool,
487
488 bool
489 finalize(
490 STTx const&,
491 TER const,
492 XRPAmount const,
493 ReadView const&,
494 beast::Journal const&);
495};
496
511{
516
517public:
518 void
520 bool,
523
524 bool
525 finalize(
526 STTx const&,
527 TER const,
528 XRPAmount const,
529 ReadView const&,
530 beast::Journal const&);
531};
532
542{
545
546public:
547 void
549 bool,
552
553 bool
554 finalize(
555 STTx const&,
556 TER const,
557 XRPAmount const,
558 ReadView const&,
559 beast::Journal const&);
560};
561
563{
566
569
570public:
571 void
573 bool,
576
577 bool
578 finalize(
579 STTx const&,
580 TER const,
581 XRPAmount const,
582 ReadView const&,
583 beast::Journal const&);
584};
585
597{
599 {
601 bool isSorted_ = false, isUnique_ = false;
602 };
604
605public:
606 void
608 bool,
611
612 bool
613 finalize(
614 STTx const&,
615 TER const,
616 XRPAmount const,
617 ReadView const&,
618 beast::Journal const&);
619};
620
621// additional invariant checks can be declared above and then added to this
622// tuple
641
650inline InvariantChecks
652{
653 return InvariantChecks{};
654}
655
656} // namespace ripple
657
658#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:36
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:52
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 &)
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 &)
Set the fee on a JTx.
Definition: fee.h:37
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: View.cpp:2696
InvariantChecks getInvariantChecks()
get a tuple of all invariant checks
std::shared_ptr< SLE const > const line
std::vector< BalanceChange > receivers
std::vector< BalanceChange > senders