Skip to content

Commit 20bbdd7

Browse files
startup-dreamerklkvrmattsse
authored
Chore: move tree config from engine-tree to engine-primitives (paradigmxyz#14890)
Co-authored-by: Arsenii Kulikov <[email protected]> Co-authored-by: Matthias Seitz <[email protected]>
1 parent f5dddff commit 20bbdd7

File tree

10 files changed

+52
-55
lines changed

10 files changed

+52
-55
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/engine/tree/src/tree/config.rs renamed to crates/engine/primitives/src/config.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
//! Engine tree configuration.
22
3-
use crate::tree::payload_processor::executor::has_enough_parallelism;
4-
use alloy_eips::merge::EPOCH_SLOTS;
5-
6-
/// The largest gap for which the tree will be used for sync. See docs for `pipeline_run_threshold`
7-
/// for more information.
8-
///
9-
/// This is the default threshold, the distance to the head that the tree will be used for sync.
10-
/// If the distance exceeds this threshold, the pipeline will be used for sync.
11-
pub(crate) const MIN_BLOCKS_FOR_PIPELINE_RUN: u64 = EPOCH_SLOTS;
12-
133
/// Triggers persistence when the number of canonical blocks in memory exceeds this threshold.
144
pub const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 2;
155

@@ -18,11 +8,26 @@ pub const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 2;
188

199
const DEFAULT_BLOCK_BUFFER_LIMIT: u32 = 256;
2010
const DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH: u32 = 256;
21-
2211
const DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE: usize = 4;
23-
2412
const DEFAULT_CROSS_BLOCK_CACHE_SIZE: u64 = 4 * 1024 * 1024 * 1024;
2513

14+
/// Determines if the host has enough parallelism to run the payload processor.
15+
///
16+
/// It requires at least 5 parallel threads:
17+
/// - Engine in main thread that spawns the state root task.
18+
/// - Multiproof task in payload processor
19+
/// - Sparse Trie task in payload processor
20+
/// - Multiproof computation spawned in payload processor
21+
/// - Storage root computation spawned in trie parallel proof
22+
pub fn has_enough_parallelism() -> bool {
23+
#[cfg(feature = "std")]
24+
{
25+
std::thread::available_parallelism().is_ok_and(|num| num.get() >= 5)
26+
}
27+
#[cfg(not(feature = "std"))]
28+
false
29+
}
30+
2631
/// The configuration of the engine tree.
2732
#[derive(Debug)]
2833
pub struct TreeConfig {
@@ -77,7 +82,7 @@ impl Default for TreeConfig {
7782

7883
impl TreeConfig {
7984
/// Create engine tree configuration.
80-
#[allow(clippy::too_many_arguments)]
85+
#[expect(clippy::too_many_arguments)]
8186
pub const fn new(
8287
persistence_threshold: u64,
8388
memory_block_buffer_target: u64,
@@ -225,7 +230,7 @@ impl TreeConfig {
225230
}
226231

227232
/// Whether or not to use state root task
228-
pub(crate) fn use_state_root_task(&self) -> bool {
233+
pub fn use_state_root_task(&self) -> bool {
229234
self.has_enough_parallelism && !self.legacy_state_root
230235
}
231236
}

crates/engine/primitives/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ pub use event::*;
4141
mod invalid_block_hook;
4242
pub use invalid_block_hook::InvalidBlockHook;
4343

44+
pub mod config;
45+
pub use config::*;
46+
4447
/// This type defines the versioned types of the engine API.
4548
///
4649
/// This includes the execution payload types and payload attributes that are used to trigger a

crates/engine/tree/src/tree/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
},
99
};
1010
use alloy_consensus::BlockHeader;
11-
use alloy_eips::BlockNumHash;
11+
use alloy_eips::{merge::EPOCH_SLOTS, BlockNumHash};
1212
use alloy_primitives::{
1313
map::{HashMap, HashSet},
1414
BlockNumber, B256, U256,
@@ -66,7 +66,6 @@ use tracing::*;
6666

6767
mod block_buffer;
6868
mod cached_state;
69-
pub mod config;
7069
pub mod error;
7170
mod invalid_block_hook;
7271
mod invalid_headers;
@@ -77,13 +76,20 @@ mod persistence_state;
7776
#[allow(unused)]
7877
mod trie_updates;
7978

80-
use crate::tree::{config::MIN_BLOCKS_FOR_PIPELINE_RUN, error::AdvancePersistenceError};
79+
use crate::tree::error::AdvancePersistenceError;
8180
pub use block_buffer::BlockBuffer;
82-
pub use config::TreeConfig;
8381
pub use invalid_block_hook::{InvalidBlockHooks, NoopInvalidBlockHook};
8482
pub use invalid_headers::InvalidHeaderCache;
8583
pub use payload_processor::*;
8684
pub use persistence_state::PersistenceState;
85+
pub use reth_engine_primitives::TreeConfig;
86+
87+
/// The largest gap for which the tree will be used for sync. See docs for `pipeline_run_threshold`
88+
/// for more information.
89+
///
90+
/// This is the default threshold, the distance to the head that the tree will be used for sync.
91+
/// If the distance exceeds this threshold, the pipeline will be used for sync.
92+
pub(crate) const MIN_BLOCKS_FOR_PIPELINE_RUN: u64 = EPOCH_SLOTS;
8793

8894
/// Keeps track of the state of the tree.
8995
///

crates/engine/tree/src/tree/payload_processor/executor.rs

-12
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,3 @@ impl WorkloadExecutorInner {
7777
Self { handle: get_runtime_handle(), rayon_pool: Arc::new(rayon_pool) }
7878
}
7979
}
80-
81-
/// Determines if the host has enough parallelism to run the payload processor.
82-
///
83-
/// It requires at least 5 parallel threads:
84-
/// - Engine in main thread that spawns the state root task.
85-
/// - Multiproof task in [`super::multiproof::MultiProofTask::run`]
86-
/// - Sparse Trie task in [`super::sparse_trie::SparseTrieTask::run`]
87-
/// - Multiproof computation spawned in [`super::multiproof::MultiproofManager::spawn_multiproof`]
88-
/// - Storage root computation spawned in [`reth_trie_parallel::proof::ParallelProof::multiproof`]
89-
pub(crate) fn has_enough_parallelism() -> bool {
90-
std::thread::available_parallelism().is_ok_and(|num| num.get() >= 5)
91-
}

crates/node/builder/src/builder/mod.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use futures::Future;
1414
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
1515
use reth_cli_util::get_secret_key;
1616
use reth_db_api::{database::Database, database_metrics::DatabaseMetrics};
17-
use reth_engine_tree::tree::TreeConfig;
1817
use reth_exex::ExExContext;
1918
use reth_network::{
2019
transactions::TransactionsManagerConfig, NetworkBuilder, NetworkConfig, NetworkConfigBuilder,
@@ -551,15 +550,7 @@ where
551550
{
552551
let Self { builder, task_executor } = self;
553552

554-
let engine_tree_config = TreeConfig::default()
555-
.with_persistence_threshold(builder.config.engine.persistence_threshold)
556-
.with_memory_block_buffer_target(builder.config.engine.memory_block_buffer_target)
557-
.with_legacy_state_root(builder.config.engine.legacy_state_root_task_enabled)
558-
.with_caching_and_prewarming(builder.config.engine.caching_and_prewarming_enabled)
559-
.with_always_compare_trie_updates(builder.config.engine.state_root_task_compare_updates)
560-
.with_cross_block_cache_size(
561-
builder.config.engine.cross_block_cache_size * 1024 * 1024,
562-
);
553+
let engine_tree_config = builder.config.engine.tree_config();
563554

564555
let launcher =
565556
EngineNodeLauncher::new(task_executor, builder.config.datadir(), engine_tree_config);
@@ -579,15 +570,7 @@ where
579570
{
580571
let Self { builder, task_executor } = self;
581572

582-
let engine_tree_config = TreeConfig::default()
583-
.with_persistence_threshold(builder.config.engine.persistence_threshold)
584-
.with_memory_block_buffer_target(builder.config.engine.memory_block_buffer_target)
585-
.with_legacy_state_root(builder.config.engine.legacy_state_root_task_enabled)
586-
.with_caching_and_prewarming(builder.config.engine.caching_and_prewarming_enabled)
587-
.with_always_compare_trie_updates(builder.config.engine.state_root_task_compare_updates)
588-
.with_cross_block_cache_size(
589-
builder.config.engine.cross_block_cache_size * 1024 * 1024,
590-
);
573+
let engine_tree_config = builder.config.engine.tree_config();
591574

592575
let launcher = DebugNodeLauncher::new(EngineNodeLauncher::new(
593576
task_executor,

crates/node/builder/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ pub use launch::{
3232
*,
3333
};
3434

35-
/// Temporarily re-export engine tree config.
36-
pub use reth_engine_tree::tree::config as engine_tree_config;
37-
3835
mod handle;
3936
pub use handle::NodeHandle;
4037

crates/node/core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ reth-network-peers.workspace = true
3535
reth-prune-types.workspace = true
3636
reth-stages-types.workspace = true
3737
reth-ethereum-forks.workspace = true
38+
reth-engine-primitives.workspace = true
3839

3940
# ethereum
4041
alloy-primitives.workspace = true

crates/node/core/src/args/engine.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! clap [Args](clap::Args) for engine purposes
22
33
use clap::Args;
4+
use reth_engine_primitives::TreeConfig;
45

56
use crate::node_config::{
67
DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB, DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
@@ -50,6 +51,19 @@ impl Default for EngineArgs {
5051
}
5152
}
5253

54+
impl EngineArgs {
55+
/// Creates a [`TreeConfig`] from the engine arguments.
56+
pub fn tree_config(&self) -> TreeConfig {
57+
TreeConfig::default()
58+
.with_persistence_threshold(self.persistence_threshold)
59+
.with_memory_block_buffer_target(self.memory_block_buffer_target)
60+
.with_legacy_state_root(self.legacy_state_root_task_enabled)
61+
.with_caching_and_prewarming(self.caching_and_prewarming_enabled)
62+
.with_always_compare_trie_updates(self.state_root_task_compare_updates)
63+
.with_cross_block_cache_size(self.cross_block_cache_size * 1024 * 1024)
64+
}
65+
}
66+
5367
#[cfg(test)]
5468
mod tests {
5569
use super::*;

crates/node/core/src/node_config.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ use std::{
3131
};
3232
use tracing::*;
3333

34+
pub use reth_engine_primitives::DEFAULT_MEMORY_BLOCK_BUFFER_TARGET;
35+
3436
/// Triggers persistence when the number of canonical blocks in memory exceeds this threshold.
3537
pub const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 2;
3638

37-
/// How close to the canonical head we persist blocks.
38-
pub const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 2;
39-
4039
/// Default size of cross-block cache in megabytes.
4140
pub const DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB: u64 = 4 * 1024;
4241

0 commit comments

Comments
 (0)