Skip to content

Commit f64aecf

Browse files
authored
feat(cli): expose tree engine persistence configuration (#10999)
1 parent c09f650 commit f64aecf

File tree

9 files changed

+95
-12
lines changed

9 files changed

+95
-12
lines changed

bin/reth/src/main.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,40 @@ static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::ne
55

66
use clap::{Args, Parser};
77
use reth::{args::utils::DefaultChainSpecParser, cli::Cli};
8-
use reth_node_builder::EngineNodeLauncher;
8+
use reth_node_builder::{
9+
engine_tree_config::{
10+
TreeConfig, DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD,
11+
},
12+
EngineNodeLauncher,
13+
};
914
use reth_node_ethereum::{node::EthereumAddOns, EthereumNode};
1015
use reth_provider::providers::BlockchainProvider2;
1116

1217
/// Parameters for configuring the engine
13-
#[derive(Debug, Clone, Args, PartialEq, Eq, Default)]
18+
#[derive(Debug, Clone, Args, PartialEq, Eq)]
1419
#[command(next_help_heading = "Engine")]
1520
pub struct EngineArgs {
1621
/// Enable the engine2 experimental features on reth binary
1722
#[arg(long = "engine.experimental", default_value = "false")]
1823
pub experimental: bool,
24+
25+
/// Configure persistence threshold for engine experimental.
26+
#[arg(long = "engine.persistence-threshold", requires = "experimental", default_value_t = DEFAULT_PERSISTENCE_THRESHOLD)]
27+
pub persistence_threshold: u64,
28+
29+
/// Configure the target number of blocks to keep in memory.
30+
#[arg(long = "engine.memory-block-buffer-target", requires = "experimental", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)]
31+
pub memory_block_buffer_target: u64,
32+
}
33+
34+
impl Default for EngineArgs {
35+
fn default() -> Self {
36+
Self {
37+
experimental: false,
38+
persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
39+
memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
40+
}
41+
}
1942
}
2043

2144
fn main() {
@@ -31,6 +54,9 @@ fn main() {
3154
let enable_engine2 = engine_args.experimental;
3255
match enable_engine2 {
3356
true => {
57+
let engine_tree_config = TreeConfig::default()
58+
.with_persistence_threshold(engine_args.persistence_threshold)
59+
.with_memory_block_buffer_target(engine_args.memory_block_buffer_target);
3460
let handle = builder
3561
.with_types_and_provider::<EthereumNode, BlockchainProvider2<_>>()
3662
.with_components(EthereumNode::components())
@@ -39,6 +65,7 @@ fn main() {
3965
let launcher = EngineNodeLauncher::new(
4066
builder.task_executor().clone(),
4167
builder.config().datadir(),
68+
engine_tree_config,
4269
);
4370
builder.launch_with(launcher)
4471
})

book/cli/reth/node.md

+10
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,16 @@ Engine:
665665
--engine.experimental
666666
Enable the engine2 experimental features on reth binary
667667
668+
--engine.persistence-threshold <PERSISTENCE_THRESHOLD>
669+
Configure persistence threshold for engine experimental
670+
671+
[default: 2]
672+
673+
--engine.memory-block-buffer-target <MEMORY_BLOCK_BUFFER_TARGET>
674+
Configure the target number of blocks to keep in memory
675+
676+
[default: 2]
677+
668678
Logging:
669679
--log.stdout.format <FORMAT>
670680
The format to use for logs written to stdout

crates/engine/tree/src/tree/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Engine tree configuration.
22
33
/// Triggers persistence when the number of canonical blocks in memory exceeds this threshold.
4-
const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 2;
4+
pub const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 2;
55

66
/// How close to the canonical head we persist blocks.
7-
const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 2;
7+
pub const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 2;
88

99
const DEFAULT_BLOCK_BUFFER_LIMIT: u32 = 256;
1010
const DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH: u32 = 256;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use tokio::sync::{
6060
};
6161
use tracing::*;
6262

63-
mod config;
63+
pub mod config;
6464
mod invalid_block_hook;
6565
mod metrics;
6666
use crate::{engine::EngineApiRequest, tree::metrics::EngineApiMetrics};

crates/ethereum/node/tests/it/builder.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ async fn test_eth_launcher() {
5656
.with_components(EthereumNode::components())
5757
.with_add_ons::<EthereumAddOns>()
5858
.launch_with_fn(|builder| {
59-
let launcher = EngineNodeLauncher::new(tasks.executor(), builder.config.datadir());
59+
let launcher = EngineNodeLauncher::new(
60+
tasks.executor(),
61+
builder.config.datadir(),
62+
Default::default(),
63+
);
6064
builder.launch_with(launcher)
6165
});
6266
}

crates/node/builder/src/launch/engine.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,20 @@ use crate::{
5454
pub struct EngineNodeLauncher {
5555
/// The task executor for the node.
5656
pub ctx: LaunchContext,
57+
58+
/// Temporary configuration for engine tree.
59+
/// After engine is stabilized, this should be configured through node builder.
60+
pub engine_tree_config: TreeConfig,
5761
}
5862

5963
impl EngineNodeLauncher {
6064
/// Create a new instance of the ethereum node launcher.
61-
pub const fn new(task_executor: TaskExecutor, data_dir: ChainPath<DataDirPath>) -> Self {
62-
Self { ctx: LaunchContext::new(task_executor, data_dir) }
65+
pub const fn new(
66+
task_executor: TaskExecutor,
67+
data_dir: ChainPath<DataDirPath>,
68+
engine_tree_config: TreeConfig,
69+
) -> Self {
70+
Self { ctx: LaunchContext::new(task_executor, data_dir), engine_tree_config }
6371
}
6472
}
6573

@@ -85,7 +93,7 @@ where
8593
self,
8694
target: NodeBuilderWithComponents<T, CB, AO>,
8795
) -> eyre::Result<Self::Node> {
88-
let Self { ctx } = self;
96+
let Self { ctx, engine_tree_config } = self;
8997
let NodeBuilderWithComponents {
9098
adapter: NodeTypesAdapter { database },
9199
components_builder,
@@ -221,7 +229,7 @@ where
221229
ctx.blockchain_db().clone(),
222230
pruner,
223231
ctx.components().payload_builder().clone(),
224-
TreeConfig::default(),
232+
engine_tree_config,
225233
ctx.invalid_block_hook()?,
226234
ctx.sync_metrics_tx(),
227235
);

crates/node/builder/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub use builder::{
2828
mod launch;
2929
pub use launch::{engine::EngineNodeLauncher, *};
3030

31+
/// Temporarily re-export engine tree config.
32+
pub use reth_engine_tree::tree::config as engine_tree_config;
33+
3134
mod handle;
3235
pub use handle::NodeHandle;
3336

crates/optimism/bin/src/main.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![cfg(feature = "optimism")]
55

66
use clap::Parser;
7-
use reth_node_builder::EngineNodeLauncher;
7+
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
88
use reth_node_optimism::{args::RollupArgs, node::OptimismAddOns, OptimismNode};
99
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
1010
use reth_optimism_rpc::SequencerClient;
@@ -27,6 +27,9 @@ fn main() {
2727
let sequencer_http_arg = rollup_args.sequencer_http.clone();
2828
match enable_engine2 {
2929
true => {
30+
let engine_tree_config = TreeConfig::default()
31+
.with_persistence_threshold(rollup_args.persistence_threshold)
32+
.with_memory_block_buffer_target(rollup_args.memory_block_buffer_target);
3033
let handle = builder
3134
.with_types_and_provider::<OptimismNode, BlockchainProvider2<_>>()
3235
.with_components(OptimismNode::components(rollup_args))
@@ -45,6 +48,7 @@ fn main() {
4548
let launcher = EngineNodeLauncher::new(
4649
builder.task_executor().clone(),
4750
builder.config().datadir(),
51+
engine_tree_config,
4852
);
4953
builder.launch_with(launcher)
5054
})

crates/optimism/node/src/args.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
33
//! clap [Args](clap::Args) for optimism rollup configuration
44
5+
use reth_node_builder::engine_tree_config::{
6+
DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD,
7+
};
8+
59
/// Parameters for rollup configuration
6-
#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]
10+
#[derive(Debug, Clone, PartialEq, Eq, clap::Args)]
711
#[command(next_help_heading = "Rollup")]
812
pub struct RollupArgs {
913
/// HTTP endpoint for the sequencer mempool
@@ -37,6 +41,29 @@ pub struct RollupArgs {
3741
/// Enable the engine2 experimental features on op-reth binary
3842
#[arg(long = "engine.experimental", default_value = "false")]
3943
pub experimental: bool,
44+
45+
/// Configure persistence threshold for engine experimental.
46+
#[arg(long = "engine.persistence-threshold", requires = "experimental", default_value_t = DEFAULT_PERSISTENCE_THRESHOLD)]
47+
pub persistence_threshold: u64,
48+
49+
/// Configure the target number of blocks to keep in memory.
50+
#[arg(long = "engine.memory-block-buffer-target", requires = "experimental", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)]
51+
pub memory_block_buffer_target: u64,
52+
}
53+
54+
impl Default for RollupArgs {
55+
fn default() -> Self {
56+
Self {
57+
sequencer_http: None,
58+
disable_txpool_gossip: false,
59+
enable_genesis_walkback: false,
60+
compute_pending_block: false,
61+
discovery_v4: false,
62+
experimental: false,
63+
persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
64+
memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
65+
}
66+
}
4067
}
4168

4269
#[cfg(test)]

0 commit comments

Comments
 (0)