Skip to content

Commit

Permalink
feat(cli): expose tree engine persistence configuration (paradigmxyz#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Sep 18, 2024
1 parent c09f650 commit f64aecf
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 12 deletions.
31 changes: 29 additions & 2 deletions bin/reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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::<EthereumNode, BlockchainProvider2<_>>()
.with_components(EthereumNode::components())
Expand All @@ -39,6 +65,7 @@ fn main() {
let launcher = EngineNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
engine_tree_config,
);
builder.launch_with(launcher)
})
Expand Down
10 changes: 10 additions & 0 deletions book/cli/reth/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,16 @@ Engine:
--engine.experimental
Enable the engine2 experimental features on reth binary
--engine.persistence-threshold <PERSISTENCE_THRESHOLD>
Configure persistence threshold for engine experimental
[default: 2]
--engine.memory-block-buffer-target <MEMORY_BLOCK_BUFFER_TARGET>
Configure the target number of blocks to keep in memory
[default: 2]
Logging:
--log.stdout.format <FORMAT>
The format to use for logs written to stdout
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/tree/src/tree/config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
6 changes: 5 additions & 1 deletion crates/ethereum/node/tests/it/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ async fn test_eth_launcher() {
.with_components(EthereumNode::components())
.with_add_ons::<EthereumAddOns>()
.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)
});
}
Expand Down
16 changes: 12 additions & 4 deletions crates/node/builder/src/launch/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataDirPath>) -> Self {
Self { ctx: LaunchContext::new(task_executor, data_dir) }
pub const fn new(
task_executor: TaskExecutor,
data_dir: ChainPath<DataDirPath>,
engine_tree_config: TreeConfig,
) -> Self {
Self { ctx: LaunchContext::new(task_executor, data_dir), engine_tree_config }
}
}

Expand All @@ -85,7 +93,7 @@ where
self,
target: NodeBuilderWithComponents<T, CB, AO>,
) -> eyre::Result<Self::Node> {
let Self { ctx } = self;
let Self { ctx, engine_tree_config } = self;
let NodeBuilderWithComponents {
adapter: NodeTypesAdapter { database },
components_builder,
Expand Down Expand Up @@ -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(),
);
Expand Down
3 changes: 3 additions & 0 deletions crates/node/builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion crates/optimism/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::<OptimismNode, BlockchainProvider2<_>>()
.with_components(OptimismNode::components(rollup_args))
Expand All @@ -45,6 +48,7 @@ fn main() {
let launcher = EngineNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
engine_tree_config,
);
builder.launch_with(launcher)
})
Expand Down
29 changes: 28 additions & 1 deletion crates/optimism/node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit f64aecf

Please sign in to comment.