Skip to content

Commit

Permalink
Adding support for experimental engine
Browse files Browse the repository at this point in the history
  • Loading branch information
poplexity committed Oct 13, 2024
1 parent c4810e8 commit 9ac1e19
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
58 changes: 43 additions & 15 deletions crates/telos/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::ne

use clap::Parser;
use reth::args::utils::EthereumChainSpecParser;
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
use reth::cli::Cli;
use reth_node_telos::{TelosArgs, TelosNode};
use reth_node_telos::node::TelosAddOns;
use reth_provider::providers::BlockchainProvider2;
use reth_telos_rpc::TelosClient;


#[cfg(feature = "telos")]
fn main() {
reth_cli_util::sigsegv_handler::install();
Expand All @@ -19,21 +23,45 @@ fn main() {
}

if let Err(err) = Cli::<EthereumChainSpecParser, TelosArgs>::parse().run(|builder, telos_args| async move {
let handle = builder
.node(TelosNode::new(telos_args.clone()))
.extend_rpc_modules(move |ctx| {
if telos_args.telos_endpoint.is_some() {
ctx.registry
.eth_api()
.set_telos_client(TelosClient::new(telos_args.into()));
}

Ok(())
})
.launch()
.await?;

handle.node_exit_future.await
match telos_args.experimental {
true => {
let engine_tree_config = TreeConfig::default()
.with_persistence_threshold(telos_args.persistence_threshold)
.with_max_execute_block_batch_size(telos_args.max_execute_block_batch_size)
.with_memory_block_buffer_target(telos_args.memory_block_buffer_target);
let handle = builder
.with_types_and_provider::<TelosNode, BlockchainProvider2<_>>()
.with_components(TelosNode::components())
.with_add_ons::<TelosAddOns>()
.launch_with_fn(|builder| {
let launcher = EngineNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
engine_tree_config,
);
builder.launch_with(launcher)
})
.await?;
handle.node_exit_future.await
},
false => {
let handle = builder
.node(TelosNode::new(telos_args.clone()))
.extend_rpc_modules(move |ctx| {
if telos_args.telos_endpoint.is_some() {
ctx.registry
.eth_api()
.set_telos_client(TelosClient::new(telos_args.into()));
}

Ok(())
})
.launch()
.await?;

handle.node_exit_future.await
}
}
}) {
eprintln!("Error: {err:?}");
std::process::exit(1);
Expand Down
20 changes: 20 additions & 0 deletions crates/telos/node/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! clap [Args](clap::Args) for telos configuration

use reth_telos_rpc::eth::telos_client::TelosClientArgs;
use crate::{DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE, DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD};

#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]
#[clap(next_help_heading = "Telos")]
Expand All @@ -25,6 +26,25 @@ pub struct TelosArgs {
/// Seconds to cache gas price
#[arg(long = "telos.gas_cache_seconds")]
pub gas_cache_seconds: Option<u32>,

/// 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,

/// Maximum number of blocks to execute sequentially in a batch.
///
/// This is used as a cutoff to prevent long-running sequential block execution when we receive
/// a batch of downloaded blocks.
#[arg(long = "engine.max-execute-block-batch-size", requires = "experimental", default_value_t = DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE)]
pub max_execute_block_batch_size: usize,
}

impl From<TelosArgs> for TelosClientArgs {
Expand Down
4 changes: 4 additions & 0 deletions crates/telos/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ pub mod node;

pub use crate::args::TelosArgs;
pub use crate::node::TelosNode;

const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 16;
const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 16;
const DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE: usize = 50;

0 comments on commit 9ac1e19

Please sign in to comment.