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
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
31 changes: 31 additions & 0 deletions crates/ethereum-forks/src/hardfork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,37 @@ pub enum Hardfork {
Cancun,
}

impl Hardfork {
/// Returns the activation block number for each Ethereum hardfork.
pub fn activation_block(&self) -> Option<u64> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can rename this to mainnet_activation_block

but what we want here is activation_block(&self, chain: Chain)
see referenced foundry issue.
I'm fine if fn activation_block only handles Chain::mainnet in this PR
we don't have to fill all blocks for other chains, just to have it so they can be added one by one.
this will mostly be useful for foundry because I intend to use it in anvil eventually

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattsse In this case, isn't it better to implement this method for the enum Chain itself by doing activation_block(&self, hardfork: Hardfork)? Because otherwise we have a circular dependency, right? Because the reth-primitives crate itself uses the Hardfork enum. Maybe I'm missing something here.

Also, I wanted to fill in the block activations for certain L2s but do you know where I could have the precise information for each of them? There is no equivalent to the precise Ethereum specification https://ethereum.github.io/execution-specs/autoapi/ethereum/index.html for the other L2s.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd like to migrate to alloy-chains now #5429 which gets rid of the circular dep issue, looks like this is a blocker for this PR

I want this functionality in Hardfork and not chainid, so chain crate stays lean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattsse Please tell me if this is better now.

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),
#[cfg(feature = "optimism")]
Hardfork::Bedrock => None,
#[cfg(feature = "optimism")]
Hardfork::Regolith => None,
Hardfork::Shanghai => Some(17034870),
#[cfg(feature = "optimism")]
Hardfork::Canyon => None,
Hardfork::Cancun => None,
}
}
}

impl FromStr for Hardfork {
type Err = String;

Expand Down
Loading