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