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/protocol/XRPAmount.h>
26
27#include <algorithm>
28#include <cstdint>
29#include <mutex>
30
31namespace ripple {
32
33struct Fees;
34
44class LoadFeeTrack final
45{
46public:
47 explicit LoadFeeTrack(
49 : j_(journal)
53 , raiseCount_(0)
54 {
55 }
56
57 ~LoadFeeTrack() = default;
58
59 void
61 {
62 JLOG(j_.trace()) << "setRemoteFee: " << f;
65 }
66
69 {
71 return remoteTxnLoadFee_;
72 }
73
76 {
78 return localTxnLoadFee_;
79 }
80
83 {
85 return clusterTxnLoadFee_;
86 }
87
90 {
91 return lftNormalFee;
92 }
93
96 {
98 return std::max(
100 }
101
104 {
106
107 return std::make_pair(
110 }
111
112 void
114 {
115 JLOG(j_.trace()) << "setClusterFee: " << fee;
117 clusterTxnLoadFee_ = fee;
118 }
119
120 bool
122 bool
124
125 bool
127 {
129 return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee);
130 }
131
132 bool
134 {
136 return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee) ||
138 }
139
140private:
141 static std::uint32_t constexpr lftNormalFee =
142 256; // 256 is the minimum/normal load factor
144 4; // increase fee by 1/4
146 4; // decrease fee by 1/4
147 static std::uint32_t constexpr lftFeeMax = lftNormalFee * 1000000;
148
151
152 std::uint32_t localTxnLoadFee_; // Scale factor, lftNormalFee = normal fee
153 std::uint32_t remoteTxnLoadFee_; // Scale factor, lftNormalFee = normal fee
155 clusterTxnLoadFee_; // Scale factor, lftNormalFee = normal fee
157};
158
159//------------------------------------------------------------------------------
160
161// Scale using load as well as base rate
164 XRPAmount fee,
165 LoadFeeTrack const& feeTrack,
166 Fees const& fees,
167 bool bUnlimited);
168
169} // namespace ripple
170
171#endif
A generic endpoint for log messages.
Definition: Journal.h:60
static Sink & getNullSink()
Returns a Sink which does nothing.
Stream trace() const
Severity stream access functions.
Definition: Journal.h:322
Manages the current fee schedule.
Definition: LoadFeeTrack.h:45
std::uint32_t getClusterFee() const
Definition: LoadFeeTrack.h:82
static std::uint32_t constexpr lftFeeIncFraction
Definition: LoadFeeTrack.h:143
bool isLoadedCluster() const
Definition: LoadFeeTrack.h:133
beast::Journal const j_
Definition: LoadFeeTrack.h:149
static std::uint32_t constexpr lftNormalFee
Definition: LoadFeeTrack.h:141
std::uint32_t raiseCount_
Definition: LoadFeeTrack.h:156
void setRemoteFee(std::uint32_t f)
Definition: LoadFeeTrack.h:60
bool isLoadedLocal() const
Definition: LoadFeeTrack.h:126
std::uint32_t localTxnLoadFee_
Definition: LoadFeeTrack.h:152
std::uint32_t remoteTxnLoadFee_
Definition: LoadFeeTrack.h:153
std::uint32_t getLocalFee() const
Definition: LoadFeeTrack.h:75
std::uint32_t getLoadBase() const
Definition: LoadFeeTrack.h:89
LoadFeeTrack(beast::Journal journal=beast::Journal(beast::Journal::getNullSink()))
Definition: LoadFeeTrack.h:47
std::pair< std::uint32_t, std::uint32_t > getScalingFactors() const
Definition: LoadFeeTrack.h:103
std::uint32_t getRemoteFee() const
Definition: LoadFeeTrack.h:68
static std::uint32_t constexpr lftFeeDecFraction
Definition: LoadFeeTrack.h:145
std::uint32_t getLoadFactor() const
Definition: LoadFeeTrack.h:95
void setClusterFee(std::uint32_t fee)
Definition: LoadFeeTrack.h:113
std::uint32_t clusterTxnLoadFee_
Definition: LoadFeeTrack.h:155
static std::uint32_t constexpr lftFeeMax
Definition: LoadFeeTrack.h:147
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