mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 00:58:11 -05:00
feat: base sepolia support (#5697)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@@ -10,14 +10,14 @@ use std::{
|
||||
};
|
||||
|
||||
#[cfg(feature = "optimism")]
|
||||
use reth_primitives::{BASE_GOERLI, BASE_MAINNET};
|
||||
use reth_primitives::{BASE_GOERLI, BASE_MAINNET, BASE_SEPOLIA};
|
||||
|
||||
#[cfg(not(feature = "optimism"))]
|
||||
use reth_primitives::{DEV, GOERLI, HOLESKY, MAINNET, SEPOLIA};
|
||||
|
||||
#[cfg(feature = "optimism")]
|
||||
/// Chains supported by op-reth. First value should be used as the default.
|
||||
pub const SUPPORTED_CHAINS: &[&str] = &["base", "base_goerli"];
|
||||
pub const SUPPORTED_CHAINS: &[&str] = &["base", "base_goerli", "base_sepolia"];
|
||||
#[cfg(not(feature = "optimism"))]
|
||||
/// Chains supported by reth. First value should be used as the default.
|
||||
pub const SUPPORTED_CHAINS: &[&str] = &["mainnet", "sepolia", "goerli", "holesky", "dev"];
|
||||
@@ -45,6 +45,8 @@ pub fn chain_spec_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Er
|
||||
#[cfg(feature = "optimism")]
|
||||
"base_goerli" | "base-goerli" => BASE_GOERLI.clone(),
|
||||
#[cfg(feature = "optimism")]
|
||||
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(),
|
||||
#[cfg(feature = "optimism")]
|
||||
"base" => BASE_MAINNET.clone(),
|
||||
_ => {
|
||||
let raw = fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned()))?;
|
||||
@@ -78,6 +80,8 @@ pub fn genesis_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error
|
||||
#[cfg(feature = "optimism")]
|
||||
"base_goerli" | "base-goerli" => BASE_GOERLI.clone(),
|
||||
#[cfg(feature = "optimism")]
|
||||
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(),
|
||||
#[cfg(feature = "optimism")]
|
||||
"base" => BASE_MAINNET.clone(),
|
||||
_ => {
|
||||
// try to read json from path first
|
||||
|
||||
15256
crates/primitives/res/genesis/sepolia_base.json
Normal file
15256
crates/primitives/res/genesis/sepolia_base.json
Normal file
File diff suppressed because one or more lines are too long
@@ -19,7 +19,7 @@ pub use spec::{
|
||||
};
|
||||
|
||||
#[cfg(feature = "optimism")]
|
||||
pub use spec::{BASE_GOERLI, BASE_MAINNET, OP_GOERLI};
|
||||
pub use spec::{BASE_GOERLI, BASE_MAINNET, BASE_SEPOLIA, OP_GOERLI};
|
||||
|
||||
// The chain info module.
|
||||
mod info;
|
||||
@@ -64,6 +64,7 @@ pub enum NamedChain {
|
||||
|
||||
Base = 8453,
|
||||
BaseGoerli = 84531,
|
||||
BaseSepolia = 84532,
|
||||
|
||||
Arbitrum = 42161,
|
||||
ArbitrumTestnet = 421611,
|
||||
@@ -138,6 +139,11 @@ impl Chain {
|
||||
Chain::Named(NamedChain::BaseGoerli)
|
||||
}
|
||||
|
||||
/// Returns the base sepolia chain.
|
||||
pub const fn base_sepolia() -> Self {
|
||||
Chain::Named(NamedChain::BaseSepolia)
|
||||
}
|
||||
|
||||
/// Returns the base mainnet chain.
|
||||
pub const fn base_mainnet() -> Self {
|
||||
Chain::Named(NamedChain::Base)
|
||||
@@ -157,7 +163,8 @@ impl Chain {
|
||||
NamedChain::OptimismGoerli |
|
||||
NamedChain::OptimismKovan |
|
||||
NamedChain::Base |
|
||||
NamedChain::BaseGoerli
|
||||
NamedChain::BaseGoerli |
|
||||
NamedChain::BaseSepolia
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -341,6 +341,55 @@ pub static BASE_GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
|
||||
.into()
|
||||
});
|
||||
|
||||
/// The Base Sepolia spec
|
||||
#[cfg(feature = "optimism")]
|
||||
pub static BASE_SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
|
||||
ChainSpec {
|
||||
chain: Chain::base_sepolia(),
|
||||
genesis: serde_json::from_str(include_str!("../../res/genesis/sepolia_base.json"))
|
||||
.expect("Can't deserialize Base Sepolia genesis json"),
|
||||
genesis_hash: Some(b256!(
|
||||
"0dcc9e089e30b90ddfc55be9a37dd15bc551aeee999d2e2b51414c54eaf934e4"
|
||||
)),
|
||||
fork_timestamps: ForkTimestamps::default().shanghai(1699981200).canyon(1699981200),
|
||||
paris_block_and_final_difficulty: Some((0, U256::from(0))),
|
||||
hardforks: BTreeMap::from([
|
||||
(Hardfork::Frontier, ForkCondition::Block(0)),
|
||||
(Hardfork::Homestead, ForkCondition::Block(0)),
|
||||
(Hardfork::Tangerine, ForkCondition::Block(0)),
|
||||
(Hardfork::SpuriousDragon, ForkCondition::Block(0)),
|
||||
(Hardfork::Byzantium, ForkCondition::Block(0)),
|
||||
(Hardfork::Constantinople, ForkCondition::Block(0)),
|
||||
(Hardfork::Petersburg, ForkCondition::Block(0)),
|
||||
(Hardfork::Istanbul, ForkCondition::Block(0)),
|
||||
(Hardfork::MuirGlacier, ForkCondition::Block(0)),
|
||||
(Hardfork::Berlin, ForkCondition::Block(0)),
|
||||
(Hardfork::London, ForkCondition::Block(0)),
|
||||
(Hardfork::ArrowGlacier, ForkCondition::Block(0)),
|
||||
(Hardfork::GrayGlacier, ForkCondition::Block(0)),
|
||||
(
|
||||
Hardfork::Paris,
|
||||
ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) },
|
||||
),
|
||||
(Hardfork::Bedrock, ForkCondition::Block(0)),
|
||||
(Hardfork::Regolith, ForkCondition::Timestamp(0)),
|
||||
(Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)),
|
||||
(Hardfork::Canyon, ForkCondition::Timestamp(1699981200)),
|
||||
]),
|
||||
base_fee_params: BaseFeeParamsKind::Variable(
|
||||
vec![
|
||||
(Hardfork::London, BaseFeeParams::optimism_sepolia()),
|
||||
(Hardfork::Canyon, BaseFeeParams::optimism_sepolia_canyon()),
|
||||
]
|
||||
.into(),
|
||||
),
|
||||
prune_delete_limit: 1700,
|
||||
snapshot_block_interval: 1_000_000,
|
||||
..Default::default()
|
||||
}
|
||||
.into()
|
||||
});
|
||||
|
||||
/// The Base mainnet spec
|
||||
#[cfg(feature = "optimism")]
|
||||
pub static BASE_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
|
||||
@@ -463,6 +512,28 @@ impl BaseFeeParams {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the base fee parameters for optimism sepolia
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const fn optimism_sepolia() -> BaseFeeParams {
|
||||
BaseFeeParams {
|
||||
max_change_denominator:
|
||||
crate::constants::OP_SEPOLIA_EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR,
|
||||
elasticity_multiplier:
|
||||
crate::constants::OP_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the base fee parameters for optimism goerli (post Canyon)
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const fn optimism_sepolia_canyon() -> BaseFeeParams {
|
||||
BaseFeeParams {
|
||||
max_change_denominator:
|
||||
crate::constants::OP_SEPOLIA_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_CANYON,
|
||||
elasticity_multiplier:
|
||||
crate::constants::OP_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the base fee parameters for optimism mainnet
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const fn optimism() -> BaseFeeParams {
|
||||
@@ -2879,4 +2950,20 @@ Post-merge hard forks (timestamp based):
|
||||
|
||||
assert_eq!(spec.hardfork_fork_filter(Hardfork::Shanghai), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "optimism")]
|
||||
fn base_sepolia_genesis() {
|
||||
let genesis = BASE_SEPOLIA.genesis_header();
|
||||
assert_eq!(
|
||||
genesis.hash_slow(),
|
||||
"0x0dcc9e089e30b90ddfc55be9a37dd15bc551aeee999d2e2b51414c54eaf934e4"
|
||||
.parse::<B256>()
|
||||
.unwrap()
|
||||
);
|
||||
let base_fee =
|
||||
genesis.next_block_base_fee(BASE_SEPOLIA.base_fee_params(genesis.timestamp)).unwrap();
|
||||
// <https://base-sepolia.blockscout.com/block/1>
|
||||
assert_eq!(base_fee, 980000000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,21 @@ pub const OP_GOERLI_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_CANYON: u64 = 250;
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const OP_GOERLI_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u64 = 10;
|
||||
|
||||
/// Base fee max change denominator for Optimism Sepolia as defined in the Optimism
|
||||
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const OP_SEPOLIA_EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR: u64 = 50;
|
||||
|
||||
/// Base fee max change denominator for Optimism Sepolia as defined in the Optimism Canyon
|
||||
/// hardfork.
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const OP_SEPOLIA_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_CANYON: u64 = 250;
|
||||
|
||||
/// Base fee max change denominator for Optimism Sepolia as defined in the Optimism
|
||||
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const OP_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u64 = 10;
|
||||
|
||||
/// Multiplier for converting gwei to wei.
|
||||
pub const GWEI_TO_WEI: u64 = 1_000_000_000;
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ pub use c_kzg as kzg;
|
||||
#[cfg(feature = "optimism")]
|
||||
mod optimism {
|
||||
pub use crate::{
|
||||
chain::{BASE_GOERLI, BASE_MAINNET, OP_GOERLI},
|
||||
chain::{BASE_GOERLI, BASE_MAINNET, BASE_SEPOLIA, OP_GOERLI},
|
||||
transaction::{TxDeposit, DEPOSIT_TX_TYPE_ID},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user