From f64aecfbc8452f60344a8adeb1b97bcd583a7d01 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Wed, 18 Sep 2024 20:24:01 +0200 Subject: [PATCH] feat(cli): expose tree engine persistence configuration (#10999) --- bin/reth/src/main.rs | 31 ++++++++++++++++++++++-- book/cli/reth/node.md | 10 ++++++++ crates/engine/tree/src/tree/config.rs | 4 +-- crates/engine/tree/src/tree/mod.rs | 2 +- crates/ethereum/node/tests/it/builder.rs | 6 ++++- crates/node/builder/src/launch/engine.rs | 16 +++++++++--- crates/node/builder/src/lib.rs | 3 +++ crates/optimism/bin/src/main.rs | 6 ++++- crates/optimism/node/src/args.rs | 29 +++++++++++++++++++++- 9 files changed, 95 insertions(+), 12 deletions(-) diff --git a/bin/reth/src/main.rs b/bin/reth/src/main.rs index 76b4713a3910..67a8919e27ae 100644 --- a/bin/reth/src/main.rs +++ b/bin/reth/src/main.rs @@ -5,17 +5,40 @@ static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::ne use clap::{Args, Parser}; use reth::{args::utils::DefaultChainSpecParser, cli::Cli}; -use reth_node_builder::EngineNodeLauncher; +use reth_node_builder::{ + engine_tree_config::{ + TreeConfig, DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD, + }, + EngineNodeLauncher, +}; use reth_node_ethereum::{node::EthereumAddOns, EthereumNode}; use reth_provider::providers::BlockchainProvider2; /// Parameters for configuring the engine -#[derive(Debug, Clone, Args, PartialEq, Eq, Default)] +#[derive(Debug, Clone, Args, PartialEq, Eq)] #[command(next_help_heading = "Engine")] pub struct EngineArgs { /// Enable the engine2 experimental features on reth binary #[arg(long = "engine.experimental", default_value = "false")] pub experimental: bool, + + /// Configure persistence threshold for engine experimental. + #[arg(long = "engine.persistence-threshold", requires = "experimental", default_value_t = DEFAULT_PERSISTENCE_THRESHOLD)] + pub persistence_threshold: u64, + + /// Configure the target number of blocks to keep in memory. + #[arg(long = "engine.memory-block-buffer-target", requires = "experimental", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)] + pub memory_block_buffer_target: u64, +} + +impl Default for EngineArgs { + fn default() -> Self { + Self { + experimental: false, + persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD, + memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, + } + } } fn main() { @@ -31,6 +54,9 @@ fn main() { let enable_engine2 = engine_args.experimental; match enable_engine2 { true => { + let engine_tree_config = TreeConfig::default() + .with_persistence_threshold(engine_args.persistence_threshold) + .with_memory_block_buffer_target(engine_args.memory_block_buffer_target); let handle = builder .with_types_and_provider::>() .with_components(EthereumNode::components()) @@ -39,6 +65,7 @@ fn main() { let launcher = EngineNodeLauncher::new( builder.task_executor().clone(), builder.config().datadir(), + engine_tree_config, ); builder.launch_with(launcher) }) diff --git a/book/cli/reth/node.md b/book/cli/reth/node.md index f5bdf582173c..3ae086d38fe2 100644 --- a/book/cli/reth/node.md +++ b/book/cli/reth/node.md @@ -665,6 +665,16 @@ Engine: --engine.experimental Enable the engine2 experimental features on reth binary + --engine.persistence-threshold + Configure persistence threshold for engine experimental + + [default: 2] + + --engine.memory-block-buffer-target + Configure the target number of blocks to keep in memory + + [default: 2] + Logging: --log.stdout.format The format to use for logs written to stdout diff --git a/crates/engine/tree/src/tree/config.rs b/crates/engine/tree/src/tree/config.rs index 9d93660c8378..d252b65a8df5 100644 --- a/crates/engine/tree/src/tree/config.rs +++ b/crates/engine/tree/src/tree/config.rs @@ -1,10 +1,10 @@ //! Engine tree configuration. /// Triggers persistence when the number of canonical blocks in memory exceeds this threshold. -const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 2; +pub const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 2; /// How close to the canonical head we persist blocks. -const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 2; +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; diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index a4f622803083..025575eaa064 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -60,7 +60,7 @@ use tokio::sync::{ }; use tracing::*; -mod config; +pub mod config; mod invalid_block_hook; mod metrics; use crate::{engine::EngineApiRequest, tree::metrics::EngineApiMetrics}; diff --git a/crates/ethereum/node/tests/it/builder.rs b/crates/ethereum/node/tests/it/builder.rs index 4041c9766af5..379f66e814b6 100644 --- a/crates/ethereum/node/tests/it/builder.rs +++ b/crates/ethereum/node/tests/it/builder.rs @@ -56,7 +56,11 @@ async fn test_eth_launcher() { .with_components(EthereumNode::components()) .with_add_ons::() .launch_with_fn(|builder| { - let launcher = EngineNodeLauncher::new(tasks.executor(), builder.config.datadir()); + let launcher = EngineNodeLauncher::new( + tasks.executor(), + builder.config.datadir(), + Default::default(), + ); builder.launch_with(launcher) }); } diff --git a/crates/node/builder/src/launch/engine.rs b/crates/node/builder/src/launch/engine.rs index b3665395128a..474635569f1d 100644 --- a/crates/node/builder/src/launch/engine.rs +++ b/crates/node/builder/src/launch/engine.rs @@ -54,12 +54,20 @@ use crate::{ pub struct EngineNodeLauncher { /// The task executor for the node. pub ctx: LaunchContext, + + /// Temporary configuration for engine tree. + /// After engine is stabilized, this should be configured through node builder. + pub engine_tree_config: TreeConfig, } impl EngineNodeLauncher { /// Create a new instance of the ethereum node launcher. - pub const fn new(task_executor: TaskExecutor, data_dir: ChainPath) -> Self { - Self { ctx: LaunchContext::new(task_executor, data_dir) } + pub const fn new( + task_executor: TaskExecutor, + data_dir: ChainPath, + engine_tree_config: TreeConfig, + ) -> Self { + Self { ctx: LaunchContext::new(task_executor, data_dir), engine_tree_config } } } @@ -85,7 +93,7 @@ where self, target: NodeBuilderWithComponents, ) -> eyre::Result { - let Self { ctx } = self; + let Self { ctx, engine_tree_config } = self; let NodeBuilderWithComponents { adapter: NodeTypesAdapter { database }, components_builder, @@ -221,7 +229,7 @@ where ctx.blockchain_db().clone(), pruner, ctx.components().payload_builder().clone(), - TreeConfig::default(), + engine_tree_config, ctx.invalid_block_hook()?, ctx.sync_metrics_tx(), ); diff --git a/crates/node/builder/src/lib.rs b/crates/node/builder/src/lib.rs index e9191f04a666..cfe16074a59d 100644 --- a/crates/node/builder/src/lib.rs +++ b/crates/node/builder/src/lib.rs @@ -28,6 +28,9 @@ pub use builder::{ mod launch; pub use launch::{engine::EngineNodeLauncher, *}; +/// Temporarily re-export engine tree config. +pub use reth_engine_tree::tree::config as engine_tree_config; + mod handle; pub use handle::NodeHandle; diff --git a/crates/optimism/bin/src/main.rs b/crates/optimism/bin/src/main.rs index 238b5aeaaf0a..f5a88798a06b 100644 --- a/crates/optimism/bin/src/main.rs +++ b/crates/optimism/bin/src/main.rs @@ -4,7 +4,7 @@ #![cfg(feature = "optimism")] use clap::Parser; -use reth_node_builder::EngineNodeLauncher; +use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher}; use reth_node_optimism::{args::RollupArgs, node::OptimismAddOns, OptimismNode}; use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli}; use reth_optimism_rpc::SequencerClient; @@ -27,6 +27,9 @@ fn main() { let sequencer_http_arg = rollup_args.sequencer_http.clone(); match enable_engine2 { true => { + let engine_tree_config = TreeConfig::default() + .with_persistence_threshold(rollup_args.persistence_threshold) + .with_memory_block_buffer_target(rollup_args.memory_block_buffer_target); let handle = builder .with_types_and_provider::>() .with_components(OptimismNode::components(rollup_args)) @@ -45,6 +48,7 @@ fn main() { let launcher = EngineNodeLauncher::new( builder.task_executor().clone(), builder.config().datadir(), + engine_tree_config, ); builder.launch_with(launcher) }) diff --git a/crates/optimism/node/src/args.rs b/crates/optimism/node/src/args.rs index 30f309656c4c..54be83dc5101 100644 --- a/crates/optimism/node/src/args.rs +++ b/crates/optimism/node/src/args.rs @@ -2,8 +2,12 @@ //! clap [Args](clap::Args) for optimism rollup configuration +use reth_node_builder::engine_tree_config::{ + DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD, +}; + /// Parameters for rollup configuration -#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)] +#[derive(Debug, Clone, PartialEq, Eq, clap::Args)] #[command(next_help_heading = "Rollup")] pub struct RollupArgs { /// HTTP endpoint for the sequencer mempool @@ -37,6 +41,29 @@ pub struct RollupArgs { /// Enable the engine2 experimental features on op-reth binary #[arg(long = "engine.experimental", default_value = "false")] pub experimental: bool, + + /// Configure persistence threshold for engine experimental. + #[arg(long = "engine.persistence-threshold", requires = "experimental", default_value_t = DEFAULT_PERSISTENCE_THRESHOLD)] + pub persistence_threshold: u64, + + /// Configure the target number of blocks to keep in memory. + #[arg(long = "engine.memory-block-buffer-target", requires = "experimental", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)] + pub memory_block_buffer_target: u64, +} + +impl Default for RollupArgs { + fn default() -> Self { + Self { + sequencer_http: None, + disable_txpool_gossip: false, + enable_genesis_walkback: false, + compute_pending_block: false, + discovery_v4: false, + experimental: false, + persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD, + memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, + } + } } #[cfg(test)]