reth_trie_sparse/
metrics.rs

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