estimateSmartFee returns the max of the feerates calculated with a 60% * threshold required at target / 2, an 85% threshold required at target and a * 95% threshold required at 2 * target. Each calculation is performed at the * shortest time horizon which tracks the required target. Conservative * estimates, however, required the 95% threshold at 2 * target be met for any * longer time hori
| 818 | * longer time horizons also. |
| 819 | */ |
| 820 | CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation *feeCalc, bool conservative) const |
| 821 | { |
| 822 | LOCK(cs_feeEstimator); |
| 823 | |
| 824 | if (feeCalc) { |
| 825 | feeCalc->desiredTarget = confTarget; |
| 826 | feeCalc->returnedTarget = confTarget; |
| 827 | } |
| 828 | |
| 829 | double median = -1; |
| 830 | EstimationResult tempResult; |
| 831 | |
| 832 | // Return failure if trying to analyze a target we're not tracking |
| 833 | if (confTarget <= 0 || (unsigned int)confTarget > longStats->GetMaxConfirms()) { |
| 834 | return CFeeRate(0); // error condition |
| 835 | } |
| 836 | |
| 837 | // It's not possible to get reasonable estimates for confTarget of 1 |
| 838 | if (confTarget == 1) confTarget = 2; |
| 839 | |
| 840 | unsigned int maxUsableEstimate = MaxUsableEstimate(); |
| 841 | if ((unsigned int)confTarget > maxUsableEstimate) { |
| 842 | confTarget = maxUsableEstimate; |
| 843 | } |
| 844 | if (feeCalc) feeCalc->returnedTarget = confTarget; |
| 845 | |
| 846 | if (confTarget <= 1) return CFeeRate(0); // error condition |
| 847 | |
| 848 | assert(confTarget > 0); //estimateCombinedFee and estimateConservativeFee take unsigned ints |
| 849 | /** true is passed to estimateCombined fee for target/2 and target so |
| 850 | * that we check the max confirms for shorter time horizons as well. |
| 851 | * This is necessary to preserve monotonically increasing estimates. |
| 852 | * For non-conservative estimates we do the same thing for 2*target, but |
| 853 | * for conservative estimates we want to skip these shorter horizons |
| 854 | * checks for 2*target because we are taking the max over all time |
| 855 | * horizons so we already have monotonically increasing estimates and |
| 856 | * the purpose of conservative estimates is not to let short term |
| 857 | * fluctuations lower our estimates by too much. |
| 858 | */ |
| 859 | double halfEst = estimateCombinedFee(confTarget/2, HALF_SUCCESS_PCT, true, &tempResult); |
| 860 | if (feeCalc) { |
| 861 | feeCalc->est = tempResult; |
| 862 | feeCalc->reason = FeeReason::HALF_ESTIMATE; |
| 863 | } |
| 864 | median = halfEst; |
| 865 | double actualEst = estimateCombinedFee(confTarget, SUCCESS_PCT, true, &tempResult); |
| 866 | if (actualEst > median) { |
| 867 | median = actualEst; |
| 868 | if (feeCalc) { |
| 869 | feeCalc->est = tempResult; |
| 870 | feeCalc->reason = FeeReason::FULL_ESTIMATE; |
| 871 | } |
| 872 | } |
| 873 | double doubleEst = estimateCombinedFee(2 * confTarget, DOUBLE_SUCCESS_PCT, !conservative, &tempResult); |
| 874 | if (doubleEst > median) { |
| 875 | median = doubleEst; |
| 876 | if (feeCalc) { |
| 877 | feeCalc->est = tempResult; |
no test coverage detected