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 Jul 8, 2024
1 parent c9b3d6b commit a87f95a
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 `unsigned 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 `unsigned 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 @@ -9,6 +9,7 @@
#include <policy/forecaster.h>
#include <policy/forecaster_util.h>
#include <txmempool.h>
#include <util/trace.h>


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


Expand Down Expand Up @@ -42,6 +43,15 @@ ForecastResult MemPoolForecaster::EstimateFee(unsigned 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_estimate = fee_rate_estimate_result.p25;
forecast_options.high_priority_estimate = fee_rate_estimate_result.p50;
Expand Down

0 comments on commit a87f95a

Please sign in to comment.