rippled
Loading...
Searching...
No Matches
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 <xrpl/basics/Log.h>
24#include <xrpl/beast/utility/Journal.h>
25#include <xrpl/json/json_value.h>
26#include <xrpl/protocol/FeeUnits.h>
27#include <xrpl/protocol/XRPAmount.h>
28#include <algorithm>
29#include <cstdint>
30#include <mutex>
31
32namespace ripple {
33
34struct Fees;
35
45class LoadFeeTrack final
46{
47public:
48 explicit LoadFeeTrack(
50 : j_(journal)
54 , raiseCount_(0)
55 {
56 }
57
58 ~LoadFeeTrack() = default;
59
60 void
62 {
63 JLOG(j_.trace()) << "setRemoteFee: " << f;
66 }
67
70 {
72 return remoteTxnLoadFee_;
73 }
74
77 {
79 return localTxnLoadFee_;
80 }
81
84 {
86 return clusterTxnLoadFee_;
87 }
88
91 {
92 return lftNormalFee;
93 }
94
97 {
99 return std::max(
101 }
102
105 {
107
108 return std::make_pair(
111 }
112
113 void
115 {
116 JLOG(j_.trace()) << "setClusterFee: " << fee;
118 clusterTxnLoadFee_ = fee;
119 }
120
121 bool
123 bool
125
126 bool
128 {
130 return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee);
131 }
132
133 bool
135 {
137 return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee) ||
139 }
140
141private:
142 static std::uint32_t constexpr lftNormalFee =
143 256; // 256 is the minimum/normal load factor
145 4; // increase fee by 1/4
147 4; // decrease fee by 1/4
148 static std::uint32_t constexpr lftFeeMax = lftNormalFee * 1000000;
149
152
153 std::uint32_t localTxnLoadFee_; // Scale factor, lftNormalFee = normal fee
154 std::uint32_t remoteTxnLoadFee_; // Scale factor, lftNormalFee = normal fee
156 clusterTxnLoadFee_; // Scale factor, lftNormalFee = normal fee
158};
159
160//------------------------------------------------------------------------------
161
162// Scale using load as well as base rate
165 XRPAmount fee,
166 LoadFeeTrack const& feeTrack,
167 Fees const& fees,
168 bool bUnlimited);
169
170} // namespace ripple
171
172#endif
A generic endpoint for log messages.
Definition: Journal.h:59
static Sink & getNullSink()
Returns a Sink which does nothing.
Stream trace() const
Severity stream access functions.
Definition: Journal.h:311
Manages the current fee schedule.
Definition: LoadFeeTrack.h:46
std::uint32_t getClusterFee() const
Definition: LoadFeeTrack.h:83
static std::uint32_t constexpr lftFeeIncFraction
Definition: LoadFeeTrack.h:144
bool isLoadedCluster() const
Definition: LoadFeeTrack.h:134
beast::Journal const j_
Definition: LoadFeeTrack.h:150
static std::uint32_t constexpr lftNormalFee
Definition: LoadFeeTrack.h:142
std::uint32_t raiseCount_
Definition: LoadFeeTrack.h:157
void setRemoteFee(std::uint32_t f)
Definition: LoadFeeTrack.h:61
bool isLoadedLocal() const
Definition: LoadFeeTrack.h:127
std::uint32_t localTxnLoadFee_
Definition: LoadFeeTrack.h:153
std::uint32_t remoteTxnLoadFee_
Definition: LoadFeeTrack.h:154
std::uint32_t getLocalFee() const
Definition: LoadFeeTrack.h:76
std::uint32_t getLoadBase() const
Definition: LoadFeeTrack.h:90
LoadFeeTrack(beast::Journal journal=beast::Journal(beast::Journal::getNullSink()))
Definition: LoadFeeTrack.h:48
std::pair< std::uint32_t, std::uint32_t > getScalingFactors() const
Definition: LoadFeeTrack.h:104
std::uint32_t getRemoteFee() const
Definition: LoadFeeTrack.h:69
static std::uint32_t constexpr lftFeeDecFraction
Definition: LoadFeeTrack.h:146
std::uint32_t getLoadFactor() const
Definition: LoadFeeTrack.h:96
void setClusterFee(std::uint32_t fee)
Definition: LoadFeeTrack.h:114
std::uint32_t clusterTxnLoadFee_
Definition: LoadFeeTrack.h:156
static std::uint32_t constexpr lftFeeMax
Definition: LoadFeeTrack.h:148
T make_pair(T... args)
T max(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
Reflects the fee settings for a particular ledger.
Definition: protocol/Fees.h:33