rippled
Loading...
Searching...
No Matches
LoadFeeTrack.h
1#pragma once
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/protocol/XRPAmount.h>
6
7#include <algorithm>
8#include <cstdint>
9#include <mutex>
10
11namespace xrpl {
12
13struct Fees;
14
24class LoadFeeTrack final
25{
26public:
28 : j_(journal)
29 {
30 }
31
32 ~LoadFeeTrack() = default;
33
34 void
36 {
37 JLOG(j_.trace()) << "setRemoteFee: " << f;
38 std::lock_guard const sl(lock_);
40 }
41
44 {
45 std::lock_guard const sl(lock_);
46 return remoteTxnLoadFee_;
47 }
48
51 {
52 std::lock_guard const sl(lock_);
53 return localTxnLoadFee_;
54 }
55
58 {
59 std::lock_guard const sl(lock_);
60 return clusterTxnLoadFee_;
61 }
62
65 {
66 return lftNormalFee;
67 }
68
75
85
86 void
88 {
89 JLOG(j_.trace()) << "setClusterFee: " << fee;
90 std::lock_guard const sl(lock_);
92 }
93
94 bool
96 bool
98
99 bool
101 {
102 std::lock_guard const sl(lock_);
103 return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee);
104 }
105
106 bool
108 {
109 std::lock_guard const sl(lock_);
110 return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee) ||
112 }
113
114private:
115 static std::uint32_t constexpr lftNormalFee = 256; // 256 is the minimum/normal load factor
116 static std::uint32_t constexpr lftFeeIncFraction = 4; // increase fee by 1/4
117 static std::uint32_t constexpr lftFeeDecFraction = 4; // decrease fee by 1/4
118 static std::uint32_t constexpr lftFeeMax = lftNormalFee * 1000000;
119
122
123 std::uint32_t localTxnLoadFee_{lftNormalFee}; // Scale factor, lftNormalFee = normal fee
124 std::uint32_t remoteTxnLoadFee_{lftNormalFee}; // Scale factor, lftNormalFee = normal fee
125 std::uint32_t clusterTxnLoadFee_{lftNormalFee}; // Scale factor, lftNormalFee = normal fee
127};
128
129//------------------------------------------------------------------------------
130
131// Scale using load as well as base rate
132XRPAmount
133scaleFeeLoad(XRPAmount fee, LoadFeeTrack const& feeTrack, Fees const& fees, bool bUnlimited);
134
135} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
static Sink & getNullSink()
Returns a Sink which does nothing.
Stream trace() const
Severity stream access functions.
Definition Journal.h:295
Manages the current fee schedule.
static std::uint32_t constexpr lftFeeDecFraction
~LoadFeeTrack()=default
static std::uint32_t constexpr lftFeeIncFraction
std::uint32_t clusterTxnLoadFee_
void setRemoteFee(std::uint32_t f)
std::uint32_t getClusterFee() const
std::uint32_t getLocalFee() const
std::uint32_t remoteTxnLoadFee_
static std::uint32_t constexpr lftNormalFee
std::uint32_t getRemoteFee() const
std::uint32_t getLoadFactor() const
void setClusterFee(std::uint32_t fee)
bool isLoadedLocal() const
std::uint32_t getLoadBase() const
std::uint32_t localTxnLoadFee_
std::uint32_t raiseCount_
beast::Journal const j_
bool isLoadedCluster() const
std::pair< std::uint32_t, std::uint32_t > getScalingFactors() const
LoadFeeTrack(beast::Journal journal=beast::Journal(beast::Journal::getNullSink()))
static std::uint32_t constexpr lftFeeMax
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:5
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)