diff --git a/src/init.cpp b/src/init.cpp index a765b89f61568c..d333b2dcf92777 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1655,6 +1655,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) node.fee_estimator = std::make_unique(FeeestPath(args), read_stale_estimates, node.mempool.get()); node.fee_estimator->RegisterForecaster(std::make_shared(node.mempool.get(), &(chainman.ActiveChainstate()))); + auto fee_estimator = node.fee_estimator.get(); + scheduler.scheduleEvery([fee_estimator] { fee_estimator->GetAllEstimates(); }, FEE_ESTIMATES_INTERVAL); auto n_time_forecaster = std::make_shared(); NTime* time_forecaster_ptr = n_time_forecaster.get(); diff --git a/src/policy/fee_estimator.cpp b/src/policy/fee_estimator.cpp index 4a3a3708799988..d1ff772e826a38 100644 --- a/src/policy/fee_estimator.cpp +++ b/src/policy/fee_estimator.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license. See the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include #include @@ -95,3 +96,20 @@ std::pair> FeeEstimator::GetFeeEstimate } return std::make_pair(forecast, err_messages); }; + + +void FeeEstimator::GetAllEstimates() +{ + const std::vector hours{1, 3, 5, 10, 20, 50, 100, 202, 500, 504}; + for (auto hour: hours){ + unsigned int conf_target = static_cast(hour * 6); + if (conf_target) { + FeeCalculation feeCalc; + bool conservative = true; + CFeeRate feeRate_conservative{block_policy_estimator.value()->estimateSmartFee(conf_target, &feeCalc, conservative)}; + CFeeRate feeRate_economical{block_policy_estimator.value()->estimateSmartFee(conf_target, &feeCalc, !conservative)}; + LogInfo("FeeEstLog PolicyEstimator: %s, %s, %s, %s\n", conf_target, feeCalc.bestheight, feeRate_conservative.GetFeePerK(), feeRate_economical.GetFeePerK()); + } + GetFeeEstimateFromForecasters(hour); + } +} diff --git a/src/policy/fee_estimator.h b/src/policy/fee_estimator.h index 132d8609d235b9..92855a5a3cb909 100644 --- a/src/policy/fee_estimator.h +++ b/src/policy/fee_estimator.h @@ -18,6 +18,8 @@ class CTxMemPool; class Forecaster; struct ForecastResult; +static constexpr std::chrono::minutes FEE_ESTIMATES_INTERVAL{1}; + /** \class FeeEstimator * Module for managing and utilising multiple fee rate forecasters to provide fee estimates. * @@ -77,6 +79,8 @@ class FeeEstimator * @return The maximum number of hours for which any forecaster can provide a fee rate estimate. */ int MaxForecastingTarget(); + + void GetAllEstimates(); }; #endif // BITCOIN_POLICY_FEE_ESTIMATOR_H diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 3c0873c3c18839..003bdee0c54647 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -940,6 +940,7 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation if (median < 0) return CFeeRate(0); // error condition + feeCalc->bestheight = nBestSeenHeight; return CFeeRate(llround(median)); } diff --git a/src/policy/forecasters/ntime.cpp b/src/policy/forecasters/ntime.cpp index 46655089687561..1003d1a10c4684 100644 --- a/src/policy/forecasters/ntime.cpp +++ b/src/policy/forecasters/ntime.cpp @@ -138,9 +138,9 @@ ForecastResult NTime::EstimateFee(int targetHours) LogDebug(BCLog::ESTIMATEFEE, "%s: Not enough tracked data to provide window estimate.\n", forecastTypeToString(m_forecastType)); } else { // Log the window estimate - LogDebug(BCLog::ESTIMATEFEE, "%s: Window: %d hours, 75th percentile fee rate: %s %s/kvB, 50th percentile feerate %s %s/kvB, 25th percentile feerate %s %s/kvB, 5th percentile feerate %s %s/kvB \n", - forecastTypeToString(m_forecastType), targetHours, window_percentiles.p75.GetFeePerK(), CURRENCY_ATOM, window_percentiles.p50.GetFeePerK(), CURRENCY_ATOM, - window_percentiles.p25.GetFeePerK(), CURRENCY_ATOM, window_percentiles.p5.GetFeePerK(), CURRENCY_ATOM); + LogDebug(BCLog::ESTIMATEFEE, "%s: Window: %d hours, %s, %s, %s, %s\n", + forecastTypeToString(m_forecastType), targetHours, window_percentiles.p75.GetFeePerK(), window_percentiles.p50.GetFeePerK(), + window_percentiles.p25.GetFeePerK(), window_percentiles.p5.GetFeePerK()); } // Get Historical Estimate @@ -149,9 +149,9 @@ ForecastResult NTime::EstimateFee(int targetHours) LogDebug(BCLog::ESTIMATEFEE, "%s: Not enough tracked data to provide historical estimate.\n", forecastTypeToString(m_forecastType)); } else { // Log the historical estimate - LogDebug(BCLog::ESTIMATEFEE, "%s: Historical: %d hours, 75th percentile fee rate: %s %s/kvB, 50th percentile feerate %s %s/kvB, 25th percentile feerate %s %s/kvB, 5th percentile feerate %s %s/kvB \n", - forecastTypeToString(m_forecastType), targetHours, historical_percentiles.p75.GetFeePerK(), CURRENCY_ATOM, historical_percentiles.p50.GetFeePerK(), CURRENCY_ATOM, - historical_percentiles.p25.GetFeePerK(), CURRENCY_ATOM, historical_percentiles.p5.GetFeePerK(), CURRENCY_ATOM); + LogDebug(BCLog::ESTIMATEFEE, "%s: Historical: %d, %s, %s, %s, %s \n", + forecastTypeToString(m_forecastType), targetHours, historical_percentiles.p75.GetFeePerK(), historical_percentiles.p50.GetFeePerK(), + historical_percentiles.p25.GetFeePerK(), historical_percentiles.p5.GetFeePerK()); } // Compare Window and Historical Estimates if (window_percentiles.p75 < historical_percentiles.p75) {