reth_trie_parallel/
stats.rs

1#[cfg(feature = "metrics")]
2use crate::proof_task_metrics::ProofTaskCursorMetricsCache;
3use derive_more::Deref;
4use reth_trie::stats::{TrieStats, TrieTracker};
5
6/// Trie stats.
7#[derive(Deref, Clone, Copy, Debug)]
8pub struct ParallelTrieStats {
9    #[deref]
10    trie: TrieStats,
11    precomputed_storage_roots: u64,
12    missed_leaves: u64,
13}
14
15impl ParallelTrieStats {
16    /// Return general trie stats.
17    pub const fn trie_stats(&self) -> TrieStats {
18        self.trie
19    }
20
21    /// The number of pre-computed storage roots.
22    pub const fn precomputed_storage_roots(&self) -> u64 {
23        self.precomputed_storage_roots
24    }
25
26    /// The number of added leaf nodes for which we did not precompute the storage root.
27    pub const fn missed_leaves(&self) -> u64 {
28        self.missed_leaves
29    }
30}
31
32/// Trie metrics tracker.
33#[derive(Deref, Default, Debug)]
34pub struct ParallelTrieTracker {
35    #[deref]
36    trie: TrieTracker,
37    precomputed_storage_roots: u64,
38    missed_leaves: u64,
39    #[cfg(feature = "metrics")]
40    /// Local tracking of cursor-related metrics
41    pub cursor_metrics: ProofTaskCursorMetricsCache,
42}
43
44impl ParallelTrieTracker {
45    /// Set the number of precomputed storage roots.
46    pub const fn set_precomputed_storage_roots(&mut self, count: u64) {
47        self.precomputed_storage_roots = count;
48    }
49
50    /// Increment the number of branches added to the hash builder during the calculation.
51    pub const fn inc_branch(&mut self) {
52        self.trie.inc_branch();
53    }
54
55    /// Increment the number of leaves added to the hash builder during the calculation.
56    pub const fn inc_leaf(&mut self) {
57        self.trie.inc_leaf();
58    }
59
60    /// Increment the number of added leaf nodes for which we did not precompute the storage root.
61    pub const fn inc_missed_leaves(&mut self) {
62        self.missed_leaves += 1;
63    }
64
65    /// Called when root calculation is finished to return trie statistics.
66    pub fn finish(self) -> ParallelTrieStats {
67        ParallelTrieStats {
68            trie: self.trie.finish(),
69            precomputed_storage_roots: self.precomputed_storage_roots,
70            missed_leaves: self.missed_leaves,
71        }
72    }
73}