feat: add opstack specific display_hardforks implementation (#15233)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Varun Doshi
2025-03-26 14:20:25 +05:30
committed by GitHub
parent 0a6b546105
commit 790b49e00a
6 changed files with 34 additions and 14 deletions

View File

@@ -478,7 +478,7 @@ impl ChainSpec {
/// Returns the hardfork display helper.
pub fn display_hardforks(&self) -> DisplayHardforks {
DisplayHardforks::new(&self)
DisplayHardforks::new(self.hardforks.forks_iter())
}
/// Get the fork id for the given hardfork.

View File

@@ -1,9 +1,10 @@
use crate::{hardforks::Hardforks, ForkCondition};
use crate::ForkCondition;
use alloc::{
format,
string::{String, ToString},
vec::Vec,
};
use alloy_hardforks::Hardfork;
/// A container to pretty-print a hardfork.
///
@@ -136,12 +137,15 @@ impl core::fmt::Display for DisplayHardforks {
impl DisplayHardforks {
/// Creates a new [`DisplayHardforks`] from an iterator of hardforks.
pub fn new<H: Hardforks>(hardforks: &H) -> Self {
pub fn new<'a, I>(hardforks: I) -> Self
where
I: IntoIterator<Item = (&'a dyn Hardfork, ForkCondition)>,
{
let mut pre_merge = Vec::new();
let mut with_merge = Vec::new();
let mut post_merge = Vec::new();
for (fork, condition) in hardforks.forks_iter() {
for (fork, condition) in hardforks {
let mut display_fork =
DisplayFork { name: fork.name().to_string(), activated_at: condition, eip: None };

View File

@@ -28,6 +28,7 @@ alloy-genesis.workspace = true
alloy-primitives.workspace = true
alloy-consensus.workspace = true
alloy-eips.workspace = true
alloy-hardforks.workspace = true
# op
op-alloy-rpc-types.workspace = true

View File

@@ -22,6 +22,7 @@ use alloy_chains::Chain;
use alloy_consensus::{proofs::storage_root_unhashed, Header};
use alloy_eips::eip7840::BlobParams;
use alloy_genesis::Genesis;
use alloy_hardforks::Hardfork;
use alloy_primitives::{B256, U256};
pub use base::BASE_MAINNET;
pub use base_sepolia::BASE_SEPOLIA;
@@ -30,10 +31,10 @@ pub use dev::OP_DEV;
pub use op::OP_MAINNET;
pub use op_sepolia::OP_SEPOLIA;
use reth_chainspec::{
BaseFeeParams, BaseFeeParamsKind, ChainSpec, ChainSpecBuilder, DepositContract, EthChainSpec,
EthereumHardforks, ForkFilter, ForkId, Hardforks, Head,
BaseFeeParams, BaseFeeParamsKind, ChainSpec, ChainSpecBuilder, DepositContract,
DisplayHardforks, EthChainSpec, EthereumHardforks, ForkFilter, ForkId, Hardforks, Head,
};
use reth_ethereum_forks::{ChainHardforks, EthereumHardfork, ForkCondition, Hardfork};
use reth_ethereum_forks::{ChainHardforks, EthereumHardfork, ForkCondition};
use reth_network_peers::NodeRecord;
use reth_optimism_forks::{OpHardfork, OpHardforks, OP_MAINNET_HARDFORKS};
use reth_optimism_primitives::ADDRESS_L2_TO_L1_MESSAGE_PASSER;
@@ -227,7 +228,12 @@ impl EthChainSpec for OpChainSpec {
}
fn display_hardforks(&self) -> Box<dyn core::fmt::Display> {
Box::new(ChainSpec::display_hardforks(self))
// filter only op hardforks
let op_forks = self.inner.hardforks.forks_iter().filter(|(fork, _)| {
!EthereumHardfork::VARIANTS.iter().any(|h| h.name() == (*fork).name())
});
Box::new(DisplayHardforks::new(op_forks))
}
fn genesis_header(&self) -> &Self::Header {
@@ -1055,4 +1061,12 @@ mod tests {
let chainspec = OpChainSpec::from_genesis(genesis);
assert!(chainspec.is_holocene_active_at_timestamp(1732633200));
}
#[test]
fn display_hardorks() {
let content = BASE_MAINNET.display_hardforks().to_string();
for eth_hf in EthereumHardfork::VARIANTS {
assert!(!content.contains(eth_hf.name()));
}
}
}