@@ -826,89 +826,81 @@ double CBlockPolicyEstimator::estimateConservativeFee(unsigned int doubleTarget,
826
826
* estimates, however, required the 95% threshold at 2 * target be met for any
827
827
* longer time horizons also.
828
828
*/
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
830
830
{
831
+ LOCK (cs_feeEstimator);
832
+
831
833
if (feeCalc) {
832
834
feeCalc->desiredTarget = confTarget;
833
835
feeCalc->returnedTarget = confTarget;
834
836
}
835
837
836
838
double median = -1 ;
837
839
EstimationResult tempResult;
838
- {
839
- LOCK (cs_feeEstimator);
840
840
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 );
844
844
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 ;
848
848
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 );
852
852
853
- if ((unsigned int )confTarget > maxUsableEstimate) {
854
- confTarget = maxUsableEstimate;
855
- }
853
+ if ((unsigned int )confTarget > maxUsableEstimate) {
854
+ confTarget = maxUsableEstimate;
855
+ }
856
856
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;
869
877
if (feeCalc) {
870
878
feeCalc->est = tempResult;
871
- feeCalc->reason = FeeReason::HALF_ESTIMATE ;
879
+ feeCalc->reason = FeeReason::FULL_ESTIMATE ;
872
880
}
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;
881
888
}
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;
885
895
if (feeCalc) {
886
896
feeCalc->est = tempResult;
887
- feeCalc->reason = FeeReason::DOUBLE_ESTIMATE ;
897
+ feeCalc->reason = FeeReason::CONSERVATIVE ;
888
898
}
889
899
}
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
+ }
902
901
903
902
if (feeCalc) feeCalc->returnedTarget = confTarget;
904
903
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
-
912
904
if (median < 0 )
913
905
return CFeeRate (0 );
914
906
0 commit comments