feat: integrate EngineArgs into NodeCommand (#13748)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Tien Nguyen
2025-01-12 00:27:11 +07:00
committed by GitHub
parent 6ef86e9340
commit 8e7768db2a
7 changed files with 99 additions and 124 deletions

View File

@ -10,7 +10,7 @@ use reth_ethereum_cli::chainspec::EthereumChainSpecParser;
use reth_node_builder::{NodeBuilder, WithLaunchContext};
use reth_node_core::{
args::{
DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs,
DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, EngineArgs, NetworkArgs, PayloadBuilderArgs,
PruningArgs, RpcServerArgs, TxPoolArgs,
},
node_config::NodeConfig,
@ -107,6 +107,10 @@ pub struct NodeCommand<
#[command(flatten)]
pub pruning: PruningArgs,
/// Engine cli arguments
#[command(flatten, next_help_heading = "Engine")]
pub engine: EngineArgs,
/// Additional cli arguments
#[command(flatten, next_help_heading = "Extension")]
pub ext: Ext,
@ -160,6 +164,7 @@ impl<
dev,
pruning,
ext,
engine,
} = self;
// set up node config
@ -177,6 +182,7 @@ impl<
db,
dev,
pruning,
engine,
};
let data_dir = node_config.datadir();

View File

@ -17,6 +17,7 @@ use reth_db_api::{
database::Database,
database_metrics::{DatabaseMetadata, DatabaseMetrics},
};
use reth_engine_tree::tree::TreeConfig;
use reth_exex::ExExContext;
use reth_network::{
transactions::TransactionsManagerConfig, NetworkBuilder, NetworkConfig, NetworkConfigBuilder,
@ -563,8 +564,16 @@ 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_state_root_task(builder.config.engine.state_root_task_enabled)
.with_always_compare_trie_updates(
builder.config.engine.state_root_task_compare_updates,
);
let launcher =
EngineNodeLauncher::new(task_executor, builder.config.datadir(), Default::default());
EngineNodeLauncher::new(task_executor, builder.config.datadir(), engine_tree_config);
builder.launch_with(launcher).await
}
}

View File

@ -0,0 +1,58 @@
//! clap [Args](clap::Args) for engine purposes
use clap::Args;
use crate::node_config::{DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD};
/// Parameters for configuring the engine driver.
#[derive(Debug, Clone, Args, PartialEq, Eq)]
#[command(next_help_heading = "Engine")]
pub struct EngineArgs {
/// Configure persistence threshold for engine experimental.
#[arg(long = "engine.persistence-threshold", 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", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)]
pub memory_block_buffer_target: u64,
/// Enable state root task
#[arg(long = "engine.state-root-task")]
pub state_root_task_enabled: bool,
/// Enable comparing trie updates from the state root task to the trie updates from the regular
/// state root calculation.
#[arg(long = "engine.state-root-task-compare-updates")]
pub state_root_task_compare_updates: bool,
}
impl Default for EngineArgs {
fn default() -> Self {
Self {
persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
state_root_task_enabled: false,
state_root_task_compare_updates: false,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
/// A helper type to parse Args more easily
#[derive(Parser)]
struct CommandParser<T: Args> {
#[command(flatten)]
args: T,
}
#[test]
fn test_parse_engine_args() {
let default_args = EngineArgs::default();
let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
assert_eq!(args, default_args);
}
}

View File

@ -56,5 +56,9 @@ pub use datadir_args::DatadirArgs;
mod benchmark_args;
pub use benchmark_args::BenchmarkArgs;
/// EngineArgs for configuring the engine
mod engine;
pub use engine::EngineArgs;
mod error;
pub mod types;

View File

@ -2,7 +2,7 @@
use crate::{
args::{
DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs,
DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, EngineArgs, NetworkArgs, PayloadBuilderArgs,
PruningArgs, RpcServerArgs, TxPoolArgs,
},
dirs::{ChainPath, DataDirPath},
@ -31,6 +31,12 @@ use std::{
};
use tracing::*;
/// 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;
/// This includes all necessary configuration to launch the node.
/// The individual configuration options can be overwritten before launching the node.
///
@ -133,6 +139,9 @@ pub struct NodeConfig<ChainSpec> {
/// All pruning related arguments
pub pruning: PruningArgs,
/// All engine related arguments
pub engine: EngineArgs,
}
impl NodeConfig<ChainSpec> {
@ -161,6 +170,7 @@ impl<ChainSpec> NodeConfig<ChainSpec> {
dev: DevArgs::default(),
pruning: PruningArgs::default(),
datadir: DatadirArgs::default(),
engine: EngineArgs::default(),
}
}
@ -449,6 +459,7 @@ impl<ChainSpec> NodeConfig<ChainSpec> {
db: self.db,
dev: self.dev,
pruning: self.pruning,
engine: self.engine,
}
}
}
@ -475,6 +486,7 @@ impl<ChainSpec> Clone for NodeConfig<ChainSpec> {
dev: self.dev,
pruning: self.pruning.clone(),
datadir: self.datadir.clone(),
engine: self.engine.clone(),
}
}
}