v31.1-roots.1 · Commit 3: [PATCH 03/17] feat(policy): preserve cluster accounting and repair dynamic dust
src/policy/feerate.cpp
Before: src/policy/feerate.cpp · After: src/policy/feerate.cpp
File metadata
index f62835acbcf2c1cb3458b2407b0d6a9881be7e19..e85a0b6da3f42b8199ecb1d6fc352cd232efbba2 100644
Download original patch · Release notes
Diff rows 1–47 of 47. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/policy/feerate.cpp
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
#include <policy/feerate.h>
|
|
8
8
|
#include <tinyformat.h>
|
|
9
9
|
|
|
10
|
+
#include <algorithm>
|
|
11
|
+
#include <limits>
|
|
12
|
+
|
|
10
13
|
|
|
11
14
|
CFeeRate::CFeeRate(const CAmount& nFeePaid, int32_t virtual_bytes)
|
|
12
15
|
{
|
|
@@ -21,11 +24,38 @@ CAmount CFeeRate::GetFee(int32_t virtual_bytes) const
|
|
|
21
24
|
{
|
|
22
25
|
Assume(virtual_bytes >= 0);
|
|
23
26
|
if (m_feerate.IsEmpty()) { return CAmount(0);}
|
|
27
|
+
if (virtual_bytes == 0) return 0;
|
|
28
|
+
constexpr CAmount maximum{std::numeric_limits<CAmount>::max()};
|
|
29
|
+
constexpr CAmount minimum{std::numeric_limits<CAmount>::min()};
|
|
30
|
+
if (m_feerate >> FeePerVSize{maximum, virtual_bytes}) return maximum;
|
|
31
|
+
if (m_feerate << FeePerVSize{minimum, virtual_bytes}) return minimum;
|
|
24
32
|
CAmount nFee = CAmount(m_feerate.EvaluateFeeUp(virtual_bytes));
|
|
25
33
|
if (nFee == 0 && virtual_bytes != 0 && m_feerate.fee < 0) return CAmount(-1);
|
|
26
34
|
return nFee;
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
CAmount CFeeRate::GetFeePerK() const
|
|
38
|
+
{
|
|
39
|
+
if (m_feerate.IsEmpty()) return 0;
|
|
40
|
+
constexpr CAmount maximum{std::numeric_limits<CAmount>::max()};
|
|
41
|
+
constexpr CAmount minimum{std::numeric_limits<CAmount>::min()};
|
|
42
|
+
if (m_feerate >> FeePerVSize{maximum, 1000}) return maximum;
|
|
43
|
+
if (m_feerate << FeePerVSize{minimum, 1000}) return minimum;
|
|
44
|
+
return m_feerate.EvaluateFeeDown(1000);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
CFeeRate ScaleDustFee(const CFeeRate& estimate, int multiplier)
|
|
48
|
+
{
|
|
49
|
+
Assume(multiplier > 0);
|
|
50
|
+
const CAmount rate{std::max<CAmount>(0, estimate.GetFeePerK())};
|
|
51
|
+
constexpr CAmount maximum{std::numeric_limits<CAmount>::max()};
|
|
52
|
+
const CAmount whole{rate / 1000};
|
|
53
|
+
if (whole > maximum / multiplier) return CFeeRate{maximum};
|
|
54
|
+
const CAmount base{whole * multiplier};
|
|
55
|
+
const CAmount remainder{(rate % 1000) * int64_t{multiplier} / 1000};
|
|
56
|
+
return CFeeRate{remainder > maximum - base ? maximum : base + remainder};
|
|
57
|
+
}
|
|
58
|
+
|
|
29
59
|
std::string CFeeRate::ToString(FeeRateFormat fee_rate_format) const
|
|
30
60
|
{
|
|
31
61
|
const CAmount feerate_per_kvb{GetFeePerK()};
|