rippled
Loading...
Searching...
No Matches
LoadFeeTrack.cpp
1#include <xrpld/app/misc/LoadFeeTrack.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/contract.h>
5#include <xrpl/basics/safe_cast.h>
6#include <xrpl/protocol/Units.h>
7
8#include <cstdint>
9
10namespace ripple {
11
12bool
14{
16
17 if (++raiseCount_ < 2)
18 return false;
19
20 std::uint32_t const origFee = localTxnLoadFee_;
21
22 // make sure this fee takes effect
25
26 // Increase slowly
28
31
32 if (origFee == localTxnLoadFee_)
33 return false;
34
35 JLOG(j_.debug()) << "Local load fee raised from " << origFee << " to "
37 return true;
38}
39
40bool
42{
44 std::uint32_t const origFee = localTxnLoadFee_;
45 raiseCount_ = 0;
46
47 // Reduce slowly
49
52
53 if (origFee == localTxnLoadFee_)
54 return false;
55
56 JLOG(j_.debug()) << "Local load fee lowered from " << origFee << " to "
58 return true;
59}
60
61//------------------------------------------------------------------------------
62
63// Scale using load as well as base rate
66 XRPAmount fee,
67 LoadFeeTrack const& feeTrack,
68 Fees const& fees,
69 bool bUnlimited)
70{
71 if (fee == 0)
72 return fee;
73
74 // Collect the fee rates
75 auto [feeFactor, uRemFee] = feeTrack.getScalingFactors();
76
77 // Let privileged users pay the normal fee until
78 // the local load exceeds four times the remote.
79 if (bUnlimited && (feeFactor > uRemFee) && (feeFactor < (4 * uRemFee)))
80 feeFactor = uRemFee;
81
82 // Compute:
83 // fee = fee * feeFactor / (lftNormalFee);
84 // without overflow, and as accurately as possible
85
86 auto const result = mulDiv(
87 fee, feeFactor, safe_cast<std::uint64_t>(feeTrack.getLoadBase()));
88 if (!result)
89 Throw<std::overflow_error>("scaleFeeLoad");
90 return *result;
91}
92
93} // namespace ripple
Stream debug() const
Definition Journal.h:309
Manages the current fee schedule.
static std::uint32_t constexpr lftFeeIncFraction
beast::Journal const j_
static std::uint32_t constexpr lftNormalFee
std::uint32_t raiseCount_
std::uint32_t localTxnLoadFee_
std::uint32_t remoteTxnLoadFee_
std::uint32_t getLoadBase() const
std::pair< std::uint32_t, std::uint32_t > getScalingFactors() const
static std::uint32_t constexpr lftFeeDecFraction
static std::uint32_t constexpr lftFeeMax
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
std::optional< std::uint64_t > mulDiv(std::uint64_t value, std::uint64_t mul, std::uint64_t div)
Return value*mul/div accurately.
Reflects the fee settings for a particular ledger.