rippled
StepChecks.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2015 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_PATHS_IMPL_STEP_CHECKS_H_INCLUDED
21 #define RIPPLE_APP_PATHS_IMPL_STEP_CHECKS_H_INCLUDED
22 
23 #include <ripple/basics/Log.h>
24 #include <ripple/beast/utility/Journal.h>
25 #include <ripple/ledger/ReadView.h>
26 #include <ripple/protocol/AccountID.h>
27 #include <ripple/protocol/UintTypes.h>
28 
29 namespace ripple {
30 
31 inline TER
33  ReadView const& view,
34  AccountID const& src,
35  AccountID const& dst,
36  Currency const& currency)
37 {
38  assert(src != dst);
39 
40  // check freeze
41  if (auto sle = view.read(keylet::account(dst)))
42  {
43  if (sle->isFlag(lsfGlobalFreeze))
44  {
45  return terNO_LINE;
46  }
47  }
48 
49  if (auto sle = view.read(keylet::line(src, dst, currency)))
50  {
51  if (sle->isFlag((dst > src) ? lsfHighFreeze : lsfLowFreeze))
52  {
53  return terNO_LINE;
54  }
55  }
56 
57  return tesSUCCESS;
58 }
59 
60 inline TER
62  ReadView const& view,
63  AccountID const& prev,
64  AccountID const& cur,
65  // This is the account whose constraints we are checking
66  AccountID const& next,
67  Currency const& currency,
69 {
70  // fetch the ripple lines into and out of this node
71  auto sleIn = view.read(keylet::line(prev, cur, currency));
72  auto sleOut = view.read(keylet::line(cur, next, currency));
73 
74  if (!sleIn || !sleOut)
75  return terNO_LINE;
76 
77  if ((*sleIn)[sfFlags] & ((cur > prev) ? lsfHighNoRipple : lsfLowNoRipple) &&
78  (*sleOut)[sfFlags] & ((cur > next) ? lsfHighNoRipple : lsfLowNoRipple))
79  {
80  JLOG(j.info()) << "Path violates noRipple constraint between " << prev
81  << ", " << cur << " and " << next;
82 
83  return terNO_RIPPLE;
84  }
85  return tesSUCCESS;
86 }
87 
88 } // namespace ripple
89 
90 #endif
ripple::lsfGlobalFreeze
@ lsfGlobalFreeze
Definition: LedgerFormats.h:137
ripple::terNO_LINE
@ terNO_LINE
Definition: TER.h:192
ripple::lsfLowNoRipple
@ lsfLowNoRipple
Definition: LedgerFormats.h:151
ripple::sfFlags
const SF_U32 sfFlags(access, STI_UINT32, 2, "Flags")
Definition: SField.h:353
ripple::terNO_RIPPLE
@ terNO_RIPPLE
Definition: TER.h:197
ripple::checkNoRipple
TER checkNoRipple(ReadView const &view, AccountID const &prev, AccountID const &cur, AccountID const &next, Currency const &currency, beast::Journal j)
Definition: StepChecks.h:61
ripple::base_uint
Definition: base_uint.h:63
ripple::keylet::line
static const line_t line
Definition: Indexes.h:190
ripple::keylet::account
static const account_t account
Definition: Indexes.h:120
ripple::TER
TERSubset< CanCvtToTER > TER
Definition: TER.h:547
beast::Journal::info
Stream info() const
Definition: Journal.h:321
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::ReadView::read
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
ripple::lsfHighNoRipple
@ lsfHighNoRipple
Definition: LedgerFormats.h:152
ripple::lsfHighFreeze
@ lsfHighFreeze
Definition: LedgerFormats.h:154
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:188
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::checkFreeze
TER checkFreeze(ReadView const &view, AccountID const &src, AccountID const &dst, Currency const &currency)
Definition: StepChecks.h:32
ripple::lsfLowFreeze
@ lsfLowFreeze
Definition: LedgerFormats.h:153
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:213