|
8 | 8 | #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] |
9 | 9 | #![cfg_attr(not(feature = "std"), no_std)] |
10 | 10 |
|
11 | | -use alloc::{boxed::Box, vec::Vec}; |
| 11 | +use alloc::{boxed::Box, vec, vec::Vec}; |
12 | 12 | use alloy_chains::Chain; |
13 | 13 | use alloy_consensus::Header; |
14 | 14 | use alloy_genesis::Genesis; |
15 | 15 | use alloy_primitives::{B256, U256}; |
16 | 16 | use derive_more::{Constructor, Deref, From, Into}; |
17 | 17 | use reth_chainspec::{ |
18 | | - BaseFeeParams, ChainSpec, ChainSpecBuilder, DepositContract, EthChainSpec, |
| 18 | + BaseFeeParams, BaseFeeParamsKind, ChainSpec, ChainSpecBuilder, DepositContract, EthChainSpec, |
19 | 19 | EthereumCapabilities, EthereumHardforks, ForkFilter, ForkId, Hardforks, Head, |
20 | 20 | }; |
21 | 21 | use reth_ethereum_forks::{ |
22 | 22 | ChainHardforks, EthereumHardfork, ForkCondition, ForkFilterKey, ForkHash, Hardfork, |
23 | 23 | }; |
24 | 24 | use reth_network_peers::NodeRecord; |
| 25 | +use reth_primitives_traits::SealedHeader; |
25 | 26 | use scroll_alloy_hardforks::{ScrollHardfork, ScrollHardforks}; |
26 | 27 |
|
27 | 28 | use alloy_eips::eip7840::BlobParams; |
@@ -184,6 +185,34 @@ impl ScrollChainSpecBuilder { |
184 | 185 | } |
185 | 186 | } |
186 | 187 |
|
| 188 | +// Used by the CLI for custom genesis files. |
| 189 | +impl ScrollChainSpec { |
| 190 | + /// Build from a custom `Genesis`, ensuring: |
| 191 | + /// - `genesis_header` has `base_fee_per_gas` (0 if Feynman@genesis) |
| 192 | + /// - `base_fee_params` switch to Scroll defaults at Feynman |
| 193 | + pub fn from_custom_genesis(genesis: Genesis) -> Self { |
| 194 | + // Use the existing From<Genesis> as the base. |
| 195 | + let mut spec: Self = genesis.into(); |
| 196 | + |
| 197 | + // Determine whether Feynman is active at genesis. |
| 198 | + let feynman_active_at_genesis = |
| 199 | + spec.is_feynman_active_at_timestamp(spec.inner.genesis.timestamp); |
| 200 | + |
| 201 | + // Ensure the genesis header has a base fee when required. |
| 202 | + let mut header = make_genesis_header(&spec.inner.genesis); |
| 203 | + if header.base_fee_per_gas.is_none() && feynman_active_at_genesis { |
| 204 | + header.base_fee_per_gas = Some(0); |
| 205 | + } |
| 206 | + spec.inner.genesis_header = SealedHeader::new_unhashed(header); |
| 207 | + |
| 208 | + // Use Scroll's EIP-1559 params from Feynman onwards. |
| 209 | + spec.inner.base_fee_params = BaseFeeParamsKind::Variable( |
| 210 | + vec![(ScrollHardfork::Feynman.boxed(), SCROLL_BASE_FEE_PARAMS_FEYNMAN)].into(), |
| 211 | + ); |
| 212 | + spec |
| 213 | + } |
| 214 | +} |
| 215 | + |
187 | 216 | /// Returns the chain configuration. |
188 | 217 | #[auto_impl::auto_impl(Arc)] |
189 | 218 | pub trait ChainConfig { |
|
0 commit comments