mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(bin, engine): make state root task default (#14371)
This commit is contained in:
@ -43,8 +43,9 @@ pub struct TreeConfig {
|
||||
/// This is used as a cutoff to prevent long-running sequential block execution when we receive
|
||||
/// a batch of downloaded blocks.
|
||||
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 use the legacy state root calculation method instead of the
|
||||
/// new state root task
|
||||
legacy_state_root: 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,
|
||||
@ -62,7 +63,7 @@ impl Default for TreeConfig {
|
||||
block_buffer_limit: DEFAULT_BLOCK_BUFFER_LIMIT,
|
||||
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,
|
||||
legacy_state_root: false,
|
||||
always_compare_trie_updates: false,
|
||||
use_caching_and_prewarming: false,
|
||||
cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE,
|
||||
@ -79,7 +80,7 @@ impl TreeConfig {
|
||||
block_buffer_limit: u32,
|
||||
max_invalid_header_cache_length: u32,
|
||||
max_execute_block_batch_size: usize,
|
||||
use_state_root_task: bool,
|
||||
legacy_state_root: bool,
|
||||
always_compare_trie_updates: bool,
|
||||
use_caching_and_prewarming: bool,
|
||||
cross_block_cache_size: u64,
|
||||
@ -90,7 +91,7 @@ impl TreeConfig {
|
||||
block_buffer_limit,
|
||||
max_invalid_header_cache_length,
|
||||
max_execute_block_batch_size,
|
||||
use_state_root_task,
|
||||
legacy_state_root,
|
||||
always_compare_trie_updates,
|
||||
use_caching_and_prewarming,
|
||||
cross_block_cache_size,
|
||||
@ -122,9 +123,10 @@ impl TreeConfig {
|
||||
self.max_execute_block_batch_size
|
||||
}
|
||||
|
||||
/// Returns whether to use the state root task calculation method.
|
||||
pub const fn use_state_root_task(&self) -> bool {
|
||||
self.use_state_root_task
|
||||
/// Returns whether to use the legacy state root calculation method instead
|
||||
/// of the new state root task
|
||||
pub const fn legacy_state_root(&self) -> bool {
|
||||
self.legacy_state_root
|
||||
}
|
||||
|
||||
/// Returns whether or not cross-block caching and parallel prewarming should be used.
|
||||
@ -182,9 +184,9 @@ impl TreeConfig {
|
||||
self
|
||||
}
|
||||
|
||||
/// Setter for whether to use the new state root task calculation method.
|
||||
pub const fn with_state_root_task(mut self, use_state_root_task: bool) -> Self {
|
||||
self.use_state_root_task = use_state_root_task;
|
||||
/// Setter for whether to use the legacy state root calculation method.
|
||||
pub const fn with_legacy_state_root(mut self, legacy_state_root: bool) -> Self {
|
||||
self.legacy_state_root = legacy_state_root;
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@ -2420,7 +2420,7 @@ where
|
||||
let cancel_execution = ManualCancel::default();
|
||||
|
||||
let (state_root_handle, state_root_task_config, state_root_sender, state_hook) =
|
||||
if is_descendant_of_persisting_blocks && self.config.use_state_root_task() {
|
||||
if is_descendant_of_persisting_blocks && !self.config.legacy_state_root() {
|
||||
let consistent_view = ConsistentDbView::new_with_latest_tip(self.provider.clone())?;
|
||||
|
||||
// Compute trie input
|
||||
@ -2548,21 +2548,7 @@ where
|
||||
// a different database transaction per thread and it might end up with a
|
||||
// different view of the database.
|
||||
let (state_root, trie_output, root_elapsed) = if is_descendant_of_persisting_blocks {
|
||||
if self.config.use_state_root_task() {
|
||||
let state_root_handle = state_root_handle
|
||||
.expect("state root handle must exist if use_state_root_task is true");
|
||||
let state_root_config = state_root_task_config.expect("task config is present");
|
||||
|
||||
// Handle state root result from task using handle
|
||||
self.handle_state_root_result(
|
||||
state_root_handle,
|
||||
state_root_config,
|
||||
block.sealed_block(),
|
||||
&hashed_state,
|
||||
&state_provider,
|
||||
root_time,
|
||||
)?
|
||||
} else {
|
||||
if self.config.legacy_state_root() {
|
||||
match self.compute_state_root_parallel(block.header().parent_hash(), &hashed_state)
|
||||
{
|
||||
Ok(result) => {
|
||||
@ -2582,6 +2568,20 @@ where
|
||||
}
|
||||
Err(error) => return Err(InsertBlockErrorKind::Other(Box::new(error))),
|
||||
}
|
||||
} else {
|
||||
let state_root_handle = state_root_handle
|
||||
.expect("state root handle must exist if use_state_root_task is true");
|
||||
let state_root_config = state_root_task_config.expect("task config is present");
|
||||
|
||||
// Handle state root result from task using handle
|
||||
self.handle_state_root_result(
|
||||
state_root_handle,
|
||||
state_root_config,
|
||||
block.sealed_block(),
|
||||
&hashed_state,
|
||||
&state_provider,
|
||||
root_time,
|
||||
)?
|
||||
}
|
||||
} else {
|
||||
debug!(target: "engine::tree", block=?block_num_hash, ?is_descendant_of_persisting_blocks, "Failed to compute state root in parallel");
|
||||
@ -3341,7 +3341,8 @@ mod tests {
|
||||
persistence_handle,
|
||||
PersistenceState::default(),
|
||||
payload_builder,
|
||||
TreeConfig::default(),
|
||||
// TODO: fix tests for state root task https://github.com/paradigmxyz/reth/issues/14376
|
||||
TreeConfig::default().with_legacy_state_root(true),
|
||||
EngineApiKind::Ethereum,
|
||||
evm_config,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user