From c601712147e8e03e227e332c51f9b2454946fe35 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin <5773434+shekhirin@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:30:50 +0000 Subject: [PATCH] feat(tree): --engine.state-root-task-compare-updates (#13763) --- bin/reth/src/main.rs | 9 ++++++++- book/cli/reth/node.md | 3 +++ crates/engine/tree/src/tree/config.rs | 22 ++++++++++++++++++++++ crates/engine/tree/src/tree/mod.rs | 9 +++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/bin/reth/src/main.rs b/bin/reth/src/main.rs index 5daaa93ee3bf..b263f03a3f79 100644 --- a/bin/reth/src/main.rs +++ b/bin/reth/src/main.rs @@ -43,6 +43,11 @@ pub struct EngineArgs { /// Enable state root task #[arg(long = "engine.state-root-task", conflicts_with = "legacy")] pub state_root_task_enabled: bool, + + /// Enable comparing trie updates from the state root task to the trie updates from the regular + /// state root calculation. + #[arg(long = "engine.state-root-task-compare-updates", conflicts_with = "legacy")] + pub state_root_task_compare_updates: bool, } impl Default for EngineArgs { @@ -53,6 +58,7 @@ impl Default for EngineArgs { persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD, memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, state_root_task_enabled: false, + state_root_task_compare_updates: false, } } } @@ -77,7 +83,8 @@ fn main() { let engine_tree_config = TreeConfig::default() .with_persistence_threshold(engine_args.persistence_threshold) .with_memory_block_buffer_target(engine_args.memory_block_buffer_target) - .with_state_root_task(engine_args.state_root_task_enabled); + .with_state_root_task(engine_args.state_root_task_enabled) + .with_always_compare_trie_updates(engine_args.state_root_task_compare_updates); let handle = builder .with_types_and_provider::>() .with_components(EthereumNode::components()) diff --git a/book/cli/reth/node.md b/book/cli/reth/node.md index c07585c44725..66a04a1dbf89 100644 --- a/book/cli/reth/node.md +++ b/book/cli/reth/node.md @@ -703,6 +703,9 @@ Engine: --engine.state-root-task Enable state root task + --engine.state-root-task-compare-updates + Enable comparing trie updates from the state root task to the trie updates from the regular state root calculation + Logging: --log.stdout.format The format to use for logs written to stdout diff --git a/crates/engine/tree/src/tree/config.rs b/crates/engine/tree/src/tree/config.rs index c0c68799aee0..cec8bb4e8f06 100644 --- a/crates/engine/tree/src/tree/config.rs +++ b/crates/engine/tree/src/tree/config.rs @@ -43,6 +43,9 @@ pub struct TreeConfig { max_execute_block_batch_size: usize, /// Whether to use the new state root task calculation method instead of parallel calculation use_state_root_task: bool, + /// Whether to always compare trie updates from the state root task to the trie updates from + /// the regular state root calculation. + always_compare_trie_updates: bool, } impl Default for TreeConfig { @@ -54,6 +57,7 @@ impl Default for TreeConfig { max_invalid_header_cache_length: DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH, max_execute_block_batch_size: DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE, use_state_root_task: false, + always_compare_trie_updates: false, } } } @@ -67,6 +71,7 @@ impl TreeConfig { max_invalid_header_cache_length: u32, max_execute_block_batch_size: usize, use_state_root_task: bool, + always_compare_trie_updates: bool, ) -> Self { Self { persistence_threshold, @@ -75,6 +80,7 @@ impl TreeConfig { max_invalid_header_cache_length, max_execute_block_batch_size, use_state_root_task, + always_compare_trie_updates, } } @@ -108,6 +114,12 @@ impl TreeConfig { self.use_state_root_task } + /// Returns whether to always compare trie updates from the state root task to the trie updates + /// from the regular state root calculation. + pub const fn always_compare_trie_updates(&self) -> bool { + self.always_compare_trie_updates + } + /// Setter for persistence threshold. pub const fn with_persistence_threshold(mut self, persistence_threshold: u64) -> Self { self.persistence_threshold = persistence_threshold; @@ -152,4 +164,14 @@ impl TreeConfig { self.use_state_root_task = use_state_root_task; self } + + /// Setter for whether to always compare trie updates from the state root task to the trie + /// updates from the regular state root calculation. + pub const fn with_always_compare_trie_updates( + mut self, + always_compare_trie_updates: bool, + ) -> Self { + self.always_compare_trie_updates = always_compare_trie_updates; + self + } } diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 429dda7283cb..70dd46fb4bdc 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -2372,8 +2372,13 @@ where "Task state root finished" ); - if task_state_root != block.header().state_root() { - debug!(target: "engine::tree", "Task state root does not match block state root"); + if task_state_root != block.header().state_root() || + self.config.always_compare_trie_updates() + { + if task_state_root != block.header().state_root() { + debug!(target: "engine::tree", "Task state root does not match block state root"); + } + let (regular_root, regular_updates) = state_provider.state_root_with_updates(hashed_state.clone())?;