reth_trie_sparse/
metrics.rs

1//! Metrics for the sparse state trie
2
3#[cfg(feature = "metrics")]
4use reth_metrics::{metrics::Histogram, Metrics};
5
6/// 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)
11    pub(crate) multiproof_skipped_account_nodes: u64,
12    /// Number of total account nodes, including those that were skipped.
13    pub(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)
16    pub(crate) multiproof_skipped_storage_nodes: u64,
17    /// Number of total storage nodes, including those that were skipped.
18    pub(crate) multiproof_total_storage_nodes: u64,
19    /// The actual metrics we will record into the histogram
20    #[cfg(feature = "metrics")]
21    pub(crate) histograms: SparseStateTrieHistograms,
22}
23
24impl SparseStateTrieMetrics {
25    /// Record the metrics into the histograms
26    pub(crate) fn record(&self) {
27        #[cfg(feature = "metrics")]
28        {
29            self.histograms
30                .multiproof_skipped_account_nodes
31                .record(self.multiproof_skipped_account_nodes as f64);
32            self.histograms
33                .multiproof_total_account_nodes
34                .record(self.multiproof_total_account_nodes as f64);
35            self.histograms
36                .multiproof_skipped_storage_nodes
37                .record(self.multiproof_skipped_storage_nodes as f64);
38            self.histograms
39                .multiproof_total_storage_nodes
40                .record(self.multiproof_total_storage_nodes as f64);
41        }
42    }
43
44    /// Increment the skipped account nodes counter by the given count
45    pub(crate) const fn increment_skipped_account_nodes(&mut self, count: u64) {
46        self.multiproof_skipped_account_nodes += count;
47    }
48
49    /// Increment the total account nodes counter by the given count
50    pub(crate) const fn increment_total_account_nodes(&mut self, count: u64) {
51        self.multiproof_total_account_nodes += count;
52    }
53
54    /// Increment the skipped storage nodes counter by the given count
55    pub(crate) const fn increment_skipped_storage_nodes(&mut self, count: u64) {
56        self.multiproof_skipped_storage_nodes += count;
57    }
58
59    /// Increment the total storage nodes counter by the given count
60    pub(crate) const fn increment_total_storage_nodes(&mut self, count: u64) {
61        self.multiproof_total_storage_nodes += count;
62    }
63}
64
65/// 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)
72    pub(crate) multiproof_skipped_account_nodes: Histogram,
73    /// Histogram of total account nodes, including those that were skipped.
74    pub(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)
77    pub(crate) multiproof_skipped_storage_nodes: Histogram,
78    /// Histogram of total storage nodes, including those that were skipped.
79    pub(crate) multiproof_total_storage_nodes: Histogram,
80}