Skip to content

Commit

Permalink
[tracing]: add fee estimator tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaelsadeeq committed Oct 14, 2024
1 parent be80fe0 commit 17b16dd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
29 changes: 29 additions & 0 deletions doc/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,35 @@ Arguments passed:
1. Transaction ID (hash) as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)
2. Reject reason as `pointer to C-style String` (max. length 118 characters)

### Context `fee_estimator`
#### Tracepoint `fee_estimator:estimate_calculated`

Is called when a fee estimate is generated from forecasters and the best estimate is selected. It Passes information about the estimate and which forecaster provided the
estimate.

Arguments passed:
1. Confirmation target in `int`
2. Forecaster that provided the estimate as `pointer to C-style String` (max. length 16 characters)
3. Block Height the estimate was made as `unsigned int`
4. Low priority estimate in sat/kvB as `int64`
5. High priority estimate in sat/kvB as `int64`

### Context `feerate_forecast`
#### Tracepoint `feerate_forecast:forecast_generated`

Is called when a fee rate forecaster estimate a fee rate for a confirmation target. It Passes the quartile fee rates.

Arguments passed:
1. Confirmation target in `int`
2. Block Height the estimate was made as `unsigned int`
3. Forecaster that provided the estimate as `pointer to C-style String` (max. length 16 characters)
4. 5th Quartile fee rate in sat/kvB as `int64`
5. 25th Quartile fee rate in sat/kvB as `int64`
6. 50th Quartile fee rate in sat/kvB as `int64`
7. 75th Quartile fee rate in sat/kvB as `int64`



## Adding tracepoints to Bitcoin Core

To add a new tracepoint, `#include <util/trace.h>` in the compilation unit where
Expand Down
7 changes: 7 additions & 0 deletions src/policy/fee_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <policy/forecaster.h>
#include <policy/forecaster_util.h>
#include <txmempool.h>
#include <util/trace.h>

void FeeEstimator::RegisterForecaster(std::unique_ptr<Forecaster> forecaster)
{
Expand Down Expand Up @@ -87,6 +88,12 @@ std::pair<ForecastResult, std::vector<std::string>> FeeEstimator::GetFeeEstimate
LogDebug(BCLog::ESTIMATEFEE, "FeeEst %s: Block height %s, low priority feerate %s %s/kvB, high priority feerate %s %s/kvB.\n",
forecastTypeToString(forecast.m_opt.forecaster), forecast.m_opt.block_height, forecast.m_opt.low_priority.GetFeePerK(),
CURRENCY_ATOM, forecast.m_opt.high_priority.GetFeePerK(), CURRENCY_ATOM);
TRACE5(fee_estimator, estimate_calculated,
targetBlocks,
forecastTypeToString(forecast.m_opt.forecaster).c_str(),
forecast.m_opt.block_height,
forecast.m_opt.low_priority.GetFeePerK(),
forecast.m_opt.high_priority.GetFeePerK());
}
return std::make_pair(forecast, err_messages);
};
10 changes: 10 additions & 0 deletions src/policy/forecasters/mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <logging.h>
#include <node/miner.h>
#include <policy/forecasters/mempool.h>
#include <util/trace.h>
#include <validation.h>


Expand Down Expand Up @@ -40,6 +41,15 @@ ForecastResult MemPoolForecaster::EstimateFee(int targetBlocks)
forecastTypeToString(m_forecastType), forecast_options.block_height, fee_rate_estimate_result.p75.GetFeePerK(), CURRENCY_ATOM, fee_rate_estimate_result.p50.GetFeePerK(), CURRENCY_ATOM,
fee_rate_estimate_result.p25.GetFeePerK(), CURRENCY_ATOM, fee_rate_estimate_result.p5.GetFeePerK(), CURRENCY_ATOM);

TRACE7(feerate_forecast, forecast_generated,
targetBlocks,
forecast_options.block_height,
forecastTypeToString(m_forecastType).c_str(),
fee_rate_estimate_result.p5.GetFeePerK(),
fee_rate_estimate_result.p25.GetFeePerK(),
fee_rate_estimate_result.p50.GetFeePerK(),
fee_rate_estimate_result.p75.GetFeePerK());

cache.update(fee_rate_estimate_result);
forecast_options.low_priority = fee_rate_estimate_result.p25;
forecast_options.high_priority = fee_rate_estimate_result.p50;
Expand Down

0 comments on commit 17b16dd

Please sign in to comment.