xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
server
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
12
namespace
xrpl
{
13
14
struct
Fees
;
15
26
class
LoadFeeTrack
final
27
{
28
public
:
29
explicit
LoadFeeTrack
(
beast::Journal
journal =
beast::Journal
(
beast::Journal::getNullSink
()))
30
:
j_
(journal)
31
{
32
}
33
34
~LoadFeeTrack
() =
default
;
35
36
void
37
setRemoteFee
(
std::uint32_t
f)
38
{
39
JLOG(
j_
.trace()) <<
"setRemoteFee: "
<< f;
40
std::scoped_lock
const
sl(
lock_
);
41
remoteTxnLoadFee_
= f;
42
}
43
44
std::uint32_t
45
getRemoteFee
()
const
46
{
47
std::scoped_lock
const
sl(
lock_
);
48
return
remoteTxnLoadFee_
;
49
}
50
51
std::uint32_t
52
getLocalFee
()
const
53
{
54
std::scoped_lock
const
sl(
lock_
);
55
return
localTxnLoadFee_
;
56
}
57
58
std::uint32_t
59
getClusterFee
()
const
60
{
61
std::scoped_lock
const
sl(
lock_
);
62
return
clusterTxnLoadFee_
;
63
}
64
65
static
std::uint32_t
66
getLoadBase
()
67
{
68
return
kLftNormalFee
;
69
}
70
71
std::uint32_t
72
getLoadFactor
()
const
73
{
74
std::scoped_lock
const
sl(
lock_
);
75
return
std::max
({
clusterTxnLoadFee_
,
localTxnLoadFee_
,
remoteTxnLoadFee_
});
76
}
77
78
std::pair<std::uint32_t, std::uint32_t>
79
getScalingFactors
()
const
80
{
81
std::scoped_lock
const
sl(
lock_
);
82
83
return
std::make_pair
(
84
std::max
(
localTxnLoadFee_
,
remoteTxnLoadFee_
),
85
std::max
(
remoteTxnLoadFee_
,
clusterTxnLoadFee_
));
86
}
87
88
void
89
setClusterFee
(
std::uint32_t
fee)
90
{
91
JLOG(
j_
.trace()) <<
"setClusterFee: "
<< fee;
92
std::scoped_lock
const
sl(
lock_
);
93
clusterTxnLoadFee_
= fee;
94
}
95
96
bool
97
raiseLocalFee
();
98
bool
99
lowerLocalFee
();
100
101
bool
102
isLoadedLocal
()
const
103
{
104
std::scoped_lock
const
sl(
lock_
);
105
return
(
raiseCount_
!= 0) || (
localTxnLoadFee_
!=
kLftNormalFee
);
106
}
107
108
bool
109
isLoadedCluster
()
const
110
{
111
std::scoped_lock
const
sl(
lock_
);
112
return
(
raiseCount_
!= 0) || (
localTxnLoadFee_
!=
kLftNormalFee
) ||
113
(
clusterTxnLoadFee_
!=
kLftNormalFee
);
114
}
115
116
private
:
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
122
beast::Journal
const
j_
;
123
std::mutex
mutable
lock_
;
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
128
std::uint32_t
raiseCount_
{0};
129
};
130
131
//------------------------------------------------------------------------------
132
133
// Scale using load as well as base rate
134
XRPAmount
135
scaleFeeLoad
(XRPAmount fee, LoadFeeTrack
const
& feeTrack, Fees
const
& fees,
bool
bUnlimited);
136
137
}
// namespace xrpl
algorithm
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::Journal::getNullSink
static Sink & getNullSink()
Returns a Sink which does nothing.
Definition
beast_Journal.cpp:63
xrpl::LoadFeeTrack::~LoadFeeTrack
~LoadFeeTrack()=default
xrpl::LoadFeeTrack::kLftNormalFee
static constexpr std::uint32_t kLftNormalFee
Definition
LoadFeeTrack.h:117
xrpl::LoadFeeTrack::raiseLocalFee
bool raiseLocalFee()
Definition
LoadFeeTrack.cpp:17
xrpl::LoadFeeTrack::kLftFeeDecFraction
static constexpr std::uint32_t kLftFeeDecFraction
Definition
LoadFeeTrack.h:119
xrpl::LoadFeeTrack::clusterTxnLoadFee_
std::uint32_t clusterTxnLoadFee_
Definition
LoadFeeTrack.h:127
xrpl::LoadFeeTrack::setRemoteFee
void setRemoteFee(std::uint32_t f)
Definition
LoadFeeTrack.h:37
xrpl::LoadFeeTrack::getClusterFee
std::uint32_t getClusterFee() const
Definition
LoadFeeTrack.h:59
xrpl::LoadFeeTrack::getLocalFee
std::uint32_t getLocalFee() const
Definition
LoadFeeTrack.h:52
xrpl::LoadFeeTrack::remoteTxnLoadFee_
std::uint32_t remoteTxnLoadFee_
Definition
LoadFeeTrack.h:126
xrpl::LoadFeeTrack::getRemoteFee
std::uint32_t getRemoteFee() const
Definition
LoadFeeTrack.h:45
xrpl::LoadFeeTrack::lowerLocalFee
bool lowerLocalFee()
Definition
LoadFeeTrack.cpp:42
xrpl::LoadFeeTrack::getLoadFactor
std::uint32_t getLoadFactor() const
Definition
LoadFeeTrack.h:72
xrpl::LoadFeeTrack::setClusterFee
void setClusterFee(std::uint32_t fee)
Definition
LoadFeeTrack.h:89
xrpl::LoadFeeTrack::getLoadBase
static std::uint32_t getLoadBase()
Definition
LoadFeeTrack.h:66
xrpl::LoadFeeTrack::isLoadedLocal
bool isLoadedLocal() const
Definition
LoadFeeTrack.h:102
xrpl::LoadFeeTrack::kLftFeeMax
static constexpr std::uint32_t kLftFeeMax
Definition
LoadFeeTrack.h:120
xrpl::LoadFeeTrack::lock_
std::mutex lock_
Definition
LoadFeeTrack.h:123
xrpl::LoadFeeTrack::localTxnLoadFee_
std::uint32_t localTxnLoadFee_
Definition
LoadFeeTrack.h:125
xrpl::LoadFeeTrack::raiseCount_
std::uint32_t raiseCount_
Definition
LoadFeeTrack.h:128
xrpl::LoadFeeTrack::kLftFeeIncFraction
static constexpr std::uint32_t kLftFeeIncFraction
Definition
LoadFeeTrack.h:118
xrpl::LoadFeeTrack::j_
beast::Journal const j_
Definition
LoadFeeTrack.h:122
xrpl::LoadFeeTrack::isLoadedCluster
bool isLoadedCluster() const
Definition
LoadFeeTrack.h:109
xrpl::LoadFeeTrack::getScalingFactors
std::pair< std::uint32_t, std::uint32_t > getScalingFactors() const
Definition
LoadFeeTrack.h:79
xrpl::LoadFeeTrack::LoadFeeTrack
LoadFeeTrack(beast::Journal journal=beast::Journal(beast::Journal::getNullSink()))
Definition
LoadFeeTrack.h:29
cstdint
std::uint32_t
std::make_pair
T make_pair(T... args)
std::max
T max(T... args)
mutex
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::scaleFeeLoad
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
Definition
LoadFeeTrack.cpp:64
std::pair
std::scoped_lock
xrpl::Fees
Reflects the fee settings for a particular ledger.
Definition
protocol/Fees.h:20
utility
Generated by
1.17.0