Move OptimismHardfork to new crate reth_optimism_forks (#10963)

This commit is contained in:
Emilia Hane
2024-09-20 18:51:45 +02:00
committed by GitHub
parent 63f2d59068
commit 66089682d7
42 changed files with 302 additions and 120 deletions

29
Cargo.lock generated
View File

@ -730,9 +730,9 @@ dependencies = [
[[package]]
name = "alloy-trie"
version = "0.5.3"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a46c9c4fdccda7982e7928904bd85fe235a0404ee3d7e197fff13d61eac8b4f"
checksum = "398a977d774db13446b8cead8cfa9517aebf9e03fc8a1512892dc1e03e70bb04"
dependencies = [
"alloy-primitives",
"alloy-rlp",
@ -4410,7 +4410,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [
"cfg-if",
"windows-targets 0.48.5",
"windows-targets 0.52.6",
]
[[package]]
@ -6463,6 +6463,7 @@ dependencies = [
"op-alloy-rpc-types",
"reth-ethereum-forks",
"reth-network-peers",
"reth-optimism-forks",
"reth-primitives-traits",
"reth-trie-common",
"serde",
@ -7170,9 +7171,11 @@ name = "reth-ethereum-cli"
version = "1.0.7"
dependencies = [
"alloy-genesis",
"clap",
"eyre",
"reth-chainspec",
"reth-cli",
"reth-cli-commands",
"serde_json",
"shellexpand",
]
@ -7308,6 +7311,7 @@ dependencies = [
"reth-execution-types",
"reth-optimism-chainspec",
"reth-optimism-consensus",
"reth-optimism-forks",
"reth-primitives",
"reth-prune-types",
"reth-revm",
@ -7942,6 +7946,7 @@ dependencies = [
"reth-node-builder",
"reth-optimism-chainspec",
"reth-optimism-consensus",
"reth-optimism-forks",
"reth-optimism-payload-builder",
"reth-optimism-rpc",
"reth-payload-builder",
@ -7983,6 +7988,7 @@ dependencies = [
"op-alloy-rpc-types",
"reth-chainspec",
"reth-ethereum-forks",
"reth-optimism-forks",
"reth-primitives-traits",
"serde_json",
]
@ -8039,11 +8045,23 @@ dependencies = [
"reth-consensus",
"reth-consensus-common",
"reth-optimism-chainspec",
"reth-optimism-forks",
"reth-primitives",
"reth-trie-common",
"tracing",
]
[[package]]
name = "reth-optimism-forks"
version = "1.0.7"
dependencies = [
"alloy-chains",
"alloy-primitives",
"once_cell",
"reth-ethereum-forks",
"serde",
]
[[package]]
name = "reth-optimism-payload-builder"
version = "1.0.7"
@ -8056,6 +8074,7 @@ dependencies = [
"reth-evm",
"reth-evm-optimism",
"reth-execution-types",
"reth-optimism-forks",
"reth-payload-builder",
"reth-payload-primitives",
"reth-primitives",
@ -8099,6 +8118,7 @@ dependencies = [
"reth-node-api",
"reth-node-builder",
"reth-optimism-chainspec",
"reth-optimism-forks",
"reth-primitives",
"reth-provider",
"reth-rpc",
@ -8197,6 +8217,7 @@ dependencies = [
"reth-codecs",
"reth-ethereum-forks",
"reth-optimism-chainspec",
"reth-optimism-forks",
"reth-primitives-traits",
"reth-static-file-types",
"reth-trie-common",
@ -11175,7 +11196,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.48.0",
"windows-sys 0.59.0",
]
[[package]]

View File

@ -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/",
@ -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" }

View File

@ -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"] }
@ -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 = [

View File

@ -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;
@ -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,
@ -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(|| {
@ -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.
@ -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"))]
@ -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();
@ -979,7 +980,8 @@ 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
}
@ -987,7 +989,8 @@ impl ChainSpecBuilder {
#[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
}
@ -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
}
@ -1006,7 +1010,8 @@ 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
}
@ -1014,7 +1019,8 @@ impl ChainSpecBuilder {
#[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
}
@ -1022,7 +1028,8 @@ impl ChainSpecBuilder {
#[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
}
@ -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),
),
]
@ -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 {

View File

@ -22,3 +22,5 @@ pub mod recover;
pub mod stage;
#[cfg(feature = "dev")]
pub mod test_vectors;
pub use node::NodeCommand;

View File

@ -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"]);

View File

@ -50,5 +50,4 @@ tracing.workspace = true
[features]
optimism = [
"reth-beacon-consensus/optimism",
"reth-ethereum-forks/optimism"
]

View File

@ -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"]

View File

@ -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![
@ -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)),
])
});

View File

@ -3,9 +3,6 @@ mod macros;
mod ethereum;
pub use ethereum::EthereumHardfork;
mod optimism;
pub use optimism::OptimismHardfork;
mod dev;
pub use dev::DEV_HARDFORKS;
@ -47,7 +44,6 @@ impl Hash for dyn Hardfork + 'static {
#[cfg(test)]
mod tests {
use super::*;
use crate::hardfork::optimism::OptimismHardfork;
use std::str::FromStr;
#[test]
@ -99,24 +95,6 @@ mod tests {
assert_eq!(hardforks, expected_hardforks);
}
#[test]
fn check_op_hardfork_from_str() {
let hardfork_str = ["beDrOck", "rEgOlITH", "cAnYoN", "eCoToNe", "FJorD", "GRaNiTe"];
let expected_hardforks = [
OptimismHardfork::Bedrock,
OptimismHardfork::Regolith,
OptimismHardfork::Canyon,
OptimismHardfork::Ecotone,
OptimismHardfork::Fjord,
OptimismHardfork::Granite,
];
let hardforks: Vec<OptimismHardfork> =
hardfork_str.iter().map(|h| OptimismHardfork::from_str(h).unwrap()).collect();
assert_eq!(hardforks, expected_hardforks);
}
#[test]
fn check_nonexistent_hardfork_from_str() {
assert!(EthereumHardfork::from_str("not a hardfork").is_err());

View File

@ -2,10 +2,6 @@
mod ethereum;
pub use ethereum::EthereumHardforks;
/// Optimism helper methods
mod optimism;
pub use optimism::OptimismHardforks;
use crate::{ForkCondition, Hardfork};
#[cfg(feature = "std")]
use rustc_hash::FxHashMap;

View File

@ -27,7 +27,7 @@ mod head;
pub use forkid::{
EnrForkIdEntry, ForkFilter, ForkFilterKey, ForkHash, ForkId, ForkTransition, ValidationError,
};
pub use hardfork::{EthereumHardfork, Hardfork, OptimismHardfork, DEV_HARDFORKS};
pub use hardfork::{EthereumHardfork, Hardfork, DEV_HARDFORKS};
pub use head::Head;
pub use display::DisplayHardforks;

View File

@ -11,12 +11,20 @@ repository.workspace = true
workspace = true
[dependencies]
# reth
reth-cli.workspace = true
reth-chainspec.workspace = true
# ethereum
alloy-genesis.workspace = true
# io
shellexpand.workspace = true
serde_json.workspace = true
# misc
eyre.workspace = true
shellexpand.workspace = true
serde_json.workspace = true
[dev-dependencies]
clap.workspace = true
reth-cli-commands.workspace = true

View File

@ -10,3 +10,29 @@
/// Chain specification parser.
pub mod chainspec;
#[cfg(test)]
mod test {
use clap::Parser;
use reth_chainspec::DEV;
use reth_cli_commands::NodeCommand;
#[test]
#[ignore = "reth cmd will print op-reth output if optimism feature enabled"]
fn parse_dev() {
let cmd: NodeCommand = NodeCommand::parse_from(["reth", "--dev"]);
let chain = 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);
}
}

View File

@ -14,9 +14,12 @@ workspace = true
[dependencies]
# reth
reth-chainspec = { workspace = true, features = ["optimism"] }
reth-ethereum-forks = { workspace = true, features = ["optimism"] }
reth-ethereum-forks.workspace = true
reth-primitives-traits.workspace = true
# op-reth
reth-optimism-forks.workspace = true
# ethereum
alloy-chains.workspace = true
alloy-primitives.workspace = true

View File

@ -6,7 +6,8 @@ use alloy_chains::Chain;
use alloy_primitives::{b256, U256};
use once_cell::sync::Lazy;
use reth_chainspec::{once_cell_set, BaseFeeParams, BaseFeeParamsKind, ChainSpec};
use reth_ethereum_forks::{EthereumHardfork, OptimismHardfork};
use reth_ethereum_forks::EthereumHardfork;
use reth_optimism_forks::OptimismHardfork;
use crate::OpChainSpec;

View File

@ -6,7 +6,8 @@ use alloy_chains::Chain;
use alloy_primitives::{b256, U256};
use once_cell::sync::Lazy;
use reth_chainspec::{once_cell_set, BaseFeeParams, BaseFeeParamsKind, ChainSpec};
use reth_ethereum_forks::{EthereumHardfork, OptimismHardfork};
use reth_ethereum_forks::EthereumHardfork;
use reth_optimism_forks::OptimismHardfork;
use crate::OpChainSpec;

View File

@ -6,7 +6,7 @@ use alloy_chains::Chain;
use alloy_primitives::U256;
use once_cell::sync::Lazy;
use reth_chainspec::{once_cell_set, BaseFeeParams, BaseFeeParamsKind, ChainSpec};
use reth_ethereum_forks::DEV_HARDFORKS;
use reth_optimism_forks::DEV_HARDFORKS;
use reth_primitives_traits::constants::DEV_GENESIS_HASH;
use crate::OpChainSpec;

View File

@ -9,10 +9,9 @@
extern crate alloc;
pub mod constants;
mod base;
mod base_sepolia;
pub mod constants;
mod dev;
mod op;
mod op_sepolia;
@ -38,10 +37,8 @@ mod tests {
use alloy_genesis::Genesis;
use alloy_primitives::b256;
use reth_chainspec::{test_fork_ids, BaseFeeParams, BaseFeeParamsKind, ChainSpec};
use reth_ethereum_forks::{
EthereumHardfork, ForkCondition, ForkHash, ForkId, Head, OptimismHardfork,
OptimismHardforks,
};
use reth_ethereum_forks::{EthereumHardfork, ForkCondition, ForkHash, ForkId, Head};
use reth_optimism_forks::{OptimismHardfork, OptimismHardforks};
use crate::*;

View File

@ -6,7 +6,8 @@ use alloy_chains::Chain;
use alloy_primitives::{b256, U256};
use once_cell::sync::Lazy;
use reth_chainspec::{once_cell_set, BaseFeeParams, BaseFeeParamsKind, ChainSpec};
use reth_ethereum_forks::{EthereumHardfork, OptimismHardfork};
use reth_ethereum_forks::EthereumHardfork;
use reth_optimism_forks::OptimismHardfork;
use reth_primitives_traits::constants::ETHEREUM_BLOCK_GAS_LIMIT;
use crate::OpChainSpec;

View File

@ -6,7 +6,8 @@ use alloy_chains::{Chain, NamedChain};
use alloy_primitives::{b256, U256};
use once_cell::sync::Lazy;
use reth_chainspec::{once_cell_set, BaseFeeParams, BaseFeeParamsKind, ChainSpec};
use reth_ethereum_forks::{EthereumHardfork, OptimismHardfork};
use reth_ethereum_forks::EthereumHardfork;
use reth_optimism_forks::OptimismHardfork;
use reth_primitives_traits::constants::ETHEREUM_BLOCK_GAS_LIMIT;
use crate::OpChainSpec;

View File

@ -66,6 +66,7 @@ eyre.workspace = true
tempfile.workspace = true
reth-stages = { workspace = true, features = ["test-utils"] }
reth-db-common.workspace = true
reth-cli-commands.workspace = true
[features]
optimism = [

View File

@ -175,3 +175,28 @@ where
Ok(guard)
}
}
#[cfg(test)]
mod test {
use clap::Parser;
use reth_cli_commands::NodeCommand;
use reth_optimism_chainspec::OP_DEV;
#[test]
fn parse_dev() {
let cmd: NodeCommand = NodeCommand::parse_from(["op-reth", "--dev"]);
let chain = OP_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);
}
}

View File

@ -19,6 +19,9 @@ reth-consensus.workspace = true
reth-primitives.workspace = true
reth-trie-common.workspace = true
# op-reth
reth-optimism-forks.workspace = true
# ethereum
alloy-primitives.workspace = true

View File

@ -10,7 +10,7 @@
#![cfg(feature = "optimism")]
use alloy_primitives::U256;
use reth_chainspec::{ChainSpec, EthereumHardforks, OptimismHardforks};
use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_consensus::{Consensus, ConsensusError, PostExecutionInput};
use reth_consensus_common::validation::{
validate_against_parent_4844, validate_against_parent_eip1559_base_fee,
@ -18,6 +18,7 @@ use reth_consensus_common::validation::{
validate_header_base_fee, validate_header_extradata, validate_header_gas,
validate_shanghai_withdrawals,
};
use reth_optimism_forks::OptimismHardforks;
use reth_primitives::{
BlockWithSenders, GotExpected, Header, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT_HASH,
};

View File

@ -1,7 +1,8 @@
//! Helper function for Receipt root calculation for Optimism hardforks.
use alloy_primitives::B256;
use reth_chainspec::{ChainSpec, OptimismHardfork};
use reth_chainspec::ChainSpec;
use reth_optimism_forks::OptimismHardfork;
use reth_primitives::ReceiptWithBloom;
use reth_trie_common::root::ordered_trie_root_with_encoder;

View File

@ -27,6 +27,7 @@ alloy-primitives.workspace = true
# Optimism
reth-optimism-consensus.workspace = true
reth-optimism-chainspec.workspace = true
reth-optimism-forks.workspace = true
# revm
revm.workspace = true

View File

@ -1,5 +1,6 @@
use reth_chainspec::{ChainSpec, OptimismHardfork};
use reth_chainspec::ChainSpec;
use reth_ethereum_forks::{EthereumHardfork, Head};
use reth_optimism_forks::OptimismHardfork;
/// Returns the revm [`SpecId`](revm_primitives::SpecId) at the given timestamp.
///

View File

@ -4,7 +4,7 @@ use crate::{
l1::ensure_create2_deployer, OpChainSpec, OptimismBlockExecutionError, OptimismEvmConfig,
};
use alloy_primitives::{BlockNumber, U256};
use reth_chainspec::{ChainSpec, EthereumHardforks, OptimismHardfork};
use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_evm::{
execute::{
BatchExecutor, BlockExecutionError, BlockExecutionInput, BlockExecutionOutput,
@ -15,6 +15,7 @@ use reth_evm::{
};
use reth_execution_types::ExecutionOutcome;
use reth_optimism_consensus::validate_block_post_execution;
use reth_optimism_forks::OptimismHardfork;
use reth_primitives::{BlockWithSenders, Header, Receipt, Receipts, TxType};
use reth_prune_types::PruneModes;
use reth_revm::{

View File

@ -2,8 +2,9 @@
use crate::OptimismBlockExecutionError;
use alloy_primitives::{address, b256, hex, Address, Bytes, B256, U256};
use reth_chainspec::{ChainSpec, OptimismHardfork};
use reth_chainspec::ChainSpec;
use reth_execution_errors::BlockExecutionError;
use reth_optimism_forks::OptimismHardfork;
use reth_primitives::Block;
use revm::{
primitives::{Bytecode, HashMap, SpecId},
@ -296,8 +297,8 @@ where
#[cfg(test)]
mod tests {
use reth_chainspec::OptimismHardforks;
use reth_optimism_chainspec::OP_MAINNET;
use reth_optimism_forks::OptimismHardforks;
use reth_primitives::TransactionSigned;
use super::*;

View File

@ -0,0 +1,31 @@
[package]
name = "reth-optimism-forks"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
description = "Optimism hardforks used in op-reth"
[lints]
workspace = true
[dependencies]
# reth
reth-ethereum-forks.workspace = true
# ethereum
alloy-chains.workspace = true
alloy-primitives.workspace = true
# io
serde = { workspace = true, optional = true }
# misc
once_cell.workspace = true
[features]
default = ["std"]
std = []
serde = ["dep:serde"]

View File

@ -0,0 +1,32 @@
use alloy_primitives::U256;
use once_cell::sync::Lazy;
use reth_ethereum_forks::{ChainHardforks, EthereumHardfork, ForkCondition};
/// Dev hardforks
pub static DEV_HARDFORKS: Lazy<ChainHardforks> = Lazy::new(|| {
ChainHardforks::new(vec![
(EthereumHardfork::Frontier.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Homestead.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Dao.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Tangerine.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::SpuriousDragon.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Byzantium.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Constantinople.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Petersburg.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Istanbul.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Berlin.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::London.boxed(), ForkCondition::Block(0)),
(
EthereumHardfork::Paris.boxed(),
ForkCondition::TTD { fork_block: None, total_difficulty: U256::ZERO },
),
(crate::OptimismHardfork::Bedrock.boxed(), ForkCondition::Block(0)),
(crate::OptimismHardfork::Regolith.boxed(), ForkCondition::Timestamp(0)),
(EthereumHardfork::Shanghai.boxed(), ForkCondition::Timestamp(0)),
(crate::OptimismHardfork::Canyon.boxed(), ForkCondition::Timestamp(0)),
(EthereumHardfork::Cancun.boxed(), ForkCondition::Timestamp(0)),
(crate::OptimismHardfork::Ecotone.boxed(), ForkCondition::Timestamp(0)),
(crate::OptimismHardfork::Fjord.boxed(), ForkCondition::Timestamp(0)),
(crate::OptimismHardfork::Granite.boxed(), ForkCondition::Timestamp(0)),
])
});

View File

@ -1,3 +1,5 @@
//! Hard forks of optimism protocol.
use alloc::{boxed::Box, format, string::String, vec};
use core::{
any::Any,
@ -7,11 +9,10 @@ use core::{
use alloy_chains::Chain;
use alloy_primitives::U256;
use reth_ethereum_forks::{hardfork, ChainHardforks, EthereumHardfork, ForkCondition, Hardfork};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::{hardfork, ChainHardforks, EthereumHardfork, ForkCondition, Hardfork};
hardfork!(
/// The name of an optimism hardfork.
///
@ -334,6 +335,8 @@ where
#[cfg(test)]
mod tests {
use std::str::FromStr;
use super::*;
#[test]
@ -347,4 +350,27 @@ mod tests {
Some(9101527)
);
}
#[test]
fn check_op_hardfork_from_str() {
let hardfork_str = ["beDrOck", "rEgOlITH", "cAnYoN", "eCoToNe", "FJorD", "GRaNiTe"];
let expected_hardforks = [
OptimismHardfork::Bedrock,
OptimismHardfork::Regolith,
OptimismHardfork::Canyon,
OptimismHardfork::Ecotone,
OptimismHardfork::Fjord,
OptimismHardfork::Granite,
];
let hardforks: Vec<OptimismHardfork> =
hardfork_str.iter().map(|h| OptimismHardfork::from_str(h).unwrap()).collect();
assert_eq!(hardforks, expected_hardforks);
}
#[test]
fn check_nonexistent_hardfork_from_str() {
assert!(OptimismHardfork::from_str("not a hardfork").is_err());
}
}

View File

@ -1,8 +1,25 @@
use super::Hardforks;
use crate::OptimismHardfork;
//! OP-Reth hard forks.
/// Extends [`crate::EthereumHardforks`] with optimism helper methods.
pub trait OptimismHardforks: Hardforks {
#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
extern crate alloc;
pub mod hardfork;
mod dev;
pub use dev::DEV_HARDFORKS;
pub use hardfork::OptimismHardfork;
use reth_ethereum_forks::EthereumHardforks;
/// Extends [`EthereumHardforks`] with optimism helper methods.
pub trait OptimismHardforks: EthereumHardforks {
/// Convenience method to check if [`OptimismHardfork::Bedrock`] is active at a given block
/// number.
fn is_bedrock_active_at_block(&self, block_number: u64) -> bool {

View File

@ -18,7 +18,6 @@ reth-payload-builder.workspace = true
reth-auto-seal-consensus.workspace = true
reth-basic-payload-builder.workspace = true
reth-consensus.workspace = true
reth-optimism-payload-builder.workspace = true
reth-rpc-types.workspace = true
reth-rpc-types-compat.workspace = true
reth-node-api.workspace = true
@ -29,15 +28,19 @@ reth-transaction-pool.workspace = true
reth-network.workspace = true
reth-evm.workspace = true
reth-revm.workspace = true
reth-evm-optimism.workspace = true
reth-beacon-consensus.workspace = true
reth-optimism-consensus.workspace = true
reth-discv5.workspace = true
reth-rpc-eth-types.workspace = true
reth-rpc-eth-api.workspace = true
reth-optimism-rpc.workspace = true
reth-rpc.workspace = true
# op-reth
reth-optimism-payload-builder.workspace = true
reth-evm-optimism.workspace = true
reth-optimism-rpc.workspace = true
reth-optimism-chainspec.workspace = true
reth-optimism-consensus.workspace = true
reth-optimism-forks.workspace = true
# ethereum
alloy-primitives.workspace = true

View File

@ -1,4 +1,4 @@
use reth_chainspec::{ChainSpec, OptimismHardfork};
use reth_chainspec::ChainSpec;
use reth_node_api::{
payload::{
validate_parent_beacon_block_root_presence, EngineApiMessageVersion,
@ -7,6 +7,7 @@ use reth_node_api::{
},
EngineTypes,
};
use reth_optimism_forks::OptimismHardfork;
use reth_optimism_payload_builder::{OptimismBuiltPayload, OptimismPayloadBuilderAttributes};
use reth_rpc_types::{
engine::ExecutionPayloadEnvelopeV2,

View File

@ -21,7 +21,6 @@ reth-provider.workspace = true
reth-rpc-types.workspace = true
reth-rpc-types-compat.workspace = true
reth-evm.workspace = true
reth-evm-optimism.workspace = true
reth-execution-types.workspace = true
reth-payload-builder.workspace = true
reth-payload-primitives.workspace = true
@ -29,6 +28,10 @@ reth-basic-payload-builder.workspace = true
reth-trie.workspace = true
reth-chain-state.workspace = true
# op-reth
reth-evm-optimism.workspace = true
reth-optimism-forks.workspace = true
# ethereum
revm.workspace = true
alloy-primitives.workspace = true

View File

@ -1,18 +1,17 @@
//! Optimism payload builder implementation.
use crate::{
error::OptimismPayloadBuilderError,
payload::{OptimismBuiltPayload, OptimismPayloadBuilderAttributes},
};
use std::sync::Arc;
use alloy_primitives::U256;
use reth_basic_payload_builder::*;
use reth_chain_state::ExecutedBlock;
use reth_chainspec::{EthereumHardforks, OptimismHardfork};
use reth_chainspec::EthereumHardforks;
use reth_evm::{
system_calls::pre_block_beacon_root_contract_call, ConfigureEvm, ConfigureEvmEnv,
NextBlockEnvAttributes,
};
use reth_execution_types::ExecutionOutcome;
use reth_optimism_forks::OptimismHardfork;
use reth_payload_primitives::{PayloadBuilderAttributes, PayloadBuilderError};
use reth_primitives::{
constants::BEACON_NONCE,
@ -32,9 +31,13 @@ use revm::{
primitives::{EVMError, EnvWithHandlerCfg, InvalidTransaction, ResultAndState},
DatabaseCommit, State,
};
use std::sync::Arc;
use tracing::{debug, trace, warn};
use crate::{
error::OptimismPayloadBuilderError,
payload::{OptimismBuiltPayload, OptimismPayloadBuilderAttributes},
};
/// Optimism's payload builder
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OptimismPayloadBuilder<EvmConfig> {

View File

@ -13,7 +13,6 @@ workspace = true
[dependencies]
# reth
reth-evm-optimism.workspace = true
reth-evm.workspace = true
reth-primitives.workspace = true
reth-provider.workspace = true
@ -29,6 +28,10 @@ reth-network-api.workspace = true
reth-node-builder.workspace = true
reth-chainspec.workspace = true
# op-reth
reth-evm-optimism.workspace = true
reth-optimism-forks.workspace = true
# ethereum
alloy-primitives.workspace = true
op-alloy-network.workspace = true

View File

@ -4,9 +4,10 @@ use op_alloy_consensus::{OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptE
use op_alloy_rpc_types::{
receipt::L1BlockInfo, OpTransactionReceipt, OptimismTransactionReceiptFields,
};
use reth_chainspec::{ChainSpec, OptimismHardforks};
use reth_chainspec::ChainSpec;
use reth_evm_optimism::RethL1BlockInfo;
use reth_node_api::{FullNodeComponents, NodeTypes};
use reth_optimism_forks::OptimismHardforks;
use reth_primitives::{Receipt, TransactionMeta, TransactionSigned, TxType};
use reth_provider::ChainSpecProvider;
use reth_rpc_eth_api::{helpers::LoadReceipt, FromEthApiError, RpcReceipt};

View File

@ -20,7 +20,10 @@ reth-trie-common.workspace = true
revm-primitives = { workspace = true, features = ["serde"] }
reth-chainspec = { workspace = true, optional = true }
reth-codecs = { workspace = true, optional = true }
# op-reth
reth-optimism-chainspec = { workspace = true, optional = true }
reth-optimism-forks = { workspace = true, optional = true }
# ethereum
alloy-consensus.workspace = true
@ -109,11 +112,11 @@ c-kzg = [
]
optimism = [
"reth-chainspec/optimism",
"reth-ethereum-forks/optimism",
"revm-primitives/optimism",
"reth-codecs?/optimism",
"dep:reth-optimism-chainspec",
"dep:op-alloy-consensus",
"reth-optimism-forks",
]
alloy-compat = [
"reth-primitives-traits/alloy-compat",

View File

@ -63,9 +63,12 @@ pub fn calculate_receipt_root_no_memo_optimism(
// encoding. In the Regolith Hardfork, we must strip the deposit nonce from the
// receipts before calculating the receipt root. This was corrected in the Canyon
// hardfork.
if chain_spec.is_fork_active_at_timestamp(reth_chainspec::OptimismHardfork::Regolith, timestamp) &&
!chain_spec
.is_fork_active_at_timestamp(reth_chainspec::OptimismHardfork::Canyon, timestamp)
if chain_spec
.is_fork_active_at_timestamp(reth_optimism_forks::OptimismHardfork::Regolith, timestamp) &&
!chain_spec.is_fork_active_at_timestamp(
reth_optimism_forks::OptimismHardfork::Canyon,
timestamp,
)
{
let receipts = receipts
.iter()