@@ -20,6 +20,22 @@ CAmount GetRequiredFee(unsigned int nTxBytes)
20
20
21
21
22
22
CAmount GetMinimumFee (unsigned int nTxBytes, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation *feeCalc)
23
+ {
24
+ CAmount fee_needed = GetMinimumFeeRate (coin_control, pool, estimator, feeCalc).GetFee (nTxBytes);
25
+ // Always obey the maximum
26
+ if (fee_needed > maxTxFee) {
27
+ fee_needed = maxTxFee;
28
+ if (feeCalc) feeCalc->reason = FeeReason::MAXTXFEE;
29
+ }
30
+ return fee_needed;
31
+ }
32
+
33
+ CFeeRate GetRequiredFeeRate ()
34
+ {
35
+ return std::max (CWallet::minTxFee, ::minRelayTxFee);
36
+ }
37
+
38
+ CFeeRate GetMinimumFeeRate (const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation *feeCalc)
23
39
{
24
40
/* User control of how to calculate fee uses the following parameter precedence:
25
41
1. coin_control.m_feerate
@@ -28,15 +44,15 @@ CAmount GetMinimumFee(unsigned int nTxBytes, const CCoinControl& coin_control, c
28
44
4. nTxConfirmTarget (user-set global variable)
29
45
The first parameter that is set is used.
30
46
*/
31
- CAmount fee_needed ;
47
+ CFeeRate feerate_needed ;
32
48
if (coin_control.m_feerate ) { // 1.
33
- fee_needed = coin_control.m_feerate -> GetFee (nTxBytes );
49
+ feerate_needed = *( coin_control.m_feerate );
34
50
if (feeCalc) feeCalc->reason = FeeReason::PAYTXFEE;
35
51
// Allow to override automatic min/max check over coin control instance
36
- if (coin_control.fOverrideFeeRate ) return fee_needed ;
52
+ if (coin_control.fOverrideFeeRate ) return feerate_needed ;
37
53
}
38
54
else if (!coin_control.m_confirm_target && ::payTxFee != CFeeRate (0 )) { // 3. TODO: remove magic value of 0 for global payTxFee
39
- fee_needed = ::payTxFee. GetFee (nTxBytes) ;
55
+ feerate_needed = ::payTxFee;
40
56
if (feeCalc) feeCalc->reason = FeeReason::PAYTXFEE;
41
57
}
42
58
else { // 2. or 4.
@@ -48,38 +64,32 @@ CAmount GetMinimumFee(unsigned int nTxBytes, const CCoinControl& coin_control, c
48
64
if (coin_control.m_fee_mode == FeeEstimateMode::CONSERVATIVE) conservative_estimate = true ;
49
65
else if (coin_control.m_fee_mode == FeeEstimateMode::ECONOMICAL) conservative_estimate = false ;
50
66
51
- fee_needed = estimator.estimateSmartFee (target, feeCalc, conservative_estimate). GetFee (nTxBytes );
52
- if (fee_needed == 0 ) {
67
+ feerate_needed = estimator.estimateSmartFee (target, feeCalc, conservative_estimate);
68
+ if (feerate_needed == CFeeRate ( 0 ) ) {
53
69
// if we don't have enough data for estimateSmartFee, then use fallbackFee
54
- fee_needed = CWallet::fallbackFee. GetFee (nTxBytes) ;
70
+ feerate_needed = CWallet::fallbackFee;
55
71
if (feeCalc) feeCalc->reason = FeeReason::FALLBACK;
56
72
57
73
// directly return if fallback fee is disabled (feerate 0 == disabled)
58
- if (CWallet::fallbackFee. GetFee ( 1000 ) == 0 ) return fee_needed ;
74
+ if (CWallet::fallbackFee == CFeeRate ( 0 )) return feerate_needed ;
59
75
}
60
76
// Obey mempool min fee when using smart fee estimation
61
- CAmount min_mempool_fee = pool.GetMinFee (gArgs .GetArg (" -maxmempool" , DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 ). GetFee (nTxBytes );
62
- if (fee_needed < min_mempool_fee ) {
63
- fee_needed = min_mempool_fee ;
77
+ CFeeRate min_mempool_feerate = pool.GetMinFee (gArgs .GetArg (" -maxmempool" , DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 );
78
+ if (feerate_needed < min_mempool_feerate ) {
79
+ feerate_needed = min_mempool_feerate ;
64
80
if (feeCalc) feeCalc->reason = FeeReason::MEMPOOL_MIN;
65
81
}
66
82
}
67
83
68
84
// prevent user from paying a fee below minRelayTxFee or minTxFee
69
- CAmount required_fee = GetRequiredFee (nTxBytes );
70
- if (required_fee > fee_needed ) {
71
- fee_needed = required_fee ;
85
+ CFeeRate required_feerate = GetRequiredFeeRate ( );
86
+ if (required_feerate > feerate_needed ) {
87
+ feerate_needed = required_feerate ;
72
88
if (feeCalc) feeCalc->reason = FeeReason::REQUIRED;
73
89
}
74
- // But always obey the maximum
75
- if (fee_needed > maxTxFee) {
76
- fee_needed = maxTxFee;
77
- if (feeCalc) feeCalc->reason = FeeReason::MAXTXFEE;
78
- }
79
- return fee_needed;
90
+ return feerate_needed;
80
91
}
81
92
82
-
83
93
CFeeRate GetDiscardRate (const CBlockPolicyEstimator& estimator)
84
94
{
85
95
unsigned int highest_target = estimator.HighestTargetTracked (FeeEstimateHorizon::LONG_HALFLIFE);
0 commit comments