Skip to content

Commit

Permalink
feat: add activation_block method for Ethereum hardforks (#5723)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
tcoratger and mattsse authored Jan 13, 2024
1 parent 8761072 commit b08371b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
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

0 comments on commit b08371b

Please sign in to comment.