feat(primitives): add Hardfork::Eip150 and Eip158 (#925)

This commit is contained in:
Dan Cline
2023-01-18 18:04:16 -05:00
committed by GitHub
parent 9a2f265d6f
commit 82b10fae41
3 changed files with 32 additions and 22 deletions

View File

@@ -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"),

View File

@@ -18,7 +18,8 @@ pub static MAINNET: Lazy<ChainSpec> = 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<EthersGenesis> 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<EthersGenesis> 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));

View File

@@ -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<ForkId> {
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<ForkFilter> {
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)