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:231
ripple::terNO_LINE
@ terNO_LINE
Definition: TER.h:200
ripple::lsfLowNoRipple
@ lsfLowNoRipple
Definition: LedgerFormats.h:256
ripple::terNO_RIPPLE
@ terNO_RIPPLE
Definition: TER.h:205
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
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:133
ripple::TER
TERSubset< CanCvtToTER > TER
Definition: TER.h:568
beast::Journal::info
Stream info() const
Definition: Journal.h:321
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::keylet::line
Keylet line(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition: Indexes.cpp:193
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:257
ripple::lsfHighFreeze
@ lsfHighFreeze
Definition: LedgerFormats.h:259
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::sfFlags
const SF_UINT32 sfFlags
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:258
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:222