Skip to content

Commit

Permalink
test(engine): enable state root task in engine unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed Feb 19, 2025
1 parent 465af6e commit e4e01f8
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 73 deletions.
7 changes: 5 additions & 2 deletions crates/engine/local/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use reth_engine_tree::{
RequestHandlerEvent,
},
persistence::PersistenceHandle,
tree::{EngineApiTreeHandler, InvalidBlockHook, TreeConfig},
tree::{root::BasicStateRootTaskFactory, EngineApiTreeHandler, InvalidBlockHook, TreeConfig},
};
use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm};
use reth_node_types::{BlockTy, HeaderTy, TxTy};
Expand Down Expand Up @@ -95,8 +95,10 @@ where
PersistenceHandle::<N::Primitives>::spawn_service(provider, pruner, sync_metrics_tx);
let canonical_in_memory_state = blockchain_db.canonical_in_memory_state();

let state_root_task_factory = BasicStateRootTaskFactory::new();

let (to_tree_tx, from_tree) =
EngineApiTreeHandler::<N::Primitives, _, _, _, _, _>::spawn_new(
EngineApiTreeHandler::<N::Primitives, _, _, _, _, _, _>::spawn_new(
blockchain_db.clone(),
executor_factory,
consensus,
Expand All @@ -108,6 +110,7 @@ where
invalid_block_hook,
engine_kind,
evm_config,
state_root_task_factory,
);

let handler = EngineApiRequestHandler::new(to_tree_tx, from_tree);
Expand Down
7 changes: 5 additions & 2 deletions crates/engine/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reth_engine_tree::{
download::BasicBlockDownloader,
engine::{EngineApiKind, EngineApiRequest, EngineApiRequestHandler, EngineHandler},
persistence::PersistenceHandle,
tree::{EngineApiTreeHandler, InvalidBlockHook, TreeConfig},
tree::{root::BasicStateRootTaskFactory, EngineApiTreeHandler, InvalidBlockHook, TreeConfig},
};
pub use reth_engine_tree::{
chain::{ChainEvent, ChainOrchestrator},
Expand Down Expand Up @@ -105,8 +105,10 @@ where

let canonical_in_memory_state = blockchain_db.canonical_in_memory_state();

let state_root_task_factory = BasicStateRootTaskFactory::new();

let (to_tree_tx, from_tree) =
EngineApiTreeHandler::<N::Primitives, _, _, _, _, _>::spawn_new(
EngineApiTreeHandler::<N::Primitives, _, _, _, _, _, _>::spawn_new(
blockchain_db,
executor_factory,
consensus,
Expand All @@ -118,6 +120,7 @@ where
invalid_block_hook,
engine_kind,
evm_config,
state_root_task_factory,
);

let engine_handler = EngineApiRequestHandler::new(to_tree_tx, from_tree);
Expand Down
17 changes: 17 additions & 0 deletions crates/engine/tree/src/tree/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Engine tree configuration.
use crate::tree::root::has_enough_parallelism;
use alloy_eips::merge::EPOCH_SLOTS;

/// The largest gap for which the tree will be used for sync. See docs for `pipeline_run_threshold`
Expand Down Expand Up @@ -53,6 +54,8 @@ pub struct TreeConfig {
use_caching_and_prewarming: bool,
/// Cross-block cache size in bytes.
cross_block_cache_size: u64,
/// Wether the host has enough parallelism to run state root task.
has_enough_parallelism: bool,
}

impl Default for TreeConfig {
Expand All @@ -67,6 +70,7 @@ impl Default for TreeConfig {
always_compare_trie_updates: false,
use_caching_and_prewarming: false,
cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE,
has_enough_parallelism: has_enough_parallelism(),
}
}
}
Expand All @@ -84,6 +88,7 @@ impl TreeConfig {
always_compare_trie_updates: bool,
use_caching_and_prewarming: bool,
cross_block_cache_size: u64,
has_enough_parallelism: bool,
) -> Self {
Self {
persistence_threshold,
Expand All @@ -95,6 +100,7 @@ impl TreeConfig {
always_compare_trie_updates,
use_caching_and_prewarming,
cross_block_cache_size,
has_enough_parallelism,
}
}

Expand Down Expand Up @@ -211,4 +217,15 @@ impl TreeConfig {
self.cross_block_cache_size = cross_block_cache_size;
self
}

/// Setter for has enough parallelism.
pub const fn with_has_enough_parallelism(mut self, has_enough_parallelism: bool) -> Self {
self.has_enough_parallelism = has_enough_parallelism;
self
}

/// Wether or not to use state root task
pub(crate) fn use_state_root_task(&self) -> bool {
self.has_enough_parallelism && !self.legacy_state_root
}
}
Loading

0 comments on commit e4e01f8

Please sign in to comment.