Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 23 additions & 4 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
sepolia::SEPOLIA_PARIS_BLOCK,
EthChainSpec,
};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloc::{boxed::Box, format, sync::Arc, vec::Vec};
use alloy_chains::{Chain, NamedChain};
use alloy_consensus::{
constants::{
Expand Down Expand Up @@ -440,7 +440,26 @@ impl<H: BlockHeader> ChainSpec<H> {

/// Returns the hardfork display helper.
pub fn display_hardforks(&self) -> DisplayHardforks {
DisplayHardforks::new(self.hardforks.forks_iter())
// Create an iterator with hardfork, condition, and optional blob metadata
let hardforks_with_meta = self.hardforks.forks_iter().map(|(fork, condition)| {
// Generate blob metadata for timestamp-based hardforks that have blob params
let metadata = match condition {
ForkCondition::Timestamp(timestamp) => {
// Try to get blob params for this timestamp
// This automatically handles all hardforks with blob support
EthChainSpec::blob_params_at_timestamp(self, timestamp).map(|params| {
format!(
"blob: (target: {}, max: {}, fraction: {})",
params.target_blob_count, params.max_blob_count, params.update_fraction
)
})
}
_ => None,
};
(fork, condition, metadata)
});

DisplayHardforks::with_meta(hardforks_with_meta)
}

/// Get the fork id for the given hardfork.
Expand Down Expand Up @@ -1157,8 +1176,8 @@ Merge hard forks:
- Paris @58750000000000000000000 (network is known to be merged)
Post-merge hard forks (timestamp based):
- Shanghai @1681338455
- Cancun @1710338135
- Prague @1746612311"
- Cancun @1710338135 blob: (target: 3, max: 6, fraction: 3338477)
- Prague @1746612311 blob: (target: 6, max: 9, fraction: 5007716)"
);
}

Expand Down
27 changes: 24 additions & 3 deletions crates/ethereum/hardforks/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct DisplayFork {
activated_at: ForkCondition,
/// An optional EIP (e.g. `EIP-1559`).
eip: Option<String>,
/// Optional metadata to display alongside the fork (e.g. blob parameters)
metadata: Option<String>,
}

impl core::fmt::Display for DisplayFork {
Expand All @@ -38,13 +40,19 @@ impl core::fmt::Display for DisplayFork {
match self.activated_at {
ForkCondition::Block(at) | ForkCondition::Timestamp(at) => {
write!(f, "{name_with_eip:32} @{at}")?;
if let Some(metadata) = &self.metadata {
write!(f, " {metadata}")?;
}
}
ForkCondition::TTD { total_difficulty, .. } => {
// All networks that have merged are finalized.
write!(
f,
"{name_with_eip:32} @{total_difficulty} (network is known to be merged)",
)?;
if let Some(metadata) = &self.metadata {
write!(f, " {metadata}")?;
}
}
ForkCondition::Never => unreachable!(),
}
Expand Down Expand Up @@ -145,14 +153,27 @@ impl DisplayHardforks {
pub fn new<'a, I>(hardforks: I) -> Self
where
I: IntoIterator<Item = (&'a dyn Hardfork, ForkCondition)>,
{
// Delegate to with_meta by mapping the iterator to include None for metadata
Self::with_meta(hardforks.into_iter().map(|(fork, condition)| (fork, condition, None)))
}

/// Creates a new [`DisplayHardforks`] from an iterator of hardforks with optional metadata.
pub fn with_meta<'a, I>(hardforks: I) -> Self
where
I: IntoIterator<Item = (&'a dyn Hardfork, ForkCondition, Option<String>)>,
{
let mut pre_merge = Vec::new();
let mut with_merge = Vec::new();
let mut post_merge = Vec::new();

for (fork, condition) in hardforks {
let mut display_fork =
DisplayFork { name: fork.name().to_string(), activated_at: condition, eip: None };
for (fork, condition, metadata) in hardforks {
let mut display_fork = DisplayFork {
name: fork.name().to_string(),
activated_at: condition,
eip: None,
metadata,
};

match condition {
ForkCondition::Block(_) => {
Expand Down