feat: display blob params alongside hardfork info (#19358)

This commit is contained in:
leniram159
2025-10-29 21:34:31 +01:00
committed by GitHub
parent 1ed41d5151
commit be50b284b3
2 changed files with 47 additions and 7 deletions

View File

@@ -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::{
@@ -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.
@@ -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)"
);
}

View File

@@ -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 {
@@ -38,6 +40,9 @@ 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.
@@ -45,6 +50,9 @@ impl core::fmt::Display for DisplayFork {
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!(),
}
@@ -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(_) => {