Skip to content

Commit

Permalink
[fees]: log estimates in intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaelsadeeq committed Oct 3, 2024
1 parent 4ff7beb commit 5a9c7d6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)

node.fee_estimator = std::make_unique<FeeEstimator>(FeeestPath(args), read_stale_estimates, node.mempool.get());
node.fee_estimator->RegisterForecaster(std::make_shared<MemPoolForecaster>(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>();
NTime* time_forecaster_ptr = n_time_forecaster.get();
Expand Down
18 changes: 18 additions & 0 deletions src/policy/fee_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <policy/fees.h>
#include <logging.h>
#include <policy/fee_estimator.h>
#include <policy/forecaster.h>
Expand Down Expand Up @@ -95,3 +96,20 @@ std::pair<ForecastResult, std::vector<std::string>> FeeEstimator::GetFeeEstimate
}
return std::make_pair(forecast, err_messages);
};


void FeeEstimator::GetAllEstimates()
{
const std::vector<int> hours{1, 3, 5, 10, 20, 50, 100, 202, 500, 504};
for (auto hour: hours){
unsigned int conf_target = static_cast<unsigned int>(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);
}
}
4 changes: 4 additions & 0 deletions src/policy/fee_estimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
12 changes: 6 additions & 6 deletions src/policy/forecasters/ntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,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
Expand All @@ -144,9 +144,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) {
Expand Down

0 comments on commit 5a9c7d6

Please sign in to comment.