reth_trie_parallel/
stats.rs

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