Skip to content

Commit fd29d3d

Browse files
committed
Remove checking of mempool min fee from estimateSmartFee.
This check has been moved to the wallet logic GetMinimumFee. The rpc call to estimatesmartfee will now no longer return a result maxed with the mempool min fee, but automated fee calculations from the wallet will produce the same result as before and coincontrol and sendcoins dialogs in the GUI will correctly display the right prospective fee. changes to policy/fees.cpp include a big whitespace indentation change.
1 parent 2fffaa9 commit fd29d3d

File tree

5 files changed

+60
-73
lines changed

5 files changed

+60
-73
lines changed

src/policy/fees.cpp

+51-59
Original file line numberDiff line numberDiff line change
@@ -826,89 +826,81 @@ double CBlockPolicyEstimator::estimateConservativeFee(unsigned int doubleTarget,
826826
* estimates, however, required the 95% threshold at 2 * target be met for any
827827
* longer time horizons also.
828828
*/
829-
CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation *feeCalc, const CTxMemPool& pool, bool conservative) const
829+
CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation *feeCalc, bool conservative) const
830830
{
831+
LOCK(cs_feeEstimator);
832+
831833
if (feeCalc) {
832834
feeCalc->desiredTarget = confTarget;
833835
feeCalc->returnedTarget = confTarget;
834836
}
835837

836838
double median = -1;
837839
EstimationResult tempResult;
838-
{
839-
LOCK(cs_feeEstimator);
840840

841-
// Return failure if trying to analyze a target we're not tracking
842-
if (confTarget <= 0 || (unsigned int)confTarget > longStats->GetMaxConfirms())
843-
return CFeeRate(0);
841+
// Return failure if trying to analyze a target we're not tracking
842+
if (confTarget <= 0 || (unsigned int)confTarget > longStats->GetMaxConfirms())
843+
return CFeeRate(0);
844844

845-
// It's not possible to get reasonable estimates for confTarget of 1
846-
if (confTarget == 1)
847-
confTarget = 2;
845+
// It's not possible to get reasonable estimates for confTarget of 1
846+
if (confTarget == 1)
847+
confTarget = 2;
848848

849-
unsigned int maxUsableEstimate = MaxUsableEstimate();
850-
if (maxUsableEstimate <= 1)
851-
return CFeeRate(0);
849+
unsigned int maxUsableEstimate = MaxUsableEstimate();
850+
if (maxUsableEstimate <= 1)
851+
return CFeeRate(0);
852852

853-
if ((unsigned int)confTarget > maxUsableEstimate) {
854-
confTarget = maxUsableEstimate;
855-
}
853+
if ((unsigned int)confTarget > maxUsableEstimate) {
854+
confTarget = maxUsableEstimate;
855+
}
856856

857-
assert(confTarget > 0); //estimateCombinedFee and estimateConservativeFee take unsigned ints
858-
/** true is passed to estimateCombined fee for target/2 and target so
859-
* that we check the max confirms for shorter time horizons as well.
860-
* This is necessary to preserve monotonically increasing estimates.
861-
* For non-conservative estimates we do the same thing for 2*target, but
862-
* for conservative estimates we want to skip these shorter horizons
863-
* checks for 2*target because we are taking the max over all time
864-
* horizons so we already have monotonically increasing estimates and
865-
* the purpose of conservative estimates is not to let short term
866-
* fluctuations lower our estimates by too much.
867-
*/
868-
double halfEst = estimateCombinedFee(confTarget/2, HALF_SUCCESS_PCT, true, &tempResult);
857+
assert(confTarget > 0); //estimateCombinedFee and estimateConservativeFee take unsigned ints
858+
/** true is passed to estimateCombined fee for target/2 and target so
859+
* that we check the max confirms for shorter time horizons as well.
860+
* This is necessary to preserve monotonically increasing estimates.
861+
* For non-conservative estimates we do the same thing for 2*target, but
862+
* for conservative estimates we want to skip these shorter horizons
863+
* checks for 2*target because we are taking the max over all time
864+
* horizons so we already have monotonically increasing estimates and
865+
* the purpose of conservative estimates is not to let short term
866+
* fluctuations lower our estimates by too much.
867+
*/
868+
double halfEst = estimateCombinedFee(confTarget/2, HALF_SUCCESS_PCT, true, &tempResult);
869+
if (feeCalc) {
870+
feeCalc->est = tempResult;
871+
feeCalc->reason = FeeReason::HALF_ESTIMATE;
872+
}
873+
median = halfEst;
874+
double actualEst = estimateCombinedFee(confTarget, SUCCESS_PCT, true, &tempResult);
875+
if (actualEst > median) {
876+
median = actualEst;
869877
if (feeCalc) {
870878
feeCalc->est = tempResult;
871-
feeCalc->reason = FeeReason::HALF_ESTIMATE;
879+
feeCalc->reason = FeeReason::FULL_ESTIMATE;
872880
}
873-
median = halfEst;
874-
double actualEst = estimateCombinedFee(confTarget, SUCCESS_PCT, true, &tempResult);
875-
if (actualEst > median) {
876-
median = actualEst;
877-
if (feeCalc) {
878-
feeCalc->est = tempResult;
879-
feeCalc->reason = FeeReason::FULL_ESTIMATE;
880-
}
881+
}
882+
double doubleEst = estimateCombinedFee(2 * confTarget, DOUBLE_SUCCESS_PCT, !conservative, &tempResult);
883+
if (doubleEst > median) {
884+
median = doubleEst;
885+
if (feeCalc) {
886+
feeCalc->est = tempResult;
887+
feeCalc->reason = FeeReason::DOUBLE_ESTIMATE;
881888
}
882-
double doubleEst = estimateCombinedFee(2 * confTarget, DOUBLE_SUCCESS_PCT, !conservative, &tempResult);
883-
if (doubleEst > median) {
884-
median = doubleEst;
889+
}
890+
891+
if (conservative || median == -1) {
892+
double consEst = estimateConservativeFee(2 * confTarget, &tempResult);
893+
if (consEst > median) {
894+
median = consEst;
885895
if (feeCalc) {
886896
feeCalc->est = tempResult;
887-
feeCalc->reason = FeeReason::DOUBLE_ESTIMATE;
897+
feeCalc->reason = FeeReason::CONSERVATIVE;
888898
}
889899
}
890-
891-
if (conservative || median == -1) {
892-
double consEst = estimateConservativeFee(2 * confTarget, &tempResult);
893-
if (consEst > median) {
894-
median = consEst;
895-
if (feeCalc) {
896-
feeCalc->est = tempResult;
897-
feeCalc->reason = FeeReason::CONSERVATIVE;
898-
}
899-
}
900-
}
901-
} // Must unlock cs_feeEstimator before taking mempool locks
900+
}
902901

903902
if (feeCalc) feeCalc->returnedTarget = confTarget;
904903

905-
// If mempool is limiting txs , return at least the min feerate from the mempool
906-
CAmount minPoolFee = pool.GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
907-
if (minPoolFee > 0 && minPoolFee > median) {
908-
if (feeCalc) feeCalc->reason = FeeReason::MEMPOOL_MIN;
909-
return CFeeRate(minPoolFee);
910-
}
911-
912904
if (median < 0)
913905
return CFeeRate(0);
914906

src/policy/fees.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class CBlockPolicyEstimator
208208
* the closest target where one can be given. 'conservative' estimates are
209209
* valid over longer time horizons also.
210210
*/
211-
CFeeRate estimateSmartFee(int confTarget, FeeCalculation *feeCalc, const CTxMemPool& pool, bool conservative) const;
211+
CFeeRate estimateSmartFee(int confTarget, FeeCalculation *feeCalc, bool conservative) const;
212212

213213
/** Return a specific fee estimate calculation with a given success
214214
* threshold and time horizon, and optionally return detailed data about

src/rpc/mining.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,6 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
815815
"\n"
816816
"A negative value is returned if not enough transactions and blocks\n"
817817
"have been observed to make an estimate for any number of blocks.\n"
818-
"However it will not return a value below the mempool reject fee.\n"
819818
"\nExample:\n"
820819
+ HelpExampleCli("estimatesmartfee", "6")
821820
);
@@ -831,7 +830,7 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
831830

832831
UniValue result(UniValue::VOBJ);
833832
FeeCalculation feeCalc;
834-
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(nBlocks, &feeCalc, ::mempool, conservative);
833+
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(nBlocks, &feeCalc, conservative);
835834
result.push_back(Pair("feerate", feeRate == CFeeRate(0) ? -1.0 : ValueFromAmount(feeRate.GetFeePerK())));
836835
result.push_back(Pair("blocks", feeCalc.returnedTarget));
837836
return result;

src/test/policyestimator_tests.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,6 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
177177
for (int i = 2; i < 9; i++) { // At 9, the original estimate was already at the bottom (b/c scale = 2)
178178
BOOST_CHECK(feeEst.estimateFee(i).GetFeePerK() < origFeeEst[i-1] - deltaFee);
179179
}
180-
181-
// Test that if the mempool is limited, estimateSmartFee won't return a value below the mempool min fee
182-
mpool.addUnchecked(tx.GetHash(), entry.Fee(feeV[5]).Time(GetTime()).Height(blocknum).FromTx(tx));
183-
// evict that transaction which should set a mempool min fee of minRelayTxFee + feeV[5]
184-
mpool.TrimToSize(1);
185-
BOOST_CHECK(mpool.GetMinFee(1).GetFeePerK() > feeV[5]);
186-
for (int i = 1; i < 10; i++) {
187-
BOOST_CHECK(feeEst.estimateSmartFee(i, NULL, mpool, true).GetFeePerK() >= feeEst.estimateRawFee(i, 0.85, FeeEstimateHorizon::MED_HALFLIFE).GetFeePerK());
188-
BOOST_CHECK(feeEst.estimateSmartFee(i, NULL, mpool, true).GetFeePerK() >= mpool.GetMinFee(1).GetFeePerK());
189-
}
190180
}
191181

192182
BOOST_AUTO_TEST_SUITE_END()

src/wallet/wallet.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -2951,12 +2951,18 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, const CCoinControl& coin_c
29512951
if (coin_control.m_fee_mode == FeeEstimateMode::CONSERVATIVE) conservative_estimate = true;
29522952
else if (coin_control.m_fee_mode == FeeEstimateMode::ECONOMICAL) conservative_estimate = false;
29532953

2954-
fee_needed = estimator.estimateSmartFee(target, feeCalc, pool, conservative_estimate).GetFee(nTxBytes);
2954+
fee_needed = estimator.estimateSmartFee(target, feeCalc, conservative_estimate).GetFee(nTxBytes);
29552955
if (fee_needed == 0) {
29562956
// if we don't have enough data for estimateSmartFee, then use fallbackFee
29572957
fee_needed = fallbackFee.GetFee(nTxBytes);
29582958
if (feeCalc) feeCalc->reason = FeeReason::FALLBACK;
29592959
}
2960+
// Obey mempool min fee when using smart fee estimation
2961+
CAmount min_mempool_fee = pool.GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFee(nTxBytes);
2962+
if (fee_needed < min_mempool_fee) {
2963+
fee_needed = min_mempool_fee;
2964+
if (feeCalc) feeCalc->reason = FeeReason::MEMPOOL_MIN;
2965+
}
29602966
}
29612967

29622968
// prevent user from paying a fee below minRelayTxFee or minTxFee

0 commit comments

Comments
 (0)