diff --git a/Cargo.lock b/Cargo.lock index bdae392a39f6..f746eaca26a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5325,6 +5325,35 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "op-alloy-consensus" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "767fd3026c514f4d2ebdb4ebda5ed8857660dd1ef5bfed2aaa2ae8e42019630e" +dependencies = [ + "alloy-consensus", + "alloy-eips", + "alloy-primitives", + "alloy-rlp", + "alloy-serde", + "serde", +] + +[[package]] +name = "op-alloy-rpc-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c50d6e6767b0b21efc9efb40fc0802ad6d28321c66ff17f1aaa46003cd234d4d" +dependencies = [ + "alloy-network", + "alloy-primitives", + "alloy-rpc-types-eth", + "alloy-serde", + "op-alloy-consensus", + "serde", + "serde_json", +] + [[package]] name = "opaque-debug" version = "0.3.1" @@ -6556,6 +6585,7 @@ dependencies = [ "derive_more", "nybbles", "once_cell", + "op-alloy-rpc-types", "rand 0.8.5", "reth-ethereum-forks", "reth-network-peers", diff --git a/Cargo.toml b/Cargo.toml index ceb9c9532083..537f7f3cf1a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -419,6 +419,9 @@ alloy-pubsub = { version = "0.1", default-features = false } alloy-json-rpc = { version = "0.1", default-features = false } alloy-rpc-client = { version = "0.1", default-features = false } +# op +op-alloy-rpc-types = "0.1" + # misc auto_impl = "1" aquamarine = "0.5" diff --git a/crates/chainspec/Cargo.toml b/crates/chainspec/Cargo.toml index f473acc4b20a..e4574acdace9 100644 --- a/crates/chainspec/Cargo.toml +++ b/crates/chainspec/Cargo.toml @@ -24,6 +24,10 @@ alloy-genesis.workspace = true alloy-primitives = { workspace = true, features = ["rand", "rlp"] } alloy-trie.workspace = true +# op +op-alloy-rpc-types = { workspace = true, optional = true } + + # misc once_cell.workspace = true serde = { workspace = true, optional = true } @@ -40,11 +44,15 @@ alloy-genesis.workspace = true reth-rpc-types.workspace = true rand.workspace = true +# op +op-alloy-rpc-types.workspace = true + [features] default = ["std"] optimism = [ "reth-ethereum-forks/optimism", - "serde" + "serde", + "dep:op-alloy-rpc-types", ] std = [] arbitrary = [ diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 33ca2f4f0244..4b1083f60aab 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -731,6 +731,9 @@ impl From for ChainSpec { fn from(genesis: Genesis) -> Self { #[cfg(feature = "optimism")] let optimism_genesis_info = OptimismGenesisInfo::extract_from(&genesis); + #[cfg(feature = "optimism")] + let genesis_info = + optimism_genesis_info.optimism_chain_info.genesis_info.unwrap_or_default(); // Block-based hardforks let hardfork_opts = [ @@ -748,7 +751,7 @@ impl From for ChainSpec { (EthereumHardfork::ArrowGlacier.boxed(), genesis.config.arrow_glacier_block), (EthereumHardfork::GrayGlacier.boxed(), genesis.config.gray_glacier_block), #[cfg(feature = "optimism")] - (OptimismHardfork::Bedrock.boxed(), optimism_genesis_info.bedrock_block), + (OptimismHardfork::Bedrock.boxed(), genesis_info.bedrock_block), ]; let mut hardforks = hardfork_opts .into_iter() @@ -777,13 +780,13 @@ impl From for ChainSpec { (EthereumHardfork::Cancun.boxed(), genesis.config.cancun_time), (EthereumHardfork::Prague.boxed(), genesis.config.prague_time), #[cfg(feature = "optimism")] - (OptimismHardfork::Regolith.boxed(), optimism_genesis_info.regolith_time), + (OptimismHardfork::Regolith.boxed(), genesis_info.regolith_time), #[cfg(feature = "optimism")] - (OptimismHardfork::Canyon.boxed(), optimism_genesis_info.canyon_time), + (OptimismHardfork::Canyon.boxed(), genesis_info.canyon_time), #[cfg(feature = "optimism")] - (OptimismHardfork::Ecotone.boxed(), optimism_genesis_info.ecotone_time), + (OptimismHardfork::Ecotone.boxed(), genesis_info.ecotone_time), #[cfg(feature = "optimism")] - (OptimismHardfork::Fjord.boxed(), optimism_genesis_info.fjord_time), + (OptimismHardfork::Fjord.boxed(), genesis_info.fjord_time), ]; let time_hardforks = time_hardfork_opts @@ -1085,33 +1088,22 @@ impl DepositContract { #[derive(Default, Debug, serde::Deserialize)] #[serde(rename_all = "camelCase")] struct OptimismGenesisInfo { - bedrock_block: Option, - regolith_time: Option, - canyon_time: Option, - ecotone_time: Option, - fjord_time: Option, + optimism_chain_info: op_alloy_rpc_types::genesis::OptimismChainInfo, #[serde(skip)] base_fee_params: BaseFeeParamsKind, } -#[cfg(feature = "optimism")] -#[derive(Debug, Eq, PartialEq, serde::Deserialize)] -#[serde(rename_all = "camelCase")] -struct OptimismBaseFeeInfo { - eip1559_elasticity: Option, - eip1559_denominator: Option, - eip1559_denominator_canyon: Option, -} - #[cfg(feature = "optimism")] impl OptimismGenesisInfo { fn extract_from(genesis: &Genesis) -> Self { - let mut optimism_genesis_info: Self = - genesis.config.extra_fields.deserialize_as().unwrap_or_default(); - - if let Some(Ok(optimism_base_fee_info)) = - genesis.config.extra_fields.get_deserialized::("optimism") - { + let mut info = Self { + optimism_chain_info: op_alloy_rpc_types::genesis::OptimismChainInfo::extract_from( + &genesis.config.extra_fields, + ) + .unwrap_or_default(), + ..Default::default() + }; + if let Some(optimism_base_fee_info) = &info.optimism_chain_info.base_fee_info { if let (Some(elasticity), Some(denominator)) = ( optimism_base_fee_info.eip1559_elasticity, optimism_base_fee_info.eip1559_denominator, @@ -1136,11 +1128,11 @@ impl OptimismGenesisInfo { BaseFeeParams::new(denominator as u128, elasticity as u128).into() }; - optimism_genesis_info.base_fee_params = base_fee_params; + info.base_fee_params = base_fee_params; } } - optimism_genesis_info + info } } @@ -2902,6 +2894,8 @@ Post-merge hard forks (timestamp based): #[cfg(feature = "optimism")] #[test] fn parse_genesis_optimism_with_variable_base_fee_params() { + use op_alloy_rpc_types::genesis::OptimismBaseFeeInfo; + let geth_genesis = r#" { "config": {