Skip to content

Commit

Permalink
feat(tree): --engine.state-root-task-compare-updates (#13763)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin authored Jan 10, 2025
1 parent 69f9e16 commit c601712
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
9 changes: 8 additions & 1 deletion bin/reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand All @@ -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::<EthereumNode, BlockchainProvider<_>>()
.with_components(EthereumNode::components())
Expand Down
3 changes: 3 additions & 0 deletions book/cli/reth/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <FORMAT>
The format to use for logs written to stdout
Expand Down
22 changes: 22 additions & 0 deletions crates/engine/tree/src/tree/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand All @@ -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,
Expand All @@ -75,6 +80,7 @@ impl TreeConfig {
max_invalid_header_cache_length,
max_execute_block_batch_size,
use_state_root_task,
always_compare_trie_updates,
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}
9 changes: 7 additions & 2 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;

Expand Down

0 comments on commit c601712

Please sign in to comment.