From 3d77d95aa568bf0ef97e116772bbd42d9ddc197e Mon Sep 17 00:00:00 2001 From: Tomas Milukas Date: Tue, 31 Dec 2024 03:34:20 +0100 Subject: [PATCH 1/6] changes --- crates/chainspec/src/spec.rs | 54 +++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 755b892d976f..7c4d7f8cc158 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeMap; + pub use alloy_eips::eip1559::BaseFeeParams; use crate::{constants::MAINNET_DEPOSIT_CONTRACT, once_cell_set, EthChainSpec, LazyLock, OnceLock}; @@ -12,7 +14,7 @@ use alloy_consensus::{ }; use alloy_eips::{ eip1559::INITIAL_BASE_FEE, eip6110::MAINNET_DEPOSIT_CONTRACT_ADDRESS, - eip7685::EMPTY_REQUESTS_HASH, + eip7685::EMPTY_REQUESTS_HASH, eip7840::{BlobParams, BlobScheduleItem}, }; use alloy_genesis::Genesis; use alloy_primitives::{address, b256, Address, BlockNumber, B256, U256}; @@ -50,6 +52,7 @@ pub static MAINNET: LazyLock> = LazyLock::new(|| { )), base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), prune_delete_limit: 20000, + blob_params: HardforkBlobParams::default(), }; spec.genesis.config.dao_fork_support = true; spec.into() @@ -74,6 +77,7 @@ pub static SEPOLIA: LazyLock> = LazyLock::new(|| { )), base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), prune_delete_limit: 10000, + blob_params: HardforkBlobParams::default(), }; spec.genesis.config.dao_fork_support = true; spec.into() @@ -96,6 +100,7 @@ pub static HOLESKY: LazyLock> = LazyLock::new(|| { )), base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), prune_delete_limit: 10000, + blob_params: HardforkBlobParams::default(), }; spec.genesis.config.dao_fork_support = true; spec.into() @@ -154,6 +159,45 @@ impl From for BaseFeeParamsKind { #[derive(Clone, Debug, PartialEq, Eq, From)] pub struct ForkBaseFeeParams(Vec<(Box, BaseFeeParams)>); +/// A container for hardforks that use eip-7804 blobs. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct HardforkBlobParams { + pub cancun: BlobParams, + pub prague: BlobParams, +} + +impl HardforkBlobParams { + /// Constructs params for chainspec from a provided blob schedule. + /// Falls back to defaults if the schedule is empty. + pub fn from_schedule(blob_schedule: &BTreeMap) -> Self { + + let extract = |key: &str, default: fn() -> BlobParams| { + blob_schedule + .get(key) + .map(|item| BlobParams { + target_blob_count: item.target_blob_count, + max_blob_count: item.max_blob_count, + ..default() + }) + .unwrap_or_else(default) // Use default if key is missing + }; + + Self { + cancun: extract("cancun", BlobParams::cancun), + prague: extract("prague", BlobParams::prague), + } + } +} + +impl Default for HardforkBlobParams { + fn default() -> Self { + Self { + cancun: BlobParams::cancun(), + prague: BlobParams::prague(), + } + } +} + impl core::ops::Deref for ChainSpec { type Target = ChainHardforks; @@ -204,6 +248,9 @@ pub struct ChainSpec { /// The delete limit for pruner, per run. pub prune_delete_limit: usize, + + /// The settings passed for blob configurations for specific hardforks. + pub blob_params: HardforkBlobParams, } impl Default for ChainSpec { @@ -218,6 +265,7 @@ impl Default for ChainSpec { deposit_contract: Default::default(), base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), prune_delete_limit: MAINNET.prune_delete_limit, + blob_params: Default::default() } } } @@ -669,6 +717,9 @@ impl From for ChainSpec { // append the remaining unknown hardforks to ensure we don't filter any out ordered_hardforks.append(&mut hardforks); + // Extract blob parameters directly from blob_schedule + let blob_params = HardforkBlobParams::from_schedule(&genesis.config.blob_schedule); + // NOTE: in full node, we prune all receipts except the deposit contract's. We do not // have the deployment block in the genesis file, so we use block zero. We use the same // deposit topic as the mainnet contract if we have the deposit contract address in the @@ -684,6 +735,7 @@ impl From for ChainSpec { hardforks: ChainHardforks::new(ordered_hardforks), paris_block_and_final_difficulty, deposit_contract, + blob_params, ..Default::default() } } From cf98c98f20731802f090b9eb60017e447b176737 Mon Sep 17 00:00:00 2001 From: Tomas Milukas Date: Tue, 31 Dec 2024 03:46:30 +0100 Subject: [PATCH 2/6] lint and checks --- crates/chainspec/src/spec.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 7c4d7f8cc158..c22d8bb51469 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -13,8 +13,10 @@ use alloy_consensus::{ Header, }; use alloy_eips::{ - eip1559::INITIAL_BASE_FEE, eip6110::MAINNET_DEPOSIT_CONTRACT_ADDRESS, - eip7685::EMPTY_REQUESTS_HASH, eip7840::{BlobParams, BlobScheduleItem}, + eip1559::INITIAL_BASE_FEE, + eip6110::MAINNET_DEPOSIT_CONTRACT_ADDRESS, + eip7685::EMPTY_REQUESTS_HASH, + eip7840::{BlobParams, BlobScheduleItem}, }; use alloy_genesis::Genesis; use alloy_primitives::{address, b256, Address, BlockNumber, B256, U256}; @@ -170,7 +172,6 @@ impl HardforkBlobParams { /// Constructs params for chainspec from a provided blob schedule. /// Falls back to defaults if the schedule is empty. pub fn from_schedule(blob_schedule: &BTreeMap) -> Self { - let extract = |key: &str, default: fn() -> BlobParams| { blob_schedule .get(key) @@ -191,10 +192,7 @@ impl HardforkBlobParams { impl Default for HardforkBlobParams { fn default() -> Self { - Self { - cancun: BlobParams::cancun(), - prague: BlobParams::prague(), - } + Self { cancun: BlobParams::cancun(), prague: BlobParams::prague() } } } @@ -265,7 +263,7 @@ impl Default for ChainSpec { deposit_contract: Default::default(), base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), prune_delete_limit: MAINNET.prune_delete_limit, - blob_params: Default::default() + blob_params: Default::default(), } } } From a179ebbc70f60ced0b19a2363370b196b4f74945 Mon Sep 17 00:00:00 2001 From: Tomas Milukas Date: Tue, 31 Dec 2024 03:56:21 +0100 Subject: [PATCH 3/6] fixes --- examples/bsc-p2p/src/chainspec.rs | 1 + examples/polygon-p2p/src/chain_cfg.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/bsc-p2p/src/chainspec.rs b/examples/bsc-p2p/src/chainspec.rs index 588175734ff9..d6676bed6d68 100644 --- a/examples/bsc-p2p/src/chainspec.rs +++ b/examples/bsc-p2p/src/chainspec.rs @@ -24,6 +24,7 @@ pub(crate) fn bsc_chain_spec() -> Arc { deposit_contract: None, base_fee_params: reth_chainspec::BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), prune_delete_limit: 0, + blob_params: Default::default() } .into() } diff --git a/examples/polygon-p2p/src/chain_cfg.rs b/examples/polygon-p2p/src/chain_cfg.rs index 229e4301b8c2..cc289795effa 100644 --- a/examples/polygon-p2p/src/chain_cfg.rs +++ b/examples/polygon-p2p/src/chain_cfg.rs @@ -30,6 +30,7 @@ pub(crate) fn polygon_chain_spec() -> Arc { deposit_contract: None, base_fee_params: reth_chainspec::BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), prune_delete_limit: 0, + blob_params: Default::default() } .into() } From 58f9a8bc25ac4c835facece0d8b9759d6581a635 Mon Sep 17 00:00:00 2001 From: Tomas Milukas Date: Tue, 31 Dec 2024 03:58:14 +0100 Subject: [PATCH 4/6] missing commas --- examples/bsc-p2p/src/chainspec.rs | 2 +- examples/polygon-p2p/src/chain_cfg.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/bsc-p2p/src/chainspec.rs b/examples/bsc-p2p/src/chainspec.rs index d6676bed6d68..acf9f4dff062 100644 --- a/examples/bsc-p2p/src/chainspec.rs +++ b/examples/bsc-p2p/src/chainspec.rs @@ -24,7 +24,7 @@ pub(crate) fn bsc_chain_spec() -> Arc { deposit_contract: None, base_fee_params: reth_chainspec::BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), prune_delete_limit: 0, - blob_params: Default::default() + blob_params: Default::default(), } .into() } diff --git a/examples/polygon-p2p/src/chain_cfg.rs b/examples/polygon-p2p/src/chain_cfg.rs index cc289795effa..d87bbccb2836 100644 --- a/examples/polygon-p2p/src/chain_cfg.rs +++ b/examples/polygon-p2p/src/chain_cfg.rs @@ -30,7 +30,7 @@ pub(crate) fn polygon_chain_spec() -> Arc { deposit_contract: None, base_fee_params: reth_chainspec::BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), prune_delete_limit: 0, - blob_params: Default::default() + blob_params: Default::default(), } .into() } From afe0da99b186e2f62ae9bbb2d8efb803a937b7e4 Mon Sep 17 00:00:00 2001 From: Tomas Milukas Date: Tue, 31 Dec 2024 04:13:52 +0100 Subject: [PATCH 5/6] import problems, mb --- crates/chainspec/src/spec.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index c22d8bb51469..8f1595ce6996 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -1,9 +1,7 @@ -use std::collections::BTreeMap; - pub use alloy_eips::eip1559::BaseFeeParams; use crate::{constants::MAINNET_DEPOSIT_CONTRACT, once_cell_set, EthChainSpec, LazyLock, OnceLock}; -use alloc::{boxed::Box, sync::Arc, vec::Vec}; +use alloc::{boxed::Box, collections::BTreeMap, string::String, sync::Arc, vec::Vec}; use alloy_chains::{Chain, NamedChain}; use alloy_consensus::{ constants::{ From 9a067accd05b8fdd3e5285929e4d2c27411a3731 Mon Sep 17 00:00:00 2001 From: Tomas Milukas Date: Sat, 4 Jan 2025 11:49:46 +0100 Subject: [PATCH 6/6] one liner doc changes --- crates/chainspec/src/spec.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 8f1595ce6996..085d280b3ca7 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -162,7 +162,9 @@ pub struct ForkBaseFeeParams(Vec<(Box, BaseFeeParams)>); /// A container for hardforks that use eip-7804 blobs. #[derive(Debug, Clone, PartialEq, Eq)] pub struct HardforkBlobParams { + /// Configuration for blob-related calculations for the Cancun hardfork. pub cancun: BlobParams, + /// Configuration for blob-related calculations for the Prague hardfork. pub prague: BlobParams, }