reth_engine_tree/tree/
metrics.rs

1use reth_blockchain_tree::metrics::TreeMetrics;
2use reth_evm::metrics::ExecutorMetrics;
3use reth_metrics::{
4    metrics::{Counter, Gauge, Histogram},
5    Metrics,
6};
7use reth_trie::updates::TrieUpdates;
8
9/// Metrics for the `EngineApi`.
10#[derive(Debug, Default)]
11pub(crate) struct EngineApiMetrics {
12    /// Engine API-specific metrics.
13    pub(crate) engine: EngineMetrics,
14    /// Block executor metrics.
15    pub(crate) executor: ExecutorMetrics,
16    /// Metrics for block validation
17    pub(crate) block_validation: BlockValidationMetrics,
18    /// A copy of legacy blockchain tree metrics, to be replaced when we replace the old tree
19    pub(crate) tree: TreeMetrics,
20}
21
22/// Metrics for the `EngineApi`.
23#[derive(Metrics)]
24#[metrics(scope = "consensus.engine.beacon")]
25pub(crate) struct EngineMetrics {
26    /// How many executed blocks are currently stored.
27    pub(crate) executed_blocks: Gauge,
28    /// How many already executed blocks were directly inserted into the tree.
29    pub(crate) inserted_already_executed_blocks: Counter,
30    /// The number of times the pipeline was run.
31    pub(crate) pipeline_runs: Counter,
32    /// The total count of forkchoice updated messages received.
33    pub(crate) forkchoice_updated_messages: Counter,
34    /// The total count of new payload messages received.
35    pub(crate) new_payload_messages: Counter,
36    /// Histogram of persistence operation durations (in seconds)
37    pub(crate) persistence_duration: Histogram,
38    /// Tracks the how often we failed to deliver a newPayload response.
39    ///
40    /// This effectively tracks how often the message sender dropped the channel and indicates a CL
41    /// request timeout (e.g. it took more than 8s to send the response and the CL terminated the
42    /// request which resulted in a closed channel).
43    pub(crate) failed_new_payload_response_deliveries: Counter,
44    /// Tracks the how often we failed to deliver a forkchoice update response.
45    pub(crate) failed_forkchoice_updated_response_deliveries: Counter,
46    // TODO add latency metrics
47}
48
49/// Metrics for non-execution related block validation.
50#[derive(Metrics)]
51#[metrics(scope = "sync.block_validation")]
52pub(crate) struct BlockValidationMetrics {
53    /// Total number of storage tries updated in the state root calculation
54    pub(crate) state_root_storage_tries_updated_total: Counter,
55    /// Histogram of state root duration
56    pub(crate) state_root_histogram: Histogram,
57    /// Latest state root duration
58    pub(crate) state_root_duration: Gauge,
59}
60
61impl BlockValidationMetrics {
62    /// Records a new state root time, updating both the histogram and state root gauge
63    pub(crate) fn record_state_root(&self, trie_output: &TrieUpdates, elapsed_as_secs: f64) {
64        self.state_root_storage_tries_updated_total
65            .increment(trie_output.storage_tries_ref().len() as u64);
66        self.state_root_duration.set(elapsed_as_secs);
67        self.state_root_histogram.record(elapsed_as_secs);
68    }
69}