1//! Metrics for the sparse state trie
23use reth_metrics::{metrics::Histogram, Metrics};
45/// 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)
10pub(crate) multiproof_skipped_account_nodes: u64,
11/// Number of total account nodes, including those that were skipped.
12pub(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)
15pub(crate) multiproof_skipped_storage_nodes: u64,
16/// Number of total storage nodes, including those that were skipped.
17pub(crate) multiproof_total_storage_nodes: u64,
18/// The actual metrics we will record into the histogram
19pub(crate) histograms: SparseStateTrieHistograms,
20}
2122impl SparseStateTrieMetrics {
23/// Record the metrics into the histograms
24pub(crate) fn record(&self) {
25self.histograms
26 .multiproof_skipped_account_nodes
27 .record(self.multiproof_skipped_account_nodes as f64);
28self.histograms
29 .multiproof_total_account_nodes
30 .record(self.multiproof_total_account_nodes as f64);
31self.histograms
32 .multiproof_skipped_storage_nodes
33 .record(self.multiproof_skipped_storage_nodes as f64);
34self.histograms
35 .multiproof_total_storage_nodes
36 .record(self.multiproof_total_storage_nodes as f64);
37 }
3839/// Increment the skipped account nodes counter
40pub(crate) fn increment_skipped_account_nodes(&mut self) {
41self.multiproof_skipped_account_nodes += 1;
42 }
4344/// Increment the total account nodes counter
45pub(crate) fn increment_total_account_nodes(&mut self) {
46self.multiproof_total_account_nodes += 1;
47 }
4849/// Increment the skipped storage nodes counter
50pub(crate) fn increment_skipped_storage_nodes(&mut self) {
51self.multiproof_skipped_storage_nodes += 1;
52 }
5354/// Increment the total storage nodes counter
55pub(crate) fn increment_total_storage_nodes(&mut self) {
56self.multiproof_total_storage_nodes += 1;
57 }
58}
5960/// Metrics for the sparse state trie
61#[derive(Metrics)]
62#[metrics(scope = "sparse_state_trie")]
63pub(crate) struct SparseStateTrieHistograms {
64/// Histogram of account nodes that were skipped during a multiproof reveal due to being
65 /// redundant (i.e. they were already revealed)
66pub(crate) multiproof_skipped_account_nodes: Histogram,
67/// Histogram of total account nodes, including those that were skipped.
68pub(crate) multiproof_total_account_nodes: Histogram,
69/// Histogram of storage nodes that were skipped during a multiproof reveal due to being
70 /// redundant (i.e. they were already revealed)
71pub(crate) multiproof_skipped_storage_nodes: Histogram,
72/// Histogram of total storage nodes, including those that were skipped.
73pub(crate) multiproof_total_storage_nodes: Histogram,
74}