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#include <utility>
11
12namespace xrpl {
13
14struct Fees;
15
26class LoadFeeTrack final
27{
28public:
30 : j_(journal)
31 {
32 }
33
34 ~LoadFeeTrack() = default;
35
36 void
38 {
39 JLOG(j_.trace()) << "setRemoteFee: " << f;
40 std::scoped_lock const sl(lock_);
42 }
43
46 {
47 std::scoped_lock const sl(lock_);
48 return remoteTxnLoadFee_;
49 }
50
53 {
54 std::scoped_lock const sl(lock_);
55 return localTxnLoadFee_;
56 }
57
60 {
61 std::scoped_lock const sl(lock_);
62 return clusterTxnLoadFee_;
63 }
64
65 static std::uint32_t
67 {
68 return kLftNormalFee;
69 }
70
77
87
88 void
90 {
91 JLOG(j_.trace()) << "setClusterFee: " << fee;
92 std::scoped_lock const sl(lock_);
94 }
95
96 bool
98 bool
100
101 bool
103 {
104 std::scoped_lock const sl(lock_);
105 return (raiseCount_ != 0) || (localTxnLoadFee_ != kLftNormalFee);
106 }
107
108 bool
110 {
111 std::scoped_lock const sl(lock_);
112 return (raiseCount_ != 0) || (localTxnLoadFee_ != kLftNormalFee) ||
114 }
115
116private:
117 static constexpr std::uint32_t kLftNormalFee = 256; // 256 is the minimum/normal load factor
118 static constexpr std::uint32_t kLftFeeIncFraction = 4; // increase fee by 1/4
119 static constexpr std::uint32_t kLftFeeDecFraction = 4; // decrease fee by 1/4
120 static constexpr std::uint32_t kLftFeeMax = kLftNormalFee * 1000000;
121
124
125 std::uint32_t localTxnLoadFee_{kLftNormalFee}; // Scale factor, lftNormalFee = normal fee
126 std::uint32_t remoteTxnLoadFee_{kLftNormalFee}; // Scale factor, lftNormalFee = normal fee
127 std::uint32_t clusterTxnLoadFee_{kLftNormalFee}; // Scale factor, lftNormalFee = normal fee
129};
130
131//------------------------------------------------------------------------------
132
133// Scale using load as well as base rate
134XRPAmount
135scaleFeeLoad(XRPAmount fee, LoadFeeTrack const& feeTrack, Fees const& fees, bool bUnlimited);
136
137} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
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.