reth_engine_tree/tree/
metrics.rs

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