diff --git a/crates/engine/tree/src/tree/payload_processor/configured_sparse_trie.rs b/crates/engine/tree/src/tree/payload_processor/configured_sparse_trie.rs index 9e8f787823a..b587a721398 100644 --- a/crates/engine/tree/src/tree/payload_processor/configured_sparse_trie.rs +++ b/crates/engine/tree/src/tree/payload_processor/configured_sparse_trie.rs @@ -172,21 +172,6 @@ impl SparseTrieInterface for ConfiguredSparseTrie { Self::Parallel(trie) => trie.updates_ref(), } } - - fn node_capacity(&self) -> usize { - match self { - Self::Serial(trie) => trie.node_capacity(), - Self::Parallel(trie) => trie.node_capacity(), - } - } - - fn value_capacity(&self) -> usize { - match self { - Self::Serial(trie) => trie.value_capacity(), - Self::Parallel(trie) => trie.value_capacity(), - } - } - fn shrink_nodes_to(&mut self, size: usize) { match self { Self::Serial(trie) => trie.shrink_nodes_to(size), diff --git a/crates/trie/sparse-parallel/src/lower.rs b/crates/trie/sparse-parallel/src/lower.rs index bc8ae006074..b7eceb133b8 100644 --- a/crates/trie/sparse-parallel/src/lower.rs +++ b/crates/trie/sparse-parallel/src/lower.rs @@ -107,22 +107,6 @@ impl LowerSparseSubtrie { } } - /// Returns the capacity of any maps containing trie nodes - pub(crate) fn node_capacity(&self) -> usize { - match self { - Self::Revealed(trie) | Self::Blind(Some(trie)) => trie.node_capacity(), - Self::Blind(None) => 0, - } - } - - /// Returns the capacity of any maps containing trie values - pub(crate) fn value_capacity(&self) -> usize { - match self { - Self::Revealed(trie) | Self::Blind(Some(trie)) => trie.value_capacity(), - Self::Blind(None) => 0, - } - } - /// Shrinks the capacity of the subtrie's node storage. /// Works for both revealed and blind tries with allocated storage. pub(crate) fn shrink_nodes_to(&mut self, size: usize) { diff --git a/crates/trie/sparse-parallel/src/trie.rs b/crates/trie/sparse-parallel/src/trie.rs index 34c1ff2a963..05f64477bac 100644 --- a/crates/trie/sparse-parallel/src/trie.rs +++ b/crates/trie/sparse-parallel/src/trie.rs @@ -874,16 +874,6 @@ impl SparseTrieInterface for ParallelSparseTrie { } } - fn node_capacity(&self) -> usize { - self.upper_subtrie.node_capacity() + - self.lower_subtries.iter().map(|trie| trie.node_capacity()).sum::() - } - - fn value_capacity(&self) -> usize { - self.upper_subtrie.value_capacity() + - self.lower_subtries.iter().map(|trie| trie.value_capacity()).sum::() - } - fn shrink_nodes_to(&mut self, size: usize) { // Distribute the capacity across upper and lower subtries // @@ -2138,16 +2128,6 @@ impl SparseSubtrie { self.inner.clear(); } - /// Returns the capacity of the map containing trie nodes. - pub(crate) fn node_capacity(&self) -> usize { - self.nodes.capacity() - } - - /// Returns the capacity of the map containing trie values. - pub(crate) fn value_capacity(&self) -> usize { - self.inner.value_capacity() - } - /// Shrinks the capacity of the subtrie's node storage. pub(crate) fn shrink_nodes_to(&mut self, size: usize) { self.nodes.shrink_to(size); @@ -2490,11 +2470,6 @@ impl SparseSubtrieInner { self.values.clear(); self.buffers.clear(); } - - /// Returns the capacity of the map storing leaf values - fn value_capacity(&self) -> usize { - self.values.capacity() - } } /// Represents the outcome of processing a node during leaf insertion diff --git a/crates/trie/sparse/src/metrics.rs b/crates/trie/sparse/src/metrics.rs index 3f39e6df6f9..8dc64ddc599 100644 --- a/crates/trie/sparse/src/metrics.rs +++ b/crates/trie/sparse/src/metrics.rs @@ -1,6 +1,5 @@ //! Metrics for the sparse state trie -use metrics::Gauge; use reth_metrics::{metrics::Histogram, Metrics}; /// Metrics for the sparse state trie @@ -16,24 +15,24 @@ pub(crate) struct SparseStateTrieMetrics { pub(crate) multiproof_skipped_storage_nodes: u64, /// Number of total storage nodes, including those that were skipped. pub(crate) multiproof_total_storage_nodes: u64, - /// The actual metrics we will record - pub(crate) inner_metrics: SparseStateTrieInnerMetrics, + /// The actual metrics we will record into the histogram + pub(crate) histograms: SparseStateTrieInnerMetrics, } impl SparseStateTrieMetrics { /// Record the metrics into the histograms pub(crate) fn record(&mut self) { use core::mem::take; - self.inner_metrics + self.histograms .multiproof_skipped_account_nodes .record(take(&mut self.multiproof_skipped_account_nodes) as f64); - self.inner_metrics + self.histograms .multiproof_total_account_nodes .record(take(&mut self.multiproof_total_account_nodes) as f64); - self.inner_metrics + self.histograms .multiproof_skipped_storage_nodes .record(take(&mut self.multiproof_skipped_storage_nodes) as f64); - self.inner_metrics + self.histograms .multiproof_total_storage_nodes .record(take(&mut self.multiproof_total_storage_nodes) as f64); } @@ -57,22 +56,6 @@ impl SparseStateTrieMetrics { pub(crate) const fn increment_total_storage_nodes(&mut self, count: u64) { self.multiproof_total_storage_nodes += count; } - - /// Set the value capacity for the sparse state trie - pub(crate) fn set_value_capacity(&self, capacity: usize) { - self.inner_metrics.value_capacity.set(capacity as f64); - } - - /// Set the node capacity for the sparse state trie - pub(crate) fn set_node_capacity(&self, capacity: usize) { - self.inner_metrics.node_capacity.set(capacity as f64); - } - - /// Set the number of cleared and active storage tries - pub(crate) fn set_storage_trie_metrics(&self, cleared: usize, active: usize) { - self.inner_metrics.cleared_storage_tries.set(cleared as f64); - self.inner_metrics.active_storage_tries.set(active as f64); - } } /// Metrics for the sparse state trie @@ -89,12 +72,4 @@ pub(crate) struct SparseStateTrieInnerMetrics { pub(crate) multiproof_skipped_storage_nodes: Histogram, /// Histogram of total storage nodes, including those that were skipped. pub(crate) multiproof_total_storage_nodes: Histogram, - /// Gauge for the trie's node capacity - pub(crate) node_capacity: Gauge, - /// Gauge for the trie's value capacity - pub(crate) value_capacity: Gauge, - /// The current number of cleared storage tries. - pub(crate) cleared_storage_tries: Gauge, - /// The number of currently active storage tries, i.e., not cleared - pub(crate) active_storage_tries: Gauge, } diff --git a/crates/trie/sparse/src/state.rs b/crates/trie/sparse/src/state.rs index a202ebc8b2b..20c4f2fe879 100644 --- a/crates/trie/sparse/src/state.rs +++ b/crates/trie/sparse/src/state.rs @@ -611,17 +611,9 @@ where &mut self, provider_factory: impl TrieNodeProviderFactory, ) -> SparseStateTrieResult { - // record revealed node metrics and capacity metrics + // record revealed node metrics #[cfg(feature = "metrics")] - { - self.metrics.record(); - self.metrics.set_node_capacity(self.node_capacity()); - self.metrics.set_value_capacity(self.value_capacity()); - self.metrics.set_storage_trie_metrics( - self.storage.cleared_tries.len(), - self.storage.tries.len(), - ); - } + self.metrics.record(); Ok(self.revealed_trie_mut(provider_factory)?.root()) } @@ -632,17 +624,9 @@ where &mut self, provider_factory: impl TrieNodeProviderFactory, ) -> SparseStateTrieResult<(B256, TrieUpdates)> { - // record revealed node metrics and capacity metrics + // record revealed node metrics #[cfg(feature = "metrics")] - { - self.metrics.record(); - self.metrics.set_node_capacity(self.node_capacity()); - self.metrics.set_value_capacity(self.value_capacity()); - self.metrics.set_storage_trie_metrics( - self.storage.cleared_tries.len(), - self.storage.tries.len(), - ); - } + self.metrics.record(); let storage_tries = self.storage_trie_updates(); let revealed = self.revealed_trie_mut(provider_factory)?; @@ -847,16 +831,6 @@ where storage_trie.remove_leaf(slot, provider)?; Ok(()) } - - /// The sum of the account trie's node capacity and the storage tries' node capacity - pub fn node_capacity(&self) -> usize { - self.state.node_capacity() + self.storage.total_node_capacity() - } - - /// The sum of the account trie's value capacity and the storage tries' value capacity - pub fn value_capacity(&self) -> usize { - self.state.value_capacity() + self.storage.total_value_capacity() - } } /// The fields of [`SparseStateTrie`] related to storage tries. This is kept separate from the rest @@ -957,46 +931,6 @@ impl StorageTries { .remove(account) .unwrap_or_else(|| self.cleared_revealed_paths.pop().unwrap_or_default()) } - - /// Sums the total node capacity in `cleared_tries` - fn total_cleared_tries_node_capacity(&self) -> usize { - self.cleared_tries.iter().map(|trie| trie.node_capacity()).sum() - } - - /// Sums the total value capacity in `cleared_tries` - fn total_cleared_tries_value_capacity(&self) -> usize { - self.cleared_tries.iter().map(|trie| trie.value_capacity()).sum() - } - - /// Calculates the sum of the active storage trie node capacity, ie the tries in `tries` - fn total_active_tries_node_capacity(&self) -> usize { - self.tries.values().map(|trie| trie.node_capacity()).sum() - } - - /// Calculates the sum of the active storage trie value capacity, ie the tries in `tries` - fn total_active_tries_value_capacity(&self) -> usize { - self.tries.values().map(|trie| trie.value_capacity()).sum() - } - - /// Calculates the sum of active and cleared storage trie node capacity, i.e. the sum of - /// * [`StorageTries::total_active_tries_node_capacity`], and - /// * [`StorageTries::total_cleared_tries_node_capacity`] - /// * the default trie's node capacity - fn total_node_capacity(&self) -> usize { - self.total_active_tries_node_capacity() + - self.total_cleared_tries_node_capacity() + - self.default_trie.node_capacity() - } - - /// Calculates the sum of active and cleared storage trie value capacity, i.e. the sum of - /// * [`StorageTries::total_active_tries_value_capacity`], and - /// * [`StorageTries::total_cleared_tries_value_capacity`], and - /// * the default trie's value capacity - fn total_value_capacity(&self) -> usize { - self.total_active_tries_value_capacity() + - self.total_cleared_tries_value_capacity() + - self.default_trie.value_capacity() - } } #[derive(Debug, PartialEq, Eq, Default)] diff --git a/crates/trie/sparse/src/traits.rs b/crates/trie/sparse/src/traits.rs index 5b7b6193f96..308695ec0fd 100644 --- a/crates/trie/sparse/src/traits.rs +++ b/crates/trie/sparse/src/traits.rs @@ -223,12 +223,6 @@ pub trait SparseTrieInterface: Sized + Debug + Send + Sync { /// This is useful for reusing the trie without needing to reallocate memory. fn clear(&mut self); - /// This returns the capacity of any inner data structures which store nodes. - fn node_capacity(&self) -> usize; - - /// This returns the capacity of any inner data structures which store leaf values. - fn value_capacity(&self) -> usize; - /// Shrink the capacity of the sparse trie's node storage to the given size. /// This will reduce memory usage if the current capacity is higher than the given size. fn shrink_nodes_to(&mut self, size: usize); diff --git a/crates/trie/sparse/src/trie.rs b/crates/trie/sparse/src/trie.rs index ab0506b9364..dbfed72ce09 100644 --- a/crates/trie/sparse/src/trie.rs +++ b/crates/trie/sparse/src/trie.rs @@ -260,22 +260,6 @@ impl SparseTrie { Ok(()) } - /// Returns the allocated capacity for sparse trie nodes. - pub fn node_capacity(&self) -> usize { - match self { - Self::Blind(Some(trie)) | Self::Revealed(trie) => trie.node_capacity(), - _ => 0, - } - } - - /// Returns the allocated capacity for sparse trie values. - pub fn value_capacity(&self) -> usize { - match self { - Self::Blind(Some(trie)) | Self::Revealed(trie) => trie.value_capacity(), - _ => 0, - } - } - /// Shrinks the capacity of the sparse trie's node storage. /// Works for both revealed and blind tries with allocated storage. pub fn shrink_nodes_to(&mut self, size: usize) { @@ -1103,14 +1087,6 @@ impl SparseTrieInterface for SerialSparseTrie { Ok(LeafLookup::NonExistent) } - fn node_capacity(&self) -> usize { - self.nodes.capacity() - } - - fn value_capacity(&self) -> usize { - self.values.capacity() - } - fn shrink_nodes_to(&mut self, size: usize) { self.nodes.shrink_to(size); self.branch_node_tree_masks.shrink_to(size);