Skip to content

Commit

Permalink
refactor: Remove unused dependencies and update Taiko chain configura…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
johntaiko committed Sep 9, 2024
1 parent 3e30766 commit 1a0aafb
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 43 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use spec::{TAIKO_HEKLA, TAIKO_INTERNAL_L2_A, TAIKO_MAINNET, TAIKO_TESTNET};
extern crate alloc;

#[cfg(feature = "taiko")]
mod taiko;
pub mod taiko;

mod info;

Expand Down
19 changes: 16 additions & 3 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#[cfg(feature = "taiko")]
use super::taiko::{get_taiko_genesis, TaikoNamedChain};
use crate::constants::MAINNET_DEPOSIT_CONTRACT;
use crate::{
constants::MAINNET_DEPOSIT_CONTRACT,
taiko::{HEKLA_ONTAKE_BLOCK, INTERNAL_DEVNET_ONTAKE_BLOCK, MAINNET_ONTAKE_BLOCK},
};
#[cfg(not(feature = "std"))]
use alloc::{
collections::BTreeMap,
Expand Down Expand Up @@ -293,8 +296,8 @@ pub static BASE_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
#[cfg(feature = "taiko")]
pub static TAIKO_INTERNAL_L2_A: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: TaikoNamedChain::TaikoInternalL2A.into(),
genesis: get_taiko_genesis(TaikoNamedChain::TaikoInternalL2A),
chain: TaikoNamedChain::TaikoInternalL2a.into(),
genesis: get_taiko_genesis(TaikoNamedChain::TaikoInternalL2a),
hardforks: BTreeMap::from([
(Hardfork::Frontier, ForkCondition::Block(0)),
(Hardfork::Homestead, ForkCondition::Block(0)),
Expand Down Expand Up @@ -993,6 +996,14 @@ impl From<Genesis> for ChainSpec {
#[cfg(feature = "optimism")]
let optimism_genesis_info = OptimismGenesisInfo::extract_from(&genesis);

#[cfg(feature = "taiko")]
let ontake_block = match TaikoNamedChain::try_from(genesis.config.chain_id) {
Ok(TaikoNamedChain::TaikoInternalL2a) => Some(INTERNAL_DEVNET_ONTAKE_BLOCK),
Ok(TaikoNamedChain::Hekla) => Some(HEKLA_ONTAKE_BLOCK),
Ok(TaikoNamedChain::Mainnet) => Some(MAINNET_ONTAKE_BLOCK),
_ => None,
};

// Block-based hardforks
let hardfork_opts = [
(Hardfork::Homestead, genesis.config.homestead_block),
Expand All @@ -1010,6 +1021,8 @@ impl From<Genesis> for ChainSpec {
(Hardfork::GrayGlacier, genesis.config.gray_glacier_block),
#[cfg(feature = "optimism")]
(Hardfork::Bedrock, optimism_genesis_info.bedrock_block),
#[cfg(feature = "taiko")]
(Hardfork::Ontake, ontake_block),
];
let mut hardforks = hardfork_opts
.iter()
Expand Down
44 changes: 37 additions & 7 deletions crates/chainspec/src/taiko.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Taiko Chain Specification
use core::str::FromStr;
use std::collections::BTreeMap;

Expand All @@ -8,6 +9,13 @@ use once_cell::sync::Lazy;
use revm_primitives::{Address, Bytes, FixedBytes, B256, U256};
use serde::{Deserialize, Serialize};

/// The internal devnet ontake height.
pub const INTERNAL_DEVNET_ONTAKE_BLOCK: u64 = 2;
/// The hekla ontake height.
pub const HEKLA_ONTAKE_BLOCK: u64 = 840_512;
/// The mainnet ontake height.
pub const MAINNET_ONTAKE_BLOCK: u64 = 9_000_000;

impl ChainSpec {
/// Returns the treasury address for the chain.
#[inline]
Expand All @@ -24,7 +32,7 @@ impl ChainSpec {

// Taiko Chain Configuration, sets the chain_id to the internal devnet L2A by default.
static TAIKO_CHAIN_CONFIG: Lazy<ChainConfig> = Lazy::new(|| ChainConfig {
chain_id: TaikoNamedChain::TaikoInternalL2A as u64,
chain_id: TaikoNamedChain::TaikoInternalL2a as u64,
homestead_block: Some(0),
dao_fork_block: None,
dao_fork_support: false,
Expand Down Expand Up @@ -54,6 +62,7 @@ static TAIKO_CHAIN_CONFIG: Lazy<ChainConfig> = Lazy::new(|| ChainConfig {
deposit_contract_address: None,
});

/// The named chains for Taiko.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, strum::IntoStaticStr)] // Into<&'static str>, AsRef<str>, fmt::Display and serde::Serialize
#[derive(strum::VariantNames)] // NamedChain::VARIANTS
#[derive(strum::VariantArray)] // NamedChain::VARIANTS
Expand All @@ -64,27 +73,36 @@ static TAIKO_CHAIN_CONFIG: Lazy<ChainConfig> = Lazy::new(|| ChainConfig {
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[strum(serialize_all = "kebab-case")]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[repr(u64)]
pub enum TaikoNamedChain {
/// The mainnet chain.
#[cfg_attr(feature = "serde", serde(alias = "mainnet"))]
Mainnet = 167000,
/// The internal devnet L2A chain.
#[cfg_attr(feature = "serde", serde(alias = "taiko-internal-l2a"))]
TaikoInternalL2A = 167001,
TaikoInternalL2a = 167001,
/// The internal devnet L2B chain.
#[cfg_attr(feature = "serde", serde(alias = "taiko-internal-l2b"))]
TaikoInternalL2B = 167002,
TaikoInternalL2b = 167002,
/// The Snaefellsjokull chain.
#[cfg_attr(feature = "serde", serde(alias = "snaefellsjokull"))]
Snaefellsjokull = 167003,
/// The Askja chain.
#[cfg_attr(feature = "serde", serde(alias = "askja"))]
Askja = 167004,
/// The Grimsvotn chain.
#[cfg_attr(feature = "serde", serde(alias = "grimsvotn"))]
Grimsvotn = 167005,
/// The Eldfell chain.
#[cfg_attr(feature = "serde", serde(alias = "eldfell"))]
Eldfell = 167006,
/// The Jolnir chain.
#[cfg_attr(feature = "serde", serde(alias = "jolnir"))]
Jolnir = 167007,
/// The Katla chain.
#[cfg_attr(feature = "serde", serde(alias = "katla"))]
Katla = 167008,
/// The Hekla chain.
#[cfg_attr(feature = "serde", serde(alias = "hekla"))]
Hekla = 167009,
}
Expand All @@ -95,15 +113,16 @@ impl From<TaikoNamedChain> for Chain {
}
}

pub(crate) fn get_taiko_genesis(chain: TaikoNamedChain) -> Genesis {
/// Returns the genesis block for the given chain.
pub fn get_taiko_genesis(chain: TaikoNamedChain) -> Genesis {
let alloc_str = match chain {
TaikoNamedChain::Mainnet => {
include_str!("../res/genesis/taiko/mainnet.json")
}
TaikoNamedChain::TaikoInternalL2A => {
TaikoNamedChain::TaikoInternalL2a => {
include_str!("../res/genesis/taiko/internal_l2a.json")
}
TaikoNamedChain::TaikoInternalL2B => {
TaikoNamedChain::TaikoInternalL2b => {
include_str!("../res/genesis/taiko/internal_l2b.json")
}
TaikoNamedChain::Snaefellsjokull => {
Expand Down Expand Up @@ -173,3 +192,14 @@ impl From<TaikoGenesisAccount> for GenesisAccount {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn named() {
let name: &str = TaikoNamedChain::TaikoInternalL2a.into();
assert_eq!(name, "taiko-internal-l2a");
}
}
56 changes: 30 additions & 26 deletions crates/node-core/src/args/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Clap parser utilities

use alloy_genesis::Genesis;
use eyre::bail;
use reth_chainspec::ChainSpec;
use reth_fs_util as fs;
use reth_primitives::{BlockHashOrNumber, B256};
Expand All @@ -21,7 +22,7 @@ use reth_chainspec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA};
use reth_chainspec::{GOERLI, HOLESKY, MAINNET, SEPOLIA};

#[cfg(feature = "taiko")]
use reth_chainspec::{TAIKO_HEKLA, TAIKO_INTERNAL_L2_A, TAIKO_MAINNET, TAIKO_TESTNET};
use reth_chainspec::taiko::{get_taiko_genesis, TaikoNamedChain};

#[cfg(feature = "optimism")]
/// Chains supported by op-reth. First value should be used as the default.
Expand All @@ -31,7 +32,8 @@ pub const SUPPORTED_CHAINS: &[&str] = &["optimism", "optimism-sepolia", "base",
pub const SUPPORTED_CHAINS: &[&str] = &["mainnet", "sepolia", "goerli", "holesky", "dev"];
#[cfg(feature = "taiko")]
/// Chains supported by taiko-reth. First value should be used as default.
pub const SUPPORTED_CHAINS: &[&str] = &["testnet", "internal_devnet_a", "mainnet", "hekla"];
pub const SUPPORTED_CHAINS: &[&str] =
&["taiko-internal-l2a", "taiko-internal-l2b", "mainnet", "hekla"];

/// Helper to parse a [Duration] from seconds
pub fn parse_duration_from_secs(arg: &str) -> eyre::Result<Duration, std::num::ParseIntError> {
Expand Down Expand Up @@ -67,32 +69,34 @@ pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error>
"base" => BASE_MAINNET.clone(),
#[cfg(feature = "optimism")]
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(),
#[cfg(feature = "taiko")]
"testnet" => TAIKO_TESTNET.clone(),
#[cfg(feature = "taiko")]
"internal_devnet_a" => TAIKO_INTERNAL_L2_A.clone(),
#[cfg(feature = "taiko")]
"hekla" => TAIKO_HEKLA.clone(),
#[cfg(feature = "taiko")]
"mainnet" => TAIKO_MAINNET.clone(),
_ => {
// try to read json from path first
let raw = match fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned())) {
Ok(raw) => raw,
Err(io_err) => {
// valid json may start with "\n", but must contain "{"
if s.contains('{') {
s.to_string()
} else {
return Err(io_err.into()); // assume invalid path
}
if let Ok(chain_id) = s.parse::<u64>() {
if let Ok(chain) = TaikoNamedChain::try_from(chain_id) {
let genesis = get_taiko_genesis(chain);
Arc::new(genesis.into())
} else {
bail!("Invalid taiko chain id")
}
};

// both serialized Genesis and ChainSpec structs supported
let genesis: Genesis = serde_json::from_str(&raw)?;

Arc::new(genesis.into())
} else {
// try to read json from path first
let raw =
match fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned())) {
Ok(raw) => raw,
Err(io_err) => {
// valid json may start with "\n", but must contain "{"
if s.contains('{') {
s.to_string()
} else {
return Err(io_err.into()); // assume invalid path
}
}
};

// both serialized Genesis and ChainSpec structs supported
let genesis: Genesis = serde_json::from_str(&raw)?;

Arc::new(genesis.into())
}
}
})
}
Expand Down
1 change: 0 additions & 1 deletion crates/payload/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ tokio = { workspace = true, features = ["sync"] }
# misc
thiserror.workspace = true
serde.workspace = true
tracing.workspace = true

[features]
taiko = ["reth-transaction-pool/taiko"]
3 changes: 0 additions & 3 deletions crates/taiko/payload/validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ reth-primitives = { workspace = true, features = ["taiko"] }
reth-rpc-types.workspace = true
reth-rpc-types-compat.workspace = true
taiko-reth-engine-primitives.workspace = true

# misc
tracing.workspace = true

0 comments on commit 1a0aafb

Please sign in to comment.