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

use op-alloy genesis types for genesis parsing #9292

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { version = "0.1" }
nkysg marked this conversation as resolved.
Show resolved Hide resolved

# misc
auto_impl = "1"
aquamarine = "0.5"
Expand Down
3 changes: 3 additions & 0 deletions crates/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ alloy-genesis.workspace = true
alloy-primitives = { workspace = true, features = ["rand", "rlp"] }
alloy-trie.workspace = true

# op
op-alloy-rpc-types.workspace = true
nkysg marked this conversation as resolved.
Show resolved Hide resolved

# misc
once_cell.workspace = true
serde = { workspace = true, optional = true }
Expand Down
38 changes: 15 additions & 23 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ use reth_network_peers::{
op_testnet_nodes, sepolia_nodes,
};

#[cfg(feature = "optimism")]
use op_alloy_rpc_types::genesis::{OptimismBaseFeeInfo, OptimismGenesisInfo as OpGenesisInfo};

/// The Ethereum mainnet spec
pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
Expand Down Expand Up @@ -748,7 +751,7 @@ impl From<Genesis> 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(), optimism_genesis_info.genesis_info.bedrock_block),
];
let mut hardforks = hardfork_opts
.into_iter()
Expand Down Expand Up @@ -777,13 +780,13 @@ impl From<Genesis> 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(), optimism_genesis_info.genesis_info.regolith_time),
#[cfg(feature = "optimism")]
(OptimismHardfork::Canyon.boxed(), optimism_genesis_info.canyon_time),
(OptimismHardfork::Canyon.boxed(), optimism_genesis_info.genesis_info.canyon_time),
#[cfg(feature = "optimism")]
(OptimismHardfork::Ecotone.boxed(), optimism_genesis_info.ecotone_time),
(OptimismHardfork::Ecotone.boxed(), optimism_genesis_info.genesis_info.ecotone_time),
#[cfg(feature = "optimism")]
(OptimismHardfork::Fjord.boxed(), optimism_genesis_info.fjord_time),
(OptimismHardfork::Fjord.boxed(), optimism_genesis_info.genesis_info.fjord_time),
];

let time_hardforks = time_hardfork_opts
Expand Down Expand Up @@ -1085,32 +1088,21 @@ impl DepositContract {
#[derive(Default, Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct OptimismGenesisInfo {
bedrock_block: Option<u64>,
regolith_time: Option<u64>,
canyon_time: Option<u64>,
ecotone_time: Option<u64>,
fjord_time: Option<u64>,
genesis_info: OpGenesisInfo,
nkysg marked this conversation as resolved.
Show resolved Hide resolved
#[serde(skip)]
base_fee_params: BaseFeeParamsKind,
}

#[cfg(feature = "optimism")]
#[derive(Debug, Eq, PartialEq, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct OptimismBaseFeeInfo {
eip1559_elasticity: Option<u64>,
eip1559_denominator: Option<u64>,
eip1559_denominator_canyon: Option<u64>,
}

#[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();
let mut optimism_genesis_info = OptimismGenesisInfo::default();
if let Some(genesis_info) = OpGenesisInfo::extract_from(&genesis.config.extra_fields) {
optimism_genesis_info.genesis_info = genesis_info;
}

if let Some(Ok(optimism_base_fee_info)) =
genesis.config.extra_fields.get_deserialized::<OptimismBaseFeeInfo>("optimism")
if let Some(optimism_base_fee_info) =
OptimismBaseFeeInfo::extract_from(&genesis.config.extra_fields)
nkysg marked this conversation as resolved.
Show resolved Hide resolved
{
if let (Some(elasticity), Some(denominator)) = (
optimism_base_fee_info.eip1559_elasticity,
Expand Down