Skip to content

Commit

Permalink
feat: integrate taiko support by adding L1 origin traits and updating…
Browse files Browse the repository at this point in the history
… Cargo.toml configurations
  • Loading branch information
johntaiko committed Dec 23, 2024
1 parent bd2986d commit 7c52a32
Show file tree
Hide file tree
Showing 40 changed files with 518 additions and 2,593 deletions.
101 changes: 11 additions & 90 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,13 @@ members = [
"crates/taiko/consensus/proposer",
"crates/taiko/engine-primitives/",
"crates/taiko/evm",
"crates/taiko/bin",
"crates/taiko/cli",
"crates/taiko/node",
"crates/taiko/rpc",
"crates/taiko/payload/builder",
"crates/taiko/payload/validator",
"crates/taiko/primitives/",
"crates/taiko/storage/",
"crates/taiko/chainspec",
"crates/taiko/hardforks",
]
default-members = ["bin/reth"]
exclude = ["book/sources"]
Expand Down Expand Up @@ -441,12 +439,10 @@ reth-trie-sparse = { path = "crates/trie/sparse" }
reth-zstd-compressors = { path = "crates/storage/zstd-compressors", default-features = false }

# taiko
taiko-reth = { path = "crates/taiko/bin" }
reth-taiko-cli = { path = "crates/taiko/cli" }
reth-taiko-consensus = { path = "crates/taiko/consensus/consensus" }
reth-taiko-proposer-consensus = { path = "crates/taiko/consensus/proposer" }
reth-taiko-primitives = { path = "crates/taiko/primitives" }
reth-taiko-provider = { path = "crates/taiko/storage" }
reth-taiko-evm = { path = "crates/taiko/evm" }
reth-taiko-payload-builder = { path = "crates/taiko/payload/builder" }
reth-taiko-payload-validator = { path = "crates/taiko/payload/validator" }
Expand Down
19 changes: 12 additions & 7 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ reth-consensus.workspace = true
reth-engine-util.workspace = true
reth-prune.workspace = true

# taiko
reth-taiko-chainspec.workspace = true
reth-taiko-forks.workspace = true

# crypto
alloy-eips.workspace = true
alloy-rlp.workspace = true
Expand Down Expand Up @@ -105,20 +109,17 @@ default = ["jemalloc"]
dev = ["reth-cli-commands/arbitrary"]

asm-keccak = [
"reth-node-core/asm-keccak",
"reth-primitives/asm-keccak",
"alloy-primitives/asm-keccak"
"reth-node-core/asm-keccak",
"reth-primitives/asm-keccak",
"alloy-primitives/asm-keccak",
]

jemalloc = [
"reth-cli-util/jemalloc",
"reth-node-core/jemalloc",
"reth-node-metrics/jemalloc",
]
jemalloc-prof = [
"reth-cli-util/jemalloc",
"reth-cli-util/jemalloc-prof"
]
jemalloc-prof = ["reth-cli-util/jemalloc", "reth-cli-util/jemalloc-prof"]
tracy-allocator = ["reth-cli-util/tracy-allocator"]

min-error-logs = ["tracing/release_max_level_error"]
Expand All @@ -130,3 +131,7 @@ min-trace-logs = ["tracing/release_max_level_trace"]
[[bin]]
name = "reth"
path = "src/main.rs"

[[bin]]
name = "taiko-reth"
path = "src/taiko.rs"
137 changes: 137 additions & 0 deletions bin/reth/src/taiko.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#![allow(missing_docs)]

#[global_allocator]
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();

use std::sync::Arc;

use clap::{Args, Parser};
use reth::cli::Cli;
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::{parse_genesis, ChainSpecParser};
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;
use reth_taiko_chainspec::{get_taiko_genesis, TaikoChainSpec};
use reth_taiko_forks::{
CHAIN_HEKLA_TESTNET, CHAIN_INTERNAL_TESTNET, CHAIN_KATLA_TESTNET, CHAIN_MAINNET,
};
use reth_tracing::tracing::warn;
use tracing::info;

/// Parameters for configuring the engine
#[derive(Debug, Clone, Args, PartialEq, Eq)]
#[command(next_help_heading = "Engine")]
pub struct EngineArgs {
/// Enable the experimental engine features on reth binary
///
/// DEPRECATED: experimental engine is default now, use --engine.legacy to enable the legacy
/// functionality
#[arg(long = "engine.experimental", default_value = "false")]
pub experimental: bool,

/// Enable the legacy engine on reth binary
#[arg(long = "engine.legacy", default_value = "false")]
pub legacy: bool,

/// Configure persistence threshold for engine experimental.
#[arg(long = "engine.persistence-threshold", conflicts_with = "legacy", 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", conflicts_with = "legacy", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)]
pub memory_block_buffer_target: u64,
}

impl Default for EngineArgs {
fn default() -> Self {
Self {
experimental: false,
legacy: false,
persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
}
}
}

fn main() {
reth_cli_util::sigsegv_handler::install();

// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}

if let Err(err) =
Cli::<TaikoChainSpecParser, EngineArgs>::parse().run(|builder, engine_args| async move {
if engine_args.experimental {
warn!(target: "reth::cli", "Experimental engine is default now, and the --engine.experimental flag is deprecated. To enable the legacy functionality, use --engine.legacy.");
}

let use_legacy_engine = engine_args.legacy;
match use_legacy_engine {
false => {
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())
.with_add_ons(EthereumAddOns::default())
.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
}
true => {
info!(target: "reth::cli", "Running with legacy engine");
let handle = builder.launch_node(EthereumNode::default()).await?;
handle.node_exit_future.await
}
}
})
{
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}

/// Optimism chain specification parser.
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct TaikoChainSpecParser;

impl ChainSpecParser for TaikoChainSpecParser {
type ChainSpec = ChainSpec;

const SUPPORTED_CHAINS: &'static [&'static str] =
&["hekla", "internal-a", "mainnet", "testnet"];

fn parse(s: &str) -> eyre::Result<Arc<Self::ChainSpec>> {
chain_value_parser(s).map(|spec| Arc::new(spec.inner.clone()))
}
}

/// Clap value parser for [`OpChainSpec`]s.
///
/// The value parser matches either a known chain, the path
/// to a json file, or a json formatted string in-memory. The json needs to be a Genesis struct.
pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<TaikoChainSpec>, eyre::Error> {
Ok(Arc::new(match s {
"hekla" => get_taiko_genesis(CHAIN_HEKLA_TESTNET).into(),
"internal-a" => get_taiko_genesis(CHAIN_INTERNAL_TESTNET).into(),
"mainnet" => get_taiko_genesis(CHAIN_MAINNET).into(),
_ => parse_genesis(s)?.into(),
}))
}
Loading

0 comments on commit 7c52a32

Please sign in to comment.