Skip to content

Commit 40affdf

Browse files
authored
feat: use from_custom_genesis for custom genesis files and set Scroll fee parameters (#320)
* feat: use from_custom_genesis for custom genesis files and set Scroll fee parameters * fix CI * address a comment
1 parent 74dd0bd commit 40affdf

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/scroll/chainspec/src/lib.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
99
#![cfg_attr(not(feature = "std"), no_std)]
1010

11-
use alloc::{boxed::Box, vec::Vec};
11+
use alloc::{boxed::Box, vec, vec::Vec};
1212
use alloy_chains::Chain;
1313
use alloy_consensus::Header;
1414
use alloy_genesis::Genesis;
1515
use alloy_primitives::{B256, U256};
1616
use derive_more::{Constructor, Deref, From, Into};
1717
use reth_chainspec::{
18-
BaseFeeParams, ChainSpec, ChainSpecBuilder, DepositContract, EthChainSpec,
18+
BaseFeeParams, BaseFeeParamsKind, ChainSpec, ChainSpecBuilder, DepositContract, EthChainSpec,
1919
EthereumCapabilities, EthereumHardforks, ForkFilter, ForkId, Hardforks, Head,
2020
};
2121
use reth_ethereum_forks::{
2222
ChainHardforks, EthereumHardfork, ForkCondition, ForkFilterKey, ForkHash, Hardfork,
2323
};
2424
use reth_network_peers::NodeRecord;
25+
use reth_primitives_traits::SealedHeader;
2526
use scroll_alloy_hardforks::{ScrollHardfork, ScrollHardforks};
2627

2728
use alloy_eips::eip7840::BlobParams;
@@ -184,6 +185,34 @@ impl ScrollChainSpecBuilder {
184185
}
185186
}
186187

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+
187216
/// Returns the chain configuration.
188217
#[auto_impl::auto_impl(Arc)]
189218
pub trait ChainConfig {

crates/scroll/cli/src/spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl ChainSpecParser for ScrollChainSpecParser {
1515
"dev" => SCROLL_DEV.clone(),
1616
"scroll-mainnet" => SCROLL_MAINNET.clone(),
1717
"scroll-sepolia" => SCROLL_SEPOLIA.clone(),
18-
_ => Arc::new(parse_genesis(s)?.into()),
18+
_ => Arc::new(ScrollChainSpec::from_custom_genesis(parse_genesis(s)?)),
1919
})
2020
}
2121
}

deny.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ exceptions = [
6262
# TODO: decide on MPL-2.0 handling
6363
# These dependencies are grandfathered in https://github.com/paradigmxyz/reth/pull/6980
6464
{ allow = ["MPL-2.0"], name = "option-ext" },
65-
{ allow = ["MPL-2.0"], name = "webpki-root-certs" },
6665
]
6766

6867
# Skip the poseidon-bn254, bn254 and zktrie crates for license verification. We should at some point publish a license for them.

0 commit comments

Comments
 (0)