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
442public:
443 void
445 bool,
448
449 bool
450 finalize(
451 STTx const&,
452 TER const,
453 XRPAmount const,
454 ReadView const&,
455 beast::Journal const&);
456};
457
470{
471 bool badEntry_ = false;
472 bool badLink_ = false;
473 bool badSort_ = false;
474 bool badURI_ = false;
475 bool invalidSize_ = false;
476 bool deletedFinalPage_ = false;
477 bool deletedLink_ = false;
478
479public:
480 void
482 bool,
485
486 bool
487 finalize(
488 STTx const&,
489 TER const,
490 XRPAmount const,
491 ReadView const&,
492 beast::Journal const&);
493};
494
509{
514
515public:
516 void
518 bool,
521
522 bool
523 finalize(
524 STTx const&,
525 TER const,
526 XRPAmount const,
527 ReadView const&,
528 beast::Journal const&);
529};
530
540{
543
544public:
545 void
547 bool,
550
551 bool
552 finalize(
553 STTx const&,
554 TER const,
555 XRPAmount const,
556 ReadView const&,
557 beast::Journal const&);
558};
559
561{
564
567
568public:
569 void
571 bool,
574
575 bool
576 finalize(
577 STTx const&,
578 TER const,
579 XRPAmount const,
580 ReadView const&,
581 beast::Journal const&);
582};
583
595{
597 {
599 bool isSorted_ = false, isUnique_ = false;
600 };
602
603public:
604 void
606 bool,
609
610 bool
611 finalize(
612 STTx const&,
613 TER const,
614 XRPAmount const,
615 ReadView const&,
616 beast::Journal const&);
617};
618
619// additional invariant checks can be declared above and then added to this
620// tuple
639
648inline InvariantChecks
650{
651 return InvariantChecks{};
652}
653
654} // namespace ripple
655
656#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
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: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: 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 &)
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
std::shared_ptr< SLE const > const line
std::vector< BalanceChange > receivers
std::vector< BalanceChange > senders