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 xrpl {
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 " << localTxnLoadFee_;
36 return true;
37}
38
39bool
41{
43 std::uint32_t const origFee = localTxnLoadFee_;
44 raiseCount_ = 0;
45
46 // Reduce slowly
48
51
52 if (origFee == localTxnLoadFee_)
53 return false;
54
55 JLOG(j_.debug()) << "Local load fee lowered from " << origFee << " to " << localTxnLoadFee_;
56 return true;
57}
58
59//------------------------------------------------------------------------------
60
61// Scale using load as well as base rate
63scaleFeeLoad(XRPAmount fee, LoadFeeTrack const& feeTrack, Fees const& fees, bool bUnlimited)
64{
65 if (fee == 0)
66 return fee;
67
68 // Collect the fee rates
69 auto [feeFactor, uRemFee] = feeTrack.getScalingFactors();
70
71 // Let privileged users pay the normal fee until
72 // the local load exceeds four times the remote.
73 if (bUnlimited && (feeFactor > uRemFee) && (feeFactor < (4 * uRemFee)))
74 feeFactor = uRemFee;
75
76 // Compute:
77 // fee = fee * feeFactor / (lftNormalFee);
78 // without overflow, and as accurately as possible
79
80 auto const result = mulDiv(fee, feeFactor, safe_cast<std::uint64_t>(feeTrack.getLoadBase()));
81 if (!result)
82 Throw<std::overflow_error>("scaleFeeLoad");
83 return *result;
84}
85
86} // 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:6
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.