From b3bd69b224f005ba09a036c6ed794bcfa7639704 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin <5773434+shekhirin@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:26:34 +0000 Subject: [PATCH] feat(root): metrics and logs for state root config (#14631) --- crates/engine/tree/src/tree/root.rs | 66 +++++++++++++++++++++++++++++ crates/trie/common/src/updates.rs | 3 +- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/crates/engine/tree/src/tree/root.rs b/crates/engine/tree/src/tree/root.rs index 206992f55..fceaab9c2 100644 --- a/crates/engine/tree/src/tree/root.rs +++ b/crates/engine/tree/src/tree/root.rs @@ -497,6 +497,25 @@ struct StateRootTaskMetrics { pub proofs_processed_histogram: Histogram, /// Histogram of state root update iterations. pub state_root_iterations_histogram: Histogram, + + /// Histogram of the number of updated state nodes. + pub nodes_sorted_account_nodes_histogram: Histogram, + /// Histogram of the number of emoved state nodes. + pub nodes_sorted_removed_nodes_histogram: Histogram, + /// Histogram of the number of storage tries. + pub nodes_sorted_storage_tries_histogram: Histogram, + + /// Histogram of the number of updated state of accounts. + pub state_sorted_accounts_histogram: Histogram, + /// Histogram of the number of hashed storages. + pub state_sorted_storages_histogram: Histogram, + + /// Histogram of the number of account prefixes that have changed. + pub prefix_sets_accounts_histogram: Histogram, + /// Histogram of the number of storage prefixes that have changed. + pub prefix_sets_storages_histogram: Histogram, + /// Histogram of the number of destroyed accounts. + pub prefix_sets_destroyed_accounts_histogram: Histogram, } /// Standalone task that receives a transaction state stream and updates relevant @@ -584,6 +603,8 @@ where .spawn(move || { debug!(target: "engine::tree", "State root task starting"); + self.observe_config(); + let result = self.run(sparse_trie_tx); let _ = tx.send(result); }) @@ -592,6 +613,51 @@ where StateRootHandle::new(rx) } + /// Logs and records in metrics the state root config parameters. + fn observe_config(&self) { + let nodes_sorted_account_nodes = self.config.nodes_sorted.account_nodes.len(); + let nodes_sorted_removed_nodes = self.config.nodes_sorted.removed_nodes.len(); + let nodes_sorted_storage_tries = self.config.nodes_sorted.storage_tries.len(); + let state_sorted_accounts = self.config.state_sorted.accounts.accounts.len(); + let state_sorted_destroyed_accounts = + self.config.state_sorted.accounts.destroyed_accounts.len(); + let state_sorted_storages = self.config.state_sorted.storages.len(); + let prefix_sets_accounts = self.config.prefix_sets.account_prefix_set.len(); + let prefix_sets_storages = self + .config + .prefix_sets + .storage_prefix_sets + .values() + .map(|set| set.len()) + .sum::(); + let prefix_sets_destroyed_accounts = self.config.prefix_sets.destroyed_accounts.len(); + + debug!( + target: "engine::tree", + ?nodes_sorted_account_nodes, + ?nodes_sorted_removed_nodes, + ?nodes_sorted_storage_tries, + ?state_sorted_accounts, + ?state_sorted_destroyed_accounts, + ?state_sorted_storages, + ?prefix_sets_accounts, + ?prefix_sets_storages, + ?prefix_sets_destroyed_accounts, + "State root config" + ); + + self.metrics.nodes_sorted_account_nodes_histogram.record(nodes_sorted_account_nodes as f64); + self.metrics.nodes_sorted_removed_nodes_histogram.record(nodes_sorted_removed_nodes as f64); + self.metrics.nodes_sorted_storage_tries_histogram.record(nodes_sorted_storage_tries as f64); + self.metrics.state_sorted_accounts_histogram.record(state_sorted_accounts as f64); + self.metrics.state_sorted_storages_histogram.record(state_sorted_storages as f64); + self.metrics.prefix_sets_accounts_histogram.record(prefix_sets_accounts as f64); + self.metrics.prefix_sets_storages_histogram.record(prefix_sets_storages as f64); + self.metrics + .prefix_sets_destroyed_accounts_histogram + .record(prefix_sets_destroyed_accounts as f64); + } + /// Spawn long running sparse trie task that forwards the final result upon completion. fn spawn_sparse_trie( thread_pool: Arc, diff --git a/crates/trie/common/src/updates.rs b/crates/trie/common/src/updates.rs index f7506df9a..ed1091196 100644 --- a/crates/trie/common/src/updates.rs +++ b/crates/trie/common/src/updates.rs @@ -357,8 +357,7 @@ pub struct TrieUpdatesSorted { pub account_nodes: Vec<(Nibbles, BranchNodeCompact)>, /// The set of removed state node keys. pub removed_nodes: HashSet, - /// Storage tries storage stored by hashed address of the account - /// the trie belongs to. + /// Storage tries stored by hashed address of the account the trie belongs to. pub storage_tries: B256Map, }