Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 0 additions & 16 deletions crates/trie/sparse-parallel/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 0 additions & 25 deletions crates/trie/sparse-parallel/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<usize>()
}

fn value_capacity(&self) -> usize {
self.upper_subtrie.value_capacity() +
self.lower_subtries.iter().map(|trie| trie.value_capacity()).sum::<usize>()
}

fn shrink_nodes_to(&mut self, size: usize) {
// Distribute the capacity across upper and lower subtries
//
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
37 changes: 6 additions & 31 deletions crates/trie/sparse/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}
Expand All @@ -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
Expand All @@ -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,
}
74 changes: 4 additions & 70 deletions crates/trie/sparse/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,17 +611,9 @@ where
&mut self,
provider_factory: impl TrieNodeProviderFactory,
) -> SparseStateTrieResult<B256> {
// 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())
}
Expand All @@ -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)?;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -957,46 +931,6 @@ impl<S: SparseTrieInterface + Clone> StorageTries<S> {
.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)]
Expand Down
6 changes: 0 additions & 6 deletions crates/trie/sparse/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 0 additions & 24 deletions crates/trie/sparse/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,6 @@ impl<T: SparseTrieInterface> SparseTrie<T> {
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) {
Expand Down Expand Up @@ -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);
Expand Down