1//! Metrics for the sparse state trie
23#[cfg(feature = "metrics")]
4use reth_metrics::{metrics::Histogram, Metrics};
56/// Metrics for the sparse state trie
7#[derive(Default, Debug)]
8pub(crate) struct SparseStateTrieMetrics {
9/// Number of account nodes that were skipped during a multiproof reveal due to being redundant
10 /// (i.e. they were already revealed)
11pub(crate) multiproof_skipped_account_nodes: u64,
12/// Number of total account nodes, including those that were skipped.
13pub(crate) multiproof_total_account_nodes: u64,
14/// Number of storage nodes that were skipped during a multiproof reveal due to being redundant
15 /// (i.e. they were already revealed)
16pub(crate) multiproof_skipped_storage_nodes: u64,
17/// Number of total storage nodes, including those that were skipped.
18pub(crate) multiproof_total_storage_nodes: u64,
19/// The actual metrics we will record into the histogram
20#[cfg(feature = "metrics")]
21pub(crate) histograms: SparseStateTrieHistograms,
22}
2324impl SparseStateTrieMetrics {
25/// Record the metrics into the histograms
26pub(crate) fn record(&self) {
27#[cfg(feature = "metrics")]
28{
29self.histograms
30 .multiproof_skipped_account_nodes
31 .record(self.multiproof_skipped_account_nodes as f64);
32self.histograms
33 .multiproof_total_account_nodes
34 .record(self.multiproof_total_account_nodes as f64);
35self.histograms
36 .multiproof_skipped_storage_nodes
37 .record(self.multiproof_skipped_storage_nodes as f64);
38self.histograms
39 .multiproof_total_storage_nodes
40 .record(self.multiproof_total_storage_nodes as f64);
41 }
42 }
4344/// Increment the skipped account nodes counter by the given count
45pub(crate) const fn increment_skipped_account_nodes(&mut self, count: u64) {
46self.multiproof_skipped_account_nodes += count;
47 }
4849/// Increment the total account nodes counter by the given count
50pub(crate) const fn increment_total_account_nodes(&mut self, count: u64) {
51self.multiproof_total_account_nodes += count;
52 }
5354/// Increment the skipped storage nodes counter by the given count
55pub(crate) const fn increment_skipped_storage_nodes(&mut self, count: u64) {
56self.multiproof_skipped_storage_nodes += count;
57 }
5859/// Increment the total storage nodes counter by the given count
60pub(crate) const fn increment_total_storage_nodes(&mut self, count: u64) {
61self.multiproof_total_storage_nodes += count;
62 }
63}
6465/// Metrics for the sparse state trie
66#[cfg(feature = "metrics")]
67#[derive(Metrics)]
68#[metrics(scope = "sparse_state_trie")]
69pub(crate) struct SparseStateTrieHistograms {
70/// Histogram of account nodes that were skipped during a multiproof reveal due to being
71 /// redundant (i.e. they were already revealed)
72pub(crate) multiproof_skipped_account_nodes: Histogram,
73/// Histogram of total account nodes, including those that were skipped.
74pub(crate) multiproof_total_account_nodes: Histogram,
75/// Histogram of storage nodes that were skipped during a multiproof reveal due to being
76 /// redundant (i.e. they were already revealed)
77pub(crate) multiproof_skipped_storage_nodes: Histogram,
78/// Histogram of total storage nodes, including those that were skipped.
79pub(crate) multiproof_total_storage_nodes: Histogram,
80}