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

feat: add activation_block method for Ethereum hardforks #5723

Merged
merged 6 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/ethereum-forks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ workspace = true
reth-codecs.workspace = true

# ethereum
alloy-chains.workspace = true
alloy-primitives = { workspace = true, features = ["rand", "rlp"] }
alloy-rlp = { workspace = true, features = ["arrayvec"] }

Expand Down
40 changes: 39 additions & 1 deletion crates/ethereum-forks/src/hardfork.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy_chains::Chain;
use serde::{Deserialize, Serialize};

use std::{fmt::Display, str::FromStr};

/// The name of an Ethereum hardfork.
Expand Down Expand Up @@ -51,6 +51,44 @@ pub enum Hardfork {
Cancun,
}

impl Hardfork {
/// Retrieves the activation block for the specified hardfork on the Ethereum mainnet.
pub fn mainnet_activation_block(&self, chain: Chain) -> Option<u64> {
if chain != Chain::mainnet() {
return None;
}
match self {
Hardfork::Frontier => Some(0),
Hardfork::Homestead => Some(1150000),
Hardfork::Dao => Some(1920000),
Hardfork::Tangerine => Some(2463000),
Hardfork::SpuriousDragon => Some(2675000),
Hardfork::Byzantium => Some(4370000),
Hardfork::Constantinople => Some(7280000),
Hardfork::Petersburg => Some(7280000),
Hardfork::Istanbul => Some(9069000),
Hardfork::MuirGlacier => Some(9200000),
Hardfork::Berlin => Some(12244000),
Hardfork::London => Some(12965000),
Hardfork::ArrowGlacier => Some(13773000),
Hardfork::GrayGlacier => Some(15050000),
Hardfork::Paris => Some(15537394),
Hardfork::Shanghai => Some(17034870),

// upcoming hardforks
Hardfork::Cancun => None,

// optimism hardforks
#[cfg(feature = "optimism")]
Hardfork::Bedrock => None,
#[cfg(feature = "optimism")]
Hardfork::Regolith => None,
#[cfg(feature = "optimism")]
Hardfork::Canyon => None,
}
}
}

impl FromStr for Hardfork {
type Err = String;

Expand Down
Loading