rippled
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 <ripple/basics/base_uint.h>
24 #include <ripple/beast/utility/Journal.h>
25 #include <ripple/protocol/STLedgerEntry.h>
26 #include <ripple/protocol/STTx.h>
27 #include <ripple/protocol/TER.h>
28 #include <cstdint>
29 #include <map>
30 #include <tuple>
31 #include <utility>
32 
33 namespace ripple {
34 
35 class ReadView;
36 
37 #if GENERATING_DOCS
38 
47 {
48 public:
49  explicit InvariantChecker_PROTOTYPE() = default;
50 
58  void
59  visitEntry(
60  bool isDelete,
61  std::shared_ptr<SLE const> const& before,
63 
76  bool
77  finalize(
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 {
94 public:
95  void
96  visitEntry(
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 
122 public:
123  void
124  visitEntry(
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 
150 public:
151  void
152  visitEntry(
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 
174 {
175  bool bad_ = false;
176 
177 public:
178  void
179  visitEntry(
180  bool,
183 
184  bool
185  finalize(
186  STTx const&,
187  TER const,
188  XRPAmount const,
189  ReadView const&,
190  beast::Journal const&);
191 };
192 
198 {
199  bool typeMismatch_ = false;
200  bool invalidTypeAdded_ = false;
201 
202 public:
203  void
204  visitEntry(
205  bool,
208 
209  bool
210  finalize(
211  STTx const&,
212  TER const,
213  XRPAmount const,
214  ReadView const&,
215  beast::Journal const&);
216 };
217 
225 {
226  bool xrpTrustLine_ = false;
227 
228 public:
229  void
230  visitEntry(
231  bool,
234 
235  bool
236  finalize(
237  STTx const&,
238  TER const,
239  XRPAmount const,
240  ReadView const&,
241  beast::Journal const&);
242 };
243 
252 {
253  bool bad_ = false;
254 
255 public:
256  void
257  visitEntry(
258  bool,
261 
262  bool
263  finalize(
264  STTx const&,
265  TER const,
266  XRPAmount const,
267  ReadView const&,
268  beast::Journal const&);
269 };
270 
276 {
277  bool bad_ = false;
278 
279 public:
280  void
281  visitEntry(
282  bool,
285 
286  bool
287  finalize(
288  STTx const&,
289  TER const,
290  XRPAmount const,
291  ReadView const&,
292  beast::Journal const&);
293 };
294 
301 {
303  std::uint32_t accountSeq_ = 0; // Only meaningful if accountsCreated_ > 0
304 
305 public:
306  void
307  visitEntry(
308  bool,
311 
312  bool
313  finalize(
314  STTx const&,
315  TER const,
316  XRPAmount const,
317  ReadView const&,
318  beast::Journal const&);
319 };
320 
321 // additional invariant checks can be declared above and then added to this
322 // tuple
330  NoBadOffers,
331  NoZeroEscrow,
333 
342 inline InvariantChecks
344 {
345  return InvariantChecks{};
346 }
347 
348 } // namespace ripple
349 
350 #endif
ripple::LedgerEntryTypesMatch::visitEntry
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Definition: InvariantCheck.cpp:343
ripple::NoZeroEscrow::visitEntry
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Definition: InvariantCheck.cpp:257
std::shared_ptr
STL class.
utility
ripple::TransactionFeeCheck::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition: InvariantCheck.cpp:39
ripple::XRPBalanceChecks::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition: InvariantCheck.cpp:194
ripple::NoXRPTrustLines::visitEntry
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Definition: InvariantCheck.cpp:404
ripple::NoBadOffers::visitEntry
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Definition: InvariantCheck.cpp:213
ripple::NoZeroEscrow::bad_
bool bad_
Definition: InvariantCheck.h:277
ripple::NoBadOffers::bad_
bool bad_
Definition: InvariantCheck.h:253
tuple
ripple::NoBadOffers
Invariant: offers should be for non-negative amounts and must not be XRP to XRP.
Definition: InvariantCheck.h:251
ripple::InvariantChecker_PROTOTYPE::finalize
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
ripple::InvariantChecker_PROTOTYPE::InvariantChecker_PROTOTYPE
InvariantChecker_PROTOTYPE()=default
ripple::ValidNewAccountRoot::accountSeq_
std::uint32_t accountSeq_
Definition: InvariantCheck.h:303
ripple::XRPBalanceChecks
Invariant: An account XRP balance must be in XRP and take a value between 0 and INITIAL_XRP drops,...
Definition: InvariantCheck.h:173
ripple::ValidNewAccountRoot::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition: InvariantCheck.cpp:451
ripple::NoXRPTrustLines::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition: InvariantCheck.cpp:421
ripple::LedgerEntryTypesMatch::typeMismatch_
bool typeMismatch_
Definition: InvariantCheck.h:199
ripple::NoBadOffers::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition: InvariantCheck.cpp:238
ripple::TransactionFeeCheck
Invariant: We should never charge a transaction a negative fee or a fee that is larger than what the ...
Definition: InvariantCheck.h:92
ripple::LedgerEntryTypesMatch::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition: InvariantCheck.cpp:378
ripple::TERSubset< CanCvtToTER >
ripple::ValidNewAccountRoot::visitEntry
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Definition: InvariantCheck.cpp:438
ripple::AccountRootsNotDeleted
Invariant: we cannot remove an account ledger entry.
Definition: InvariantCheck.h:146
ripple::XRPNotCreated
Invariant: A transaction must not create XRP and should only destroy the XRP fee.
Definition: InvariantCheck.h:118
ripple::XRPNotCreated::visitEntry
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Definition: InvariantCheck.cpp:78
ripple::XRPNotCreated::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition: InvariantCheck.cpp:133
cstdint
ripple::STTx
Definition: STTx.h:42
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::int64_t
ripple::ValidNewAccountRoot
Invariant: a new account root must be the consequence of a payment, must have the right starting sequ...
Definition: InvariantCheck.h:300
map
ripple::NoZeroEscrow::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition: InvariantCheck.cpp:283
ripple::AccountRootsNotDeleted::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition: InvariantCheck.cpp:312
ripple::LedgerEntryTypesMatch
Invariant: corresponding modified ledger entries should match in type and added entries should be a v...
Definition: InvariantCheck.h:197
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:192
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::InvariantChecker_PROTOTYPE
Prototype for invariant check implementations.
Definition: InvariantCheck.h:46
ripple::NoXRPTrustLines::xrpTrustLine_
bool xrpTrustLine_
Definition: InvariantCheck.h:226
ripple::ValidNewAccountRoot::accountsCreated_
std::uint32_t accountsCreated_
Definition: InvariantCheck.h:302
ripple::TransactionFeeCheck::visitEntry
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Definition: InvariantCheck.cpp:30
ripple::AccountRootsNotDeleted::visitEntry
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Definition: InvariantCheck.cpp:302
ripple::after
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:88
ripple::AccountRootsNotDeleted::accountsDeleted_
std::uint32_t accountsDeleted_
Definition: InvariantCheck.h:148
ripple::XRPBalanceChecks::visitEntry
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
Definition: InvariantCheck.cpp:163
ripple::NoXRPTrustLines
Invariant: Trust lines using XRP are not allowed.
Definition: InvariantCheck.h:224
ripple::XRPBalanceChecks::bad_
bool bad_
Definition: InvariantCheck.h:175
ripple::getInvariantChecks
InvariantChecks getInvariantChecks()
get a tuple of all invariant checks
Definition: InvariantCheck.h:343
ripple::LedgerEntryTypesMatch::invalidTypeAdded_
bool invalidTypeAdded_
Definition: InvariantCheck.h:200
ripple::XRPNotCreated::drops_
std::int64_t drops_
Definition: InvariantCheck.h:120
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::InvariantChecker_PROTOTYPE::visitEntry
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.
ripple::NoZeroEscrow
Invariant: an escrow entry must take a value between 0 and INITIAL_XRP drops exclusive.
Definition: InvariantCheck.h:275