xrpld
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::scoped_lock const sl(lock_);
40 }
41
44 {
45 std::scoped_lock const sl(lock_);
46 return remoteTxnLoadFee_;
47 }
48
51 {
52 std::scoped_lock const sl(lock_);
53 return localTxnLoadFee_;
54 }
55
58 {
59 std::scoped_lock const sl(lock_);
60 return clusterTxnLoadFee_;
61 }
62
63 static std::uint32_t
65 {
66 return kLftNormalFee;
67 }
68
75
85
86 void
88 {
89 JLOG(j_.trace()) << "setClusterFee: " << fee;
90 std::scoped_lock const sl(lock_);
92 }
93
94 bool
96 bool
98
99 bool
101 {
102 std::scoped_lock const sl(lock_);
103 return (raiseCount_ != 0) || (localTxnLoadFee_ != kLftNormalFee);
104 }
105
106 bool
108 {
109 std::scoped_lock const sl(lock_);
110 return (raiseCount_ != 0) || (localTxnLoadFee_ != kLftNormalFee) ||
112 }
113
114private:
115 static constexpr std::uint32_t kLftNormalFee = 256; // 256 is the minimum/normal load factor
116 static constexpr std::uint32_t kLftFeeIncFraction = 4; // increase fee by 1/4
117 static constexpr std::uint32_t kLftFeeDecFraction = 4; // decrease fee by 1/4
118 static constexpr std::uint32_t kLftFeeMax = kLftNormalFee * 1000000;
119
122
123 std::uint32_t localTxnLoadFee_{kLftNormalFee}; // Scale factor, lftNormalFee = normal fee
124 std::uint32_t remoteTxnLoadFee_{kLftNormalFee}; // Scale factor, lftNormalFee = normal fee
125 std::uint32_t clusterTxnLoadFee_{kLftNormalFee}; // 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:38
static Sink & getNullSink()
Returns a Sink which does nothing.
~LoadFeeTrack()=default
static constexpr std::uint32_t kLftNormalFee
static constexpr std::uint32_t kLftFeeDecFraction
std::uint32_t clusterTxnLoadFee_
void setRemoteFee(std::uint32_t f)
std::uint32_t getClusterFee() const
std::uint32_t getLocalFee() const
std::uint32_t remoteTxnLoadFee_
std::uint32_t getRemoteFee() const
std::uint32_t getLoadFactor() const
void setClusterFee(std::uint32_t fee)
static std::uint32_t getLoadBase()
bool isLoadedLocal() const
static constexpr std::uint32_t kLftFeeMax
std::uint32_t localTxnLoadFee_
std::uint32_t raiseCount_
static constexpr std::uint32_t kLftFeeIncFraction
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()))
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)
Reflects the fee settings for a particular ledger.