1use reth_evm::metrics::ExecutorMetrics;
2use reth_metrics::{
3 metrics::{Counter, Gauge, Histogram},
4 Metrics,
5};
6use reth_trie::updates::TrieUpdates;
78/// Metrics for the `EngineApi`.
9#[derive(Debug, Default)]
10pub(crate) struct EngineApiMetrics {
11/// Engine API-specific metrics.
12pub(crate) engine: EngineMetrics,
13/// Block executor metrics.
14pub(crate) executor: ExecutorMetrics,
15/// Metrics for block validation
16pub(crate) block_validation: BlockValidationMetrics,
17/// A copy of legacy blockchain tree metrics, to be replaced when we replace the old tree
18pub(crate) tree: TreeMetrics,
19}
2021/// 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
26pub canonical_chain_height: Gauge,
27/// The number of reorgs
28pub reorgs: Counter,
29/// The latest reorg depth
30pub latest_reorg_depth: Gauge,
31}
3233/// 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.
38pub(crate) executed_blocks: Gauge,
39/// How many already executed blocks were directly inserted into the tree.
40pub(crate) inserted_already_executed_blocks: Counter,
41/// The number of times the pipeline was run.
42pub(crate) pipeline_runs: Counter,
43/// The total count of forkchoice updated messages received.
44pub(crate) forkchoice_updated_messages: Counter,
45/// The total count of new payload messages received.
46pub(crate) new_payload_messages: Counter,
47/// Histogram of persistence operation durations (in seconds)
48pub(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).
54pub(crate) failed_new_payload_response_deliveries: Counter,
55/// Tracks the how often we failed to deliver a forkchoice update response.
56pub(crate) failed_forkchoice_updated_response_deliveries: Counter,
57// TODO add latency metrics
58}
5960/// 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
65pub(crate) state_root_storage_tries_updated_total: Counter,
66/// Histogram of state root duration
67pub(crate) state_root_histogram: Histogram,
68/// Latest state root duration
69pub(crate) state_root_duration: Gauge,
70/// Trie input computation duration
71pub(crate) trie_input_duration: Histogram,
72}
7374impl BlockValidationMetrics {
75/// Records a new state root time, updating both the histogram and state root gauge
76pub(crate) fn record_state_root(&self, trie_output: &TrieUpdates, elapsed_as_secs: f64) {
77self.state_root_storage_tries_updated_total
78 .increment(trie_output.storage_tries_ref().len() as u64);
79self.state_root_duration.set(elapsed_as_secs);
80self.state_root_histogram.record(elapsed_as_secs);
81 }
82}
8384/// 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
89pub blocks: Gauge,
90}