feat(primitives): OP Sepolia ChainSpec (#6812)

This commit is contained in:
clabby
2024-03-14 08:32:11 -04:00
committed by GitHub
parent b032120ff1
commit 520d63580b
5 changed files with 108 additions and 7 deletions

View File

@@ -10,14 +10,14 @@ use std::{
};
#[cfg(feature = "optimism")]
use reth_primitives::{BASE_MAINNET, BASE_SEPOLIA};
use reth_primitives::{BASE_MAINNET, BASE_SEPOLIA, OP_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-sepolia"];
pub const SUPPORTED_CHAINS: &[&str] = &["base", "base-sepolia", "optimism-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"];
@@ -43,6 +43,8 @@ pub fn chain_spec_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Er
#[cfg(not(feature = "optimism"))]
"dev" => DEV.clone(),
#[cfg(feature = "optimism")]
"optimism_sepolia" | "optimism-sepolia" => OP_SEPOLIA.clone(),
#[cfg(feature = "optimism")]
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(),
#[cfg(feature = "optimism")]
"base" => BASE_MAINNET.clone(),
@@ -76,6 +78,8 @@ pub fn genesis_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error
#[cfg(not(feature = "optimism"))]
"dev" => DEV.clone(),
#[cfg(feature = "optimism")]
"optimism_sepolia" | "optimism-sepolia" => OP_SEPOLIA.clone(),
#[cfg(feature = "optimism")]
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(),
#[cfg(feature = "optimism")]
"base" => BASE_MAINNET.clone(),

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@ pub use spec::{
MAINNET, SEPOLIA,
};
#[cfg(feature = "optimism")]
pub use spec::{BASE_MAINNET, BASE_SEPOLIA};
pub use spec::{BASE_MAINNET, BASE_SEPOLIA, OP_SEPOLIA};
// The chain spec module.
mod spec;

View File

@@ -244,6 +244,60 @@ pub static DEV: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
.into()
});
/// The OP Sepolia spec
#[cfg(feature = "optimism")]
pub static OP_SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::from_named(NamedChain::OptimismSepolia),
genesis: serde_json::from_str(include_str!("../../res/genesis/sepolia_op.json"))
.expect("Can't deserialize OP Sepolia genesis json"),
genesis_hash: Some(b256!(
"102de6ffb001480cc9b8b548fd05c34cd4f46ae4aa91759393db90ea0409887d"
)),
fork_timestamps: ForkTimestamps::default()
.shanghai(1699981200)
.canyon(1699981200)
.cancun(1708534800)
.ecotone(1708534800),
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)),
(Hardfork::Cancun, ForkCondition::Timestamp(1708534800)),
(Hardfork::Ecotone, ForkCondition::Timestamp(1708534800)),
]),
base_fee_params: BaseFeeParamsKind::Variable(
vec![
(Hardfork::London, BaseFeeParams::optimism_sepolia()),
(Hardfork::Canyon, BaseFeeParams::optimism_sepolia_canyon()),
]
.into(),
),
prune_delete_limit: 1700,
..Default::default()
}
.into()
});
/// The Base Sepolia spec
#[cfg(feature = "optimism")]
pub static BASE_SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
@@ -2233,6 +2287,36 @@ Post-merge hard forks (timestamp based):
);
}
#[cfg(feature = "optimism")]
#[test]
fn op_sepolia_forkids() {
test_fork_ids(
&OP_SEPOLIA,
&[
(
Head { number: 0, ..Default::default() },
ForkId { hash: ForkHash([0x67, 0xa4, 0x03, 0x28]), next: 1699981200 },
),
(
Head { number: 0, timestamp: 1699981199, ..Default::default() },
ForkId { hash: ForkHash([0x67, 0xa4, 0x03, 0x28]), next: 1699981200 },
),
(
Head { number: 0, timestamp: 1699981200, ..Default::default() },
ForkId { hash: ForkHash([0xa4, 0x8d, 0x6a, 0x00]), next: 1708534800 },
),
(
Head { number: 0, timestamp: 1708534799, ..Default::default() },
ForkId { hash: ForkHash([0xa4, 0x8d, 0x6a, 0x00]), next: 1708534800 },
),
(
Head { number: 0, timestamp: 1708534800, ..Default::default() },
ForkId { hash: ForkHash([0xcc, 0x17, 0xc7, 0xeb]), next: 0 },
),
],
);
}
#[cfg(feature = "optimism")]
#[test]
fn base_sepolia_forkids() {
@@ -3055,13 +3139,25 @@ Post-merge hard forks (timestamp based):
let genesis = BASE_SEPOLIA.genesis_header();
assert_eq!(
genesis.hash_slow(),
"0x0dcc9e089e30b90ddfc55be9a37dd15bc551aeee999d2e2b51414c54eaf934e4"
.parse::<B256>()
.unwrap()
b256!("0dcc9e089e30b90ddfc55be9a37dd15bc551aeee999d2e2b51414c54eaf934e4")
);
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);
}
#[test]
#[cfg(feature = "optimism")]
fn op_sepolia_genesis() {
let genesis = OP_SEPOLIA.genesis_header();
assert_eq!(
genesis.hash_slow(),
b256!("102de6ffb001480cc9b8b548fd05c34cd4f46ae4aa91759393db90ea0409887d")
);
let base_fee =
genesis.next_block_base_fee(OP_SEPOLIA.base_fee_params(genesis.timestamp)).unwrap();
// <https://optimism-sepolia.blockscout.com/block/1>
assert_eq!(base_fee, 980000000);
}
}

View File

@@ -137,7 +137,7 @@ pub use c_kzg as kzg;
#[cfg(feature = "optimism")]
mod optimism {
pub use crate::{
chain::{BASE_MAINNET, BASE_SEPOLIA},
chain::{BASE_MAINNET, BASE_SEPOLIA, OP_SEPOLIA},
transaction::{TxDeposit, DEPOSIT_TX_TYPE_ID},
};
}