Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move OptimismHardfork to new crate reth_optimism_forks #10963

Merged
merged 14 commits into from
Sep 20, 2024
29 changes: 25 additions & 4 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ members = [
"crates/optimism/cli",
"crates/optimism/consensus",
"crates/optimism/evm/",
"crates/optimism/hardforks/",
"crates/optimism/node/",
"crates/optimism/payload/",
"crates/optimism/primitives/",
Expand Down Expand Up @@ -363,6 +364,7 @@ reth-node-types = { path = "crates/node/types" }
reth-optimism-chainspec = { path = "crates/optimism/chainspec" }
reth-optimism-cli = { path = "crates/optimism/cli" }
reth-optimism-consensus = { path = "crates/optimism/consensus" }
reth-optimism-forks = { path = "crates/optimism/hardforks" }
reth-optimism-payload-builder = { path = "crates/optimism/payload" }
reth-optimism-primitives = { path = "crates/optimism/primitives" }
reth-optimism-rpc = { path = "crates/optimism/rpc" }
Expand Down
5 changes: 4 additions & 1 deletion crates/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ reth-network-peers.workspace = true
reth-trie-common.workspace = true
reth-primitives-traits.workspace = true

# op-reth
reth-optimism-forks = { workspace = true, optional = true }

# ethereum
alloy-chains = { workspace = true, features = ["serde", "rlp"] }
alloy-eips = { workspace = true, features = ["serde"] }
Expand Down Expand Up @@ -47,9 +50,9 @@ op-alloy-rpc-types.workspace = true
[features]
default = ["std"]
optimism = [
"reth-ethereum-forks/optimism",
"serde",
"dep:op-alloy-rpc-types",
"reth-optimism-forks",
]
std = []
arbitrary = [
Expand Down
37 changes: 22 additions & 15 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{constants::MAINNET_DEPOSIT_CONTRACT, once_cell_set, EthChainSpec};
pub use alloy_eips::eip1559::BaseFeeParams;

use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_chains::{Chain, NamedChain};
use alloy_genesis::Genesis;
Expand All @@ -8,8 +9,7 @@ use derive_more::From;
use once_cell::sync::{Lazy, OnceCell};
use reth_ethereum_forks::{
ChainHardforks, DisplayHardforks, EthereumHardfork, EthereumHardforks, ForkCondition,
ForkFilter, ForkFilterKey, ForkHash, ForkId, Hardfork, Hardforks, Head, OptimismHardforks,
DEV_HARDFORKS,
ForkFilter, ForkFilterKey, ForkHash, ForkId, Hardfork, Hardforks, Head, DEV_HARDFORKS,
};
use reth_network_peers::{
base_nodes, base_testnet_nodes, holesky_nodes, mainnet_nodes, op_nodes, op_testnet_nodes,
Expand All @@ -24,7 +24,7 @@ use reth_primitives_traits::{
};
use reth_trie_common::root::state_root_ref_unhashed;

pub use alloy_eips::eip1559::BaseFeeParams;
use crate::{constants::MAINNET_DEPOSIT_CONTRACT, once_cell_set, EthChainSpec};

/// The Ethereum mainnet spec
pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
Expand Down Expand Up @@ -244,7 +244,7 @@ impl ChainSpec {
#[cfg(feature = "optimism")]
pub fn is_optimism(&self) -> bool {
self.chain.is_optimism() ||
self.hardforks.get(reth_ethereum_forks::OptimismHardfork::Bedrock).is_some()
self.hardforks.get(reth_optimism_forks::OptimismHardfork::Bedrock).is_some()
}

/// Returns `true` if this chain contains Optimism configuration.
Expand Down Expand Up @@ -621,7 +621,8 @@ impl EthereumHardforks for ChainSpec {
}
}

impl OptimismHardforks for ChainSpec {}
#[cfg(feature = "optimism")]
impl reth_optimism_forks::OptimismHardforks for ChainSpec {}

/// Convert the given [`Genesis`] into an Ethereum [`ChainSpec`].
#[cfg(not(feature = "optimism"))]
Expand Down Expand Up @@ -715,7 +716,7 @@ fn into_ethereum_chain_spec(genesis: Genesis) -> ChainSpec {
#[cfg(feature = "optimism")]
/// Convert the given [`Genesis`] into an Optimism [`ChainSpec`].
fn into_optimism_chain_spec(genesis: Genesis) -> ChainSpec {
use reth_ethereum_forks::OptimismHardfork;
use reth_optimism_forks::OptimismHardfork;
let optimism_genesis_info = OptimismGenesisInfo::extract_from(&genesis);
let genesis_info = optimism_genesis_info.optimism_chain_info.genesis_info.unwrap_or_default();

Expand Down Expand Up @@ -979,15 +980,17 @@ impl ChainSpecBuilder {
#[cfg(feature = "optimism")]
pub fn bedrock_activated(mut self) -> Self {
self = self.paris_activated();
self.hardforks.insert(crate::OptimismHardfork::Bedrock, ForkCondition::Block(0));
self.hardforks
.insert(reth_optimism_forks::OptimismHardfork::Bedrock, ForkCondition::Block(0));
self
}

/// Enable Regolith at genesis
#[cfg(feature = "optimism")]
pub fn regolith_activated(mut self) -> Self {
self = self.bedrock_activated();
self.hardforks.insert(crate::OptimismHardfork::Regolith, ForkCondition::Timestamp(0));
self.hardforks
.insert(reth_optimism_forks::OptimismHardfork::Regolith, ForkCondition::Timestamp(0));
self
}

Expand All @@ -997,7 +1000,8 @@ impl ChainSpecBuilder {
self = self.regolith_activated();
// Canyon also activates changes from L1's Shanghai hardfork
self.hardforks.insert(EthereumHardfork::Shanghai, ForkCondition::Timestamp(0));
self.hardforks.insert(crate::OptimismHardfork::Canyon, ForkCondition::Timestamp(0));
self.hardforks
.insert(reth_optimism_forks::OptimismHardfork::Canyon, ForkCondition::Timestamp(0));
self
}

Expand All @@ -1006,23 +1010,26 @@ impl ChainSpecBuilder {
pub fn ecotone_activated(mut self) -> Self {
self = self.canyon_activated();
self.hardforks.insert(EthereumHardfork::Cancun, ForkCondition::Timestamp(0));
self.hardforks.insert(crate::OptimismHardfork::Ecotone, ForkCondition::Timestamp(0));
self.hardforks
.insert(reth_optimism_forks::OptimismHardfork::Ecotone, ForkCondition::Timestamp(0));
self
}

/// Enable Fjord at genesis
#[cfg(feature = "optimism")]
pub fn fjord_activated(mut self) -> Self {
self = self.ecotone_activated();
self.hardforks.insert(crate::OptimismHardfork::Fjord, ForkCondition::Timestamp(0));
self.hardforks
.insert(reth_optimism_forks::OptimismHardfork::Fjord, ForkCondition::Timestamp(0));
self
}

/// Enable Granite at genesis
#[cfg(feature = "optimism")]
pub fn granite_activated(mut self) -> Self {
self = self.fjord_activated();
self.hardforks.insert(crate::OptimismHardfork::Granite, ForkCondition::Timestamp(0));
self.hardforks
.insert(reth_optimism_forks::OptimismHardfork::Granite, ForkCondition::Timestamp(0));
self
}

Expand Down Expand Up @@ -1117,7 +1124,7 @@ impl OptimismGenesisInfo {
BaseFeeParams::new(denominator as u128, elasticity as u128),
),
(
reth_ethereum_forks::OptimismHardfork::Canyon.boxed(),
reth_optimism_forks::OptimismHardfork::Canyon.boxed(),
BaseFeeParams::new(canyon_denominator as u128, elasticity as u128),
),
]
Expand Down Expand Up @@ -2518,7 +2525,7 @@ Post-merge hard forks (timestamp based):
#[test]
#[cfg(feature = "optimism")]
fn test_fork_order_optimism_mainnet() {
use crate::OptimismHardfork;
use reth_optimism_forks::OptimismHardfork;

let genesis = Genesis {
config: ChainConfig {
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ pub mod recover;
pub mod stage;
#[cfg(feature = "dev")]
pub mod test_vectors;

pub use node::NodeCommand;
18 changes: 0 additions & 18 deletions crates/cli/commands/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,24 +314,6 @@ mod tests {
assert_eq!(db_path, Path::new("my/custom/path/db"));
}

#[test]
fn parse_dev() {
let cmd: NodeCommand = NodeCommand::parse_from(["reth", "--dev"]);
let chain = reth_chainspec::DEV.clone();
assert_eq!(cmd.chain.chain, chain.chain);
assert_eq!(cmd.chain.genesis_hash, chain.genesis_hash);
assert_eq!(
cmd.chain.paris_block_and_final_difficulty,
chain.paris_block_and_final_difficulty
);
assert_eq!(cmd.chain.hardforks, chain.hardforks);

assert!(cmd.rpc.http);
assert!(cmd.network.discovery.disable_discovery);

assert!(cmd.dev.dev);
}

#[test]
fn parse_instance() {
let mut cmd: NodeCommand = NodeCommand::parse_from(["reth"]);
Expand Down
1 change: 0 additions & 1 deletion crates/engine/util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@ tracing.workspace = true
[features]
optimism = [
"reth-beacon-consensus/optimism",
"reth-ethereum-forks/optimism"
]
1 change: 0 additions & 1 deletion crates/ethereum-forks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ proptest.workspace = true
[features]
default = ["std", "serde", "rustc-hash"]
arbitrary = ["dep:arbitrary", "dep:proptest", "dep:proptest-derive"]
optimism = []
serde = ["dep:serde"]
std = ["thiserror-no-std/std", "rustc-hash/std"]
rustc-hash = ["dep:rustc-hash"]
12 changes: 3 additions & 9 deletions crates/ethereum-forks/src/hardfork/dev.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{ChainHardforks, EthereumHardfork, ForkCondition};
use alloc::vec;

use alloy_primitives::U256;
use once_cell::sync::Lazy;

use crate::{ChainHardforks, EthereumHardfork, ForkCondition};

/// Dev hardforks
pub static DEV_HARDFORKS: Lazy<ChainHardforks> = Lazy::new(|| {
ChainHardforks::new(vec![
Expand All @@ -23,13 +25,5 @@ pub static DEV_HARDFORKS: Lazy<ChainHardforks> = Lazy::new(|| {
),
(EthereumHardfork::Shanghai.boxed(), ForkCondition::Timestamp(0)),
(EthereumHardfork::Cancun.boxed(), ForkCondition::Timestamp(0)),
#[cfg(feature = "optimism")]
(crate::OptimismHardfork::Regolith.boxed(), ForkCondition::Timestamp(0)),
#[cfg(feature = "optimism")]
(crate::OptimismHardfork::Bedrock.boxed(), ForkCondition::Block(0)),
#[cfg(feature = "optimism")]
(crate::OptimismHardfork::Ecotone.boxed(), ForkCondition::Timestamp(0)),
#[cfg(feature = "optimism")]
(crate::OptimismHardfork::Canyon.boxed(), ForkCondition::Timestamp(0)),
])
});
Loading
Loading