Chore: move tree config from engine-tree to engine-primitives (#14890)

Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Sumit
2025-03-12 23:04:04 +05:30
committed by GitHub
parent f5dddffc7e
commit 20bbdd70b9
10 changed files with 52 additions and 55 deletions

View File

@@ -1,15 +1,5 @@
//! Engine tree configuration.
use crate::tree::payload_processor::executor::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`
/// for more information.
///
/// This is the default threshold, the distance to the head that the tree will be used for sync.
/// If the distance exceeds this threshold, the pipeline will be used for sync.
pub(crate) const MIN_BLOCKS_FOR_PIPELINE_RUN: u64 = EPOCH_SLOTS;
/// Triggers persistence when the number of canonical blocks in memory exceeds this threshold.
pub const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 2;
@@ -18,11 +8,26 @@ pub const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 2;
const DEFAULT_BLOCK_BUFFER_LIMIT: u32 = 256;
const DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH: u32 = 256;
const DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE: usize = 4;
const DEFAULT_CROSS_BLOCK_CACHE_SIZE: u64 = 4 * 1024 * 1024 * 1024;
/// Determines if the host has enough parallelism to run the payload processor.
///
/// It requires at least 5 parallel threads:
/// - Engine in main thread that spawns the state root task.
/// - Multiproof task in payload processor
/// - Sparse Trie task in payload processor
/// - Multiproof computation spawned in payload processor
/// - Storage root computation spawned in trie parallel proof
pub fn has_enough_parallelism() -> bool {
#[cfg(feature = "std")]
{
std::thread::available_parallelism().is_ok_and(|num| num.get() >= 5)
}
#[cfg(not(feature = "std"))]
false
}
/// The configuration of the engine tree.
#[derive(Debug)]
pub struct TreeConfig {
@@ -77,7 +82,7 @@ impl Default for TreeConfig {
impl TreeConfig {
/// Create engine tree configuration.
#[allow(clippy::too_many_arguments)]
#[expect(clippy::too_many_arguments)]
pub const fn new(
persistence_threshold: u64,
memory_block_buffer_target: u64,
@@ -225,7 +230,7 @@ impl TreeConfig {
}
/// Whether or not to use state root task
pub(crate) fn use_state_root_task(&self) -> bool {
pub fn use_state_root_task(&self) -> bool {
self.has_enough_parallelism && !self.legacy_state_root
}
}

View File

@@ -41,6 +41,9 @@ pub use event::*;
mod invalid_block_hook;
pub use invalid_block_hook::InvalidBlockHook;
pub mod config;
pub use config::*;
/// This type defines the versioned types of the engine API.
///
/// This includes the execution payload types and payload attributes that are used to trigger a

View File

@@ -8,7 +8,7 @@ use crate::{
},
};
use alloy_consensus::BlockHeader;
use alloy_eips::BlockNumHash;
use alloy_eips::{merge::EPOCH_SLOTS, BlockNumHash};
use alloy_primitives::{
map::{HashMap, HashSet},
BlockNumber, B256, U256,
@@ -66,7 +66,6 @@ use tracing::*;
mod block_buffer;
mod cached_state;
pub mod config;
pub mod error;
mod invalid_block_hook;
mod invalid_headers;
@@ -77,13 +76,20 @@ mod persistence_state;
#[allow(unused)]
mod trie_updates;
use crate::tree::{config::MIN_BLOCKS_FOR_PIPELINE_RUN, error::AdvancePersistenceError};
use crate::tree::error::AdvancePersistenceError;
pub use block_buffer::BlockBuffer;
pub use config::TreeConfig;
pub use invalid_block_hook::{InvalidBlockHooks, NoopInvalidBlockHook};
pub use invalid_headers::InvalidHeaderCache;
pub use payload_processor::*;
pub use persistence_state::PersistenceState;
pub use reth_engine_primitives::TreeConfig;
/// The largest gap for which the tree will be used for sync. See docs for `pipeline_run_threshold`
/// for more information.
///
/// This is the default threshold, the distance to the head that the tree will be used for sync.
/// If the distance exceeds this threshold, the pipeline will be used for sync.
pub(crate) const MIN_BLOCKS_FOR_PIPELINE_RUN: u64 = EPOCH_SLOTS;
/// Keeps track of the state of the tree.
///

View File

@@ -77,15 +77,3 @@ impl WorkloadExecutorInner {
Self { handle: get_runtime_handle(), rayon_pool: Arc::new(rayon_pool) }
}
}
/// Determines if the host has enough parallelism to run the payload processor.
///
/// It requires at least 5 parallel threads:
/// - Engine in main thread that spawns the state root task.
/// - Multiproof task in [`super::multiproof::MultiProofTask::run`]
/// - Sparse Trie task in [`super::sparse_trie::SparseTrieTask::run`]
/// - Multiproof computation spawned in [`super::multiproof::MultiproofManager::spawn_multiproof`]
/// - Storage root computation spawned in [`reth_trie_parallel::proof::ParallelProof::multiproof`]
pub(crate) fn has_enough_parallelism() -> bool {
std::thread::available_parallelism().is_ok_and(|num| num.get() >= 5)
}

View File

@@ -14,7 +14,6 @@ use futures::Future;
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
use reth_cli_util::get_secret_key;
use reth_db_api::{database::Database, database_metrics::DatabaseMetrics};
use reth_engine_tree::tree::TreeConfig;
use reth_exex::ExExContext;
use reth_network::{
transactions::TransactionsManagerConfig, NetworkBuilder, NetworkConfig, NetworkConfigBuilder,
@@ -551,15 +550,7 @@ where
{
let Self { builder, task_executor } = self;
let engine_tree_config = TreeConfig::default()
.with_persistence_threshold(builder.config.engine.persistence_threshold)
.with_memory_block_buffer_target(builder.config.engine.memory_block_buffer_target)
.with_legacy_state_root(builder.config.engine.legacy_state_root_task_enabled)
.with_caching_and_prewarming(builder.config.engine.caching_and_prewarming_enabled)
.with_always_compare_trie_updates(builder.config.engine.state_root_task_compare_updates)
.with_cross_block_cache_size(
builder.config.engine.cross_block_cache_size * 1024 * 1024,
);
let engine_tree_config = builder.config.engine.tree_config();
let launcher =
EngineNodeLauncher::new(task_executor, builder.config.datadir(), engine_tree_config);
@@ -579,15 +570,7 @@ where
{
let Self { builder, task_executor } = self;
let engine_tree_config = TreeConfig::default()
.with_persistence_threshold(builder.config.engine.persistence_threshold)
.with_memory_block_buffer_target(builder.config.engine.memory_block_buffer_target)
.with_legacy_state_root(builder.config.engine.legacy_state_root_task_enabled)
.with_caching_and_prewarming(builder.config.engine.caching_and_prewarming_enabled)
.with_always_compare_trie_updates(builder.config.engine.state_root_task_compare_updates)
.with_cross_block_cache_size(
builder.config.engine.cross_block_cache_size * 1024 * 1024,
);
let engine_tree_config = builder.config.engine.tree_config();
let launcher = DebugNodeLauncher::new(EngineNodeLauncher::new(
task_executor,

View File

@@ -32,9 +32,6 @@ pub use launch::{
*,
};
/// Temporarily re-export engine tree config.
pub use reth_engine_tree::tree::config as engine_tree_config;
mod handle;
pub use handle::NodeHandle;

View File

@@ -35,6 +35,7 @@ reth-network-peers.workspace = true
reth-prune-types.workspace = true
reth-stages-types.workspace = true
reth-ethereum-forks.workspace = true
reth-engine-primitives.workspace = true
# ethereum
alloy-primitives.workspace = true

View File

@@ -1,6 +1,7 @@
//! clap [Args](clap::Args) for engine purposes
use clap::Args;
use reth_engine_primitives::TreeConfig;
use crate::node_config::{
DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB, DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
@@ -50,6 +51,19 @@ impl Default for EngineArgs {
}
}
impl EngineArgs {
/// Creates a [`TreeConfig`] from the engine arguments.
pub fn tree_config(&self) -> TreeConfig {
TreeConfig::default()
.with_persistence_threshold(self.persistence_threshold)
.with_memory_block_buffer_target(self.memory_block_buffer_target)
.with_legacy_state_root(self.legacy_state_root_task_enabled)
.with_caching_and_prewarming(self.caching_and_prewarming_enabled)
.with_always_compare_trie_updates(self.state_root_task_compare_updates)
.with_cross_block_cache_size(self.cross_block_cache_size * 1024 * 1024)
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -31,12 +31,11 @@ use std::{
};
use tracing::*;
pub use reth_engine_primitives::DEFAULT_MEMORY_BLOCK_BUFFER_TARGET;
/// Triggers persistence when the number of canonical blocks in memory exceeds this threshold.
pub const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 2;
/// How close to the canonical head we persist blocks.
pub const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 2;
/// Default size of cross-block cache in megabytes.
pub const DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB: u64 = 4 * 1024;