From 82b10fae41705f8dfa19dbf040c96e741103987f Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 18 Jan 2023 18:04:16 -0500 Subject: [PATCH] feat(primitives): add Hardfork::Eip150 and Eip158 (#925) --- crates/executor/src/config.rs | 3 ++- crates/primitives/src/chain_spec.rs | 19 +++++++++-------- crates/primitives/src/hardfork.rs | 32 ++++++++++++++++++----------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/crates/executor/src/config.rs b/crates/executor/src/config.rs index 3f161a3061..b6b5e4d0a2 100644 --- a/crates/executor/src/config.rs +++ b/crates/executor/src/config.rs @@ -20,7 +20,8 @@ pub fn revm_spec(chain_spec: &ChainSpec, for_block: BlockNumber) -> revm::SpecId b if chain_spec.fork_active(Hardfork::Petersburg, b) => revm::PETERSBURG, b if chain_spec.fork_active(Hardfork::Byzantium, b) => revm::BYZANTIUM, b if chain_spec.fork_active(Hardfork::SpuriousDragon, b) => revm::SPURIOUS_DRAGON, - b if chain_spec.fork_active(Hardfork::Tangerine, b) => revm::TANGERINE, + b if chain_spec.fork_active(Hardfork::Eip150, b) => revm::TANGERINE, + b if chain_spec.fork_active(Hardfork::Eip158, b) => revm::TANGERINE, b if chain_spec.fork_active(Hardfork::Homestead, b) => revm::HOMESTEAD, b if chain_spec.fork_active(Hardfork::Frontier, b) => revm::FRONTIER, _ => panic!("wrong configuration"), diff --git a/crates/primitives/src/chain_spec.rs b/crates/primitives/src/chain_spec.rs index d01a1c3762..ec9f386653 100644 --- a/crates/primitives/src/chain_spec.rs +++ b/crates/primitives/src/chain_spec.rs @@ -18,7 +18,8 @@ pub static MAINNET: Lazy = Lazy::new(|| ChainSpec { (Hardfork::Frontier, 0), (Hardfork::Homestead, 1150000), (Hardfork::Dao, 1920000), - (Hardfork::Tangerine, 2463000), + (Hardfork::Eip150, 2463000), + (Hardfork::Eip158, 2463000), (Hardfork::SpuriousDragon, 2675000), (Hardfork::Byzantium, 4370000), (Hardfork::Constantinople, 7280000), @@ -200,9 +201,8 @@ impl From for ChainSpec { let hardfork_opts = vec![ (Hardfork::Homestead, genesis.config.homestead_block), (Hardfork::Dao, genesis.config.dao_fork_block), - (Hardfork::Tangerine, genesis.config.eip150_block), - // TODO: eip-158 was also activated when eip-155 was activated, but we don't have the - // proper hardfork identifier for it. this breaks the hardfork abstraction slightly + (Hardfork::Eip150, genesis.config.eip150_block), + (Hardfork::Eip158, genesis.config.eip158_block), (Hardfork::SpuriousDragon, genesis.config.eip155_block), (Hardfork::Byzantium, genesis.config.byzantium_block), (Hardfork::Constantinople, genesis.config.constantinople_block), @@ -213,8 +213,7 @@ impl From for ChainSpec { (Hardfork::London, genesis.config.london_block), (Hardfork::ArrowGlacier, genesis.config.arrow_glacier_block), (Hardfork::GrayGlacier, genesis.config.gray_glacier_block), - // TODO: similar problem as eip-158, but with the merge netsplit block. only used in - // sepolia, but required for proper forkid generation + (Hardfork::MergeNetsplit, genesis.config.merge_netsplit_block), ]; let configured_hardforks = hardfork_opts @@ -301,7 +300,8 @@ impl ChainSpecBuilder { /// Enables Tangerine pub fn tangerine_whistle_activated(mut self) -> Self { self = self.homestead_activated(); - self.hardforks.insert(Hardfork::Tangerine, 0); + self.hardforks.insert(Hardfork::Eip150, 0); + self.hardforks.insert(Hardfork::Eip158, 0); self } @@ -440,7 +440,8 @@ mod tests { .genesis_hash(empty_sealed.hash()) .with_fork(Hardfork::Frontier, 0) .with_fork(Hardfork::Homestead, 0) - .with_fork(Hardfork::Tangerine, 0) + .with_fork(Hardfork::Eip150, 0) + .with_fork(Hardfork::Eip158, 0) .with_fork(Hardfork::SpuriousDragon, 0) .with_fork(Hardfork::Byzantium, 0) .with_fork(Hardfork::Constantinople, 0) @@ -480,7 +481,7 @@ mod tests { .genesis_hash(empty_sealed.hash()) .with_fork(Hardfork::Frontier, 0) .with_fork(Hardfork::Homestead, 1) - .with_fork(Hardfork::Tangerine, 1) + .with_fork(Hardfork::Eip150, 1) .build(); assert_eq!(unique_spec.fork_id(2), duplicate_spec.fork_id(2)); diff --git a/crates/primitives/src/hardfork.rs b/crates/primitives/src/hardfork.rs index 0b6eea9ecf..0537497f89 100644 --- a/crates/primitives/src/hardfork.rs +++ b/crates/primitives/src/hardfork.rs @@ -12,7 +12,8 @@ pub enum Hardfork { Frontier, Homestead, Dao, - Tangerine, + Eip150, + Eip158, SpuriousDragon, Byzantium, Constantinople, @@ -32,6 +33,9 @@ pub enum Hardfork { impl Hardfork { /// Compute the forkid for the given [`ChainSpec`]. /// + /// This assumes the current hardfork's block number is the current head and uses known future + /// hardforks from the [`ChainSpec`] to set the forkid's `next` field. + /// /// If the hard fork is not present in the [`ChainSpec`] then `None` is returned. pub fn fork_id(&self, chain_spec: &ChainSpec) -> Option { if let Some(fork_block) = chain_spec.fork_block(*self) { @@ -56,6 +60,9 @@ impl Hardfork { /// Creates a [`ForkFilter`](crate::ForkFilter) for the given hardfork. /// + /// This assumes the current hardfork's block number is the current head and uses known future + /// hardforks from the [`ChainSpec`] to initialize the filter. + /// /// This returns `None` if the hardfork is not present in the given [`ChainSpec`]. pub fn fork_filter(&self, chain_spec: &ChainSpec) -> Option { if let Some(fork_block) = chain_spec.fork_block(*self) { @@ -79,18 +86,19 @@ impl FromStr for Hardfork { "frontier" | "1" => Hardfork::Frontier, "homestead" | "2" => Hardfork::Homestead, "dao" | "3" => Hardfork::Dao, - "tangerine" | "4" => Hardfork::Tangerine, - "spuriousdragon" | "5" => Hardfork::SpuriousDragon, - "byzantium" | "6" => Hardfork::Byzantium, - "constantinople" | "7" => Hardfork::Constantinople, - "petersburg" | "8" => Hardfork::Petersburg, - "istanbul" | "9" => Hardfork::Istanbul, - "muirglacier" | "10" => Hardfork::Muirglacier, - "berlin" | "11" => Hardfork::Berlin, - "london" | "12" => Hardfork::London, - "arrowglacier" | "13" => Hardfork::ArrowGlacier, + "eip150" | "4" => Hardfork::Eip150, + "eip158" | "5" => Hardfork::Eip158, + "spuriousdragon" | "6" => Hardfork::SpuriousDragon, + "byzantium" | "7" => Hardfork::Byzantium, + "constantinople" | "8" => Hardfork::Constantinople, + "petersburg" | "9" => Hardfork::Petersburg, + "istanbul" | "10" => Hardfork::Istanbul, + "muirglacier" | "11" => Hardfork::Muirglacier, + "berlin" | "12" => Hardfork::Berlin, + "london" | "13" => Hardfork::London, + "arrowglacier" | "14" => Hardfork::ArrowGlacier, "grayglacier" => Hardfork::GrayGlacier, - "latest" | "14" => Hardfork::Latest, + "latest" | "15" => Hardfork::Latest, _ => return Err(format!("Unknown hardfork {s}")), }; Ok(hardfork)