rippled
LoadFeeTrack.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 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_CORE_LOADFEETRACK_H_INCLUDED
21 #define RIPPLE_CORE_LOADFEETRACK_H_INCLUDED
22 
23 #include <ripple/basics/FeeUnits.h>
24 #include <ripple/beast/utility/Journal.h>
25 #include <ripple/json/json_value.h>
26 #include <algorithm>
27 #include <cstdint>
28 #include <mutex>
29 
30 namespace ripple {
31 
32 struct Fees;
33 
43 class LoadFeeTrack final
44 {
45 public:
46  explicit LoadFeeTrack(
48  : j_(journal)
52  , raiseCount_(0)
53  {
54  }
55 
56  ~LoadFeeTrack() = default;
57 
58  void
60  {
63  }
64 
66  getRemoteFee() const
67  {
69  return remoteTxnLoadFee_;
70  }
71 
73  getLocalFee() const
74  {
76  return localTxnLoadFee_;
77  }
78 
80  getClusterFee() const
81  {
83  return clusterTxnLoadFee_;
84  }
85 
87  getLoadBase() const
88  {
89  return lftNormalFee;
90  }
91 
93  getLoadFactor() const
94  {
96  return std::max(
98  }
99 
102  {
104 
105  return std::make_pair(
108  }
109 
110  void
112  {
114  clusterTxnLoadFee_ = fee;
115  }
116 
117  bool
118  raiseLocalFee();
119  bool
120  lowerLocalFee();
121 
122  bool
124  {
126  return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee);
127  }
128 
129  bool
131  {
133  return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee) ||
135  }
136 
137 private:
138  static std::uint32_t constexpr lftNormalFee =
139  256; // 256 is the minimum/normal load factor
140  static std::uint32_t constexpr lftFeeIncFraction =
141  4; // increase fee by 1/4
142  static std::uint32_t constexpr lftFeeDecFraction =
143  4; // decrease fee by 1/4
144  static std::uint32_t constexpr lftFeeMax = lftNormalFee * 1000000;
145 
147  std::mutex mutable lock_;
148 
149  std::uint32_t localTxnLoadFee_; // Scale factor, lftNormalFee = normal fee
150  std::uint32_t remoteTxnLoadFee_; // Scale factor, lftNormalFee = normal fee
152  clusterTxnLoadFee_; // Scale factor, lftNormalFee = normal fee
154 };
155 
156 //------------------------------------------------------------------------------
157 
158 // Scale using load as well as base rate
159 XRPAmount
161  FeeUnit64 fee,
162  LoadFeeTrack const& feeTrack,
163  Fees const& fees,
164  bool bUnlimited);
165 
166 } // namespace ripple
167 
168 #endif
ripple::LoadFeeTrack::lftFeeMax
static constexpr std::uint32_t lftFeeMax
Definition: LoadFeeTrack.h:144
std::pair
ripple::LoadFeeTrack::lftFeeDecFraction
static constexpr std::uint32_t lftFeeDecFraction
Definition: LoadFeeTrack.h:142
ripple::scaleFeeLoad
XRPAmount scaleFeeLoad(FeeUnit64 fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
Definition: LoadFeeTrack.cpp:89
ripple::LoadFeeTrack::~LoadFeeTrack
~LoadFeeTrack()=default
std::lock_guard
STL class.
ripple::LoadFeeTrack::getLoadBase
std::uint32_t getLoadBase() const
Definition: LoadFeeTrack.h:87
beast::Journal::getNullSink
static Sink & getNullSink()
Returns a Sink which does nothing.
Definition: beast_Journal.cpp:72
algorithm
ripple::LoadFeeTrack::LoadFeeTrack
LoadFeeTrack(beast::Journal journal=beast::Journal(beast::Journal::getNullSink()))
Definition: LoadFeeTrack.h:46
ripple::LoadFeeTrack::getRemoteFee
std::uint32_t getRemoteFee() const
Definition: LoadFeeTrack.h:66
ripple::LoadFeeTrack::clusterTxnLoadFee_
std::uint32_t clusterTxnLoadFee_
Definition: LoadFeeTrack.h:152
ripple::LoadFeeTrack::isLoadedLocal
bool isLoadedLocal() const
Definition: LoadFeeTrack.h:123
ripple::Fees
Reflects the fee settings for a particular ledger.
Definition: ReadView.h:48
ripple::LoadFeeTrack::lock_
std::mutex lock_
Definition: LoadFeeTrack.h:147
ripple::LoadFeeTrack::getLocalFee
std::uint32_t getLocalFee() const
Definition: LoadFeeTrack.h:73
ripple::LoadFeeTrack::getScalingFactors
std::pair< std::uint32_t, std::uint32_t > getScalingFactors() const
Definition: LoadFeeTrack.h:101
ripple::LoadFeeTrack::lftFeeIncFraction
static constexpr std::uint32_t lftFeeIncFraction
Definition: LoadFeeTrack.h:140
ripple::LoadFeeTrack
Manages the current fee schedule.
Definition: LoadFeeTrack.h:43
cstdint
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::feeunit::TaggedFee
Definition: FeeUnits.h:70
ripple::LoadFeeTrack::getClusterFee
std::uint32_t getClusterFee() const
Definition: LoadFeeTrack.h:80
ripple::LoadFeeTrack::j_
const beast::Journal j_
Definition: LoadFeeTrack.h:146
ripple::LoadFeeTrack::remoteTxnLoadFee_
std::uint32_t remoteTxnLoadFee_
Definition: LoadFeeTrack.h:150
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LoadFeeTrack::getLoadFactor
std::uint32_t getLoadFactor() const
Definition: LoadFeeTrack.h:93
ripple::LoadFeeTrack::raiseLocalFee
bool raiseLocalFee()
Definition: LoadFeeTrack.cpp:37
ripple::LoadFeeTrack::isLoadedCluster
bool isLoadedCluster() const
Definition: LoadFeeTrack.h:130
ripple::LoadFeeTrack::setClusterFee
void setClusterFee(std::uint32_t fee)
Definition: LoadFeeTrack.h:111
mutex
std::make_pair
T make_pair(T... args)
ripple::LoadFeeTrack::raiseCount_
std::uint32_t raiseCount_
Definition: LoadFeeTrack.h:153
std::max
T max(T... args)
ripple::LoadFeeTrack::setRemoteFee
void setRemoteFee(std::uint32_t f)
Definition: LoadFeeTrack.h:59
ripple::LoadFeeTrack::lowerLocalFee
bool lowerLocalFee()
Definition: LoadFeeTrack.cpp:65
ripple::LoadFeeTrack::lftNormalFee
static constexpr std::uint32_t lftNormalFee
Definition: LoadFeeTrack.h:138
ripple::LoadFeeTrack::localTxnLoadFee_
std::uint32_t localTxnLoadFee_
Definition: LoadFeeTrack.h:149
ripple::XRPAmount
Definition: XRPAmount.h:46