chore(op): Clean up ChainSpecs (#6810)

This commit is contained in:
clabby
2024-02-26 13:29:23 -07:00
committed by GitHub
parent 54db85a216
commit 6cf9e91144
9 changed files with 85 additions and 15594 deletions

View File

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -132,7 +132,7 @@ mod tests {
#[cfg(feature = "optimism")]
#[test]
fn calculate_optimism_goerli_base_fee_success() {
fn calculate_optimism_sepolia_base_fee_success() {
let base_fee = [
1000000000, 1000000000, 1000000000, 1072671875, 1059263476, 1049238967, 1049238967, 0,
1, 2,
@ -157,7 +157,7 @@ mod tests {
gas_used[i],
gas_limit[i],
base_fee[i],
crate::BaseFeeParams::optimism_goerli(),
crate::BaseFeeParams::optimism_sepolia(),
)
);
}

View File

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

View File

@ -247,116 +247,6 @@ pub static DEV: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
.into()
});
/// The Optimism Goerli spec
#[cfg(feature = "optimism")]
pub static OP_GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::optimism_goerli(),
genesis: serde_json::from_str(include_str!("../../res/genesis/goerli_op.json"))
.expect("Can't deserialize Optimism Goerli genesis json"),
genesis_hash: Some(b256!(
"c1fc15cd51159b1f1e5cbc4b82e85c1447ddfa33c52cf1d98d14fba0d6354be1"
)),
fork_timestamps: ForkTimestamps::default()
.shanghai(1699981200)
.canyon(1699981200)
.cancun(1707238800)
.ecotone(1707238800),
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(4061224)),
(Hardfork::Regolith, ForkCondition::Timestamp(1679079600)),
(Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)),
(Hardfork::Canyon, ForkCondition::Timestamp(1699981200)),
(Hardfork::Cancun, ForkCondition::Timestamp(1707238800)),
(Hardfork::Ecotone, ForkCondition::Timestamp(1707238800)),
]),
base_fee_params: BaseFeeParamsKind::Variable(
vec![
(Hardfork::London, BaseFeeParams::optimism_goerli()),
(Hardfork::Canyon, BaseFeeParams::optimism_goerli_canyon()),
]
.into(),
),
prune_delete_limit: 1700,
snapshot_block_interval: 1_000_000,
..Default::default()
}
.into()
});
/// The Base Goerli spec
#[cfg(feature = "optimism")]
pub static BASE_GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::base_goerli(),
genesis: serde_json::from_str(include_str!("../../res/genesis/goerli_base.json"))
.expect("Can't deserialize Base Goerli genesis json"),
genesis_hash: Some(b256!(
"a3ab140f15ea7f7443a4702da64c10314eb04d488e72974e02e2d728096b4f76"
)),
fork_timestamps: ForkTimestamps::default()
.shanghai(1699981200)
.canyon(1699981200)
.cancun(1707238800)
.ecotone(1707238800),
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(1683219600)),
(Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)),
(Hardfork::Canyon, ForkCondition::Timestamp(1699981200)),
(Hardfork::Cancun, ForkCondition::Timestamp(1707238800)),
(Hardfork::Ecotone, ForkCondition::Timestamp(1707238800)),
]),
base_fee_params: BaseFeeParamsKind::Variable(
vec![
(Hardfork::London, BaseFeeParams::optimism_goerli()),
(Hardfork::Canyon, BaseFeeParams::optimism_goerli_canyon()),
]
.into(),
),
prune_delete_limit: 1700,
snapshot_block_interval: 1_000_000,
..Default::default()
}
.into()
});
/// The Base Sepolia spec
#[cfg(feature = "optimism")]
pub static BASE_SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
@ -450,6 +340,7 @@ pub static BASE_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
(Hardfork::Regolith, ForkCondition::Timestamp(0)),
(Hardfork::Shanghai, ForkCondition::Timestamp(1704992401)),
(Hardfork::Canyon, ForkCondition::Timestamp(1704992401)),
(Hardfork::Cancun, ForkCondition::Timestamp(1710374401)),
(Hardfork::Ecotone, ForkCondition::Timestamp(1710374401)),
]),
base_fee_params: BaseFeeParamsKind::Variable(
@ -519,28 +410,6 @@ impl BaseFeeParams {
}
}
/// Get the base fee parameters for optimism goerli
#[cfg(feature = "optimism")]
pub const fn optimism_goerli() -> BaseFeeParams {
BaseFeeParams {
max_change_denominator:
crate::constants::OP_GOERLI_EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR,
elasticity_multiplier:
crate::constants::OP_GOERLI_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
}
}
/// Get the base fee parameters for optimism goerli (post Canyon)
#[cfg(feature = "optimism")]
pub const fn optimism_goerli_canyon() -> BaseFeeParams {
BaseFeeParams {
max_change_denominator:
crate::constants::OP_GOERLI_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_CANYON,
elasticity_multiplier:
crate::constants::OP_GOERLI_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
}
}
/// Get the base fee parameters for optimism sepolia
#[cfg(feature = "optimism")]
pub const fn optimism_sepolia() -> BaseFeeParams {
@ -2331,6 +2200,66 @@ Post-merge hard forks (timestamp based):
);
}
#[cfg(feature = "optimism")]
#[test]
fn base_mainnet_forkids() {
test_fork_ids(
&BASE_MAINNET,
&[
(
Head { number: 0, ..Default::default() },
ForkId { hash: ForkHash([0x67, 0xda, 0x02, 0x60]), next: 1704992401 },
),
(
Head { number: 0, timestamp: 1704992400, ..Default::default() },
ForkId { hash: ForkHash([0x67, 0xda, 0x02, 0x60]), next: 1704992401 },
),
(
Head { number: 0, timestamp: 1704992401, ..Default::default() },
ForkId { hash: ForkHash([0x3c, 0x28, 0x3c, 0xb3]), next: 1710374401 },
),
(
Head { number: 0, timestamp: 1710374400, ..Default::default() },
ForkId { hash: ForkHash([0x3c, 0x28, 0x3c, 0xb3]), next: 1710374401 },
),
(
Head { number: 0, timestamp: 1710374401, ..Default::default() },
ForkId { hash: ForkHash([0x51, 0xcc, 0x98, 0xb3]), next: 0 },
),
],
);
}
#[cfg(feature = "optimism")]
#[test]
fn base_sepolia_forkids() {
test_fork_ids(
&BASE_SEPOLIA,
&[
(
Head { number: 0, ..Default::default() },
ForkId { hash: ForkHash([0xb9, 0x59, 0xb9, 0xf7]), next: 1699981200 },
),
(
Head { number: 0, timestamp: 1699981199, ..Default::default() },
ForkId { hash: ForkHash([0xb9, 0x59, 0xb9, 0xf7]), next: 1699981200 },
),
(
Head { number: 0, timestamp: 1699981200, ..Default::default() },
ForkId { hash: ForkHash([0x60, 0x7c, 0xd5, 0xa1]), next: 1708534800 },
),
(
Head { number: 0, timestamp: 1708534799, ..Default::default() },
ForkId { hash: ForkHash([0x60, 0x7c, 0xd5, 0xa1]), next: 1708534800 },
),
(
Head { number: 0, timestamp: 1708534800, ..Default::default() },
ForkId { hash: ForkHash([0xbe, 0x96, 0x9b, 0x17]), next: 0 },
),
],
);
}
#[test]
fn dev_forkids() {
test_fork_ids(
@ -2342,86 +2271,6 @@ Post-merge hard forks (timestamp based):
)
}
#[cfg(feature = "optimism")]
#[test]
fn optimism_goerli_forkids() {
test_fork_ids(
&OP_GOERLI,
&[
(
Head { number: 0, ..Default::default() },
ForkId { hash: ForkHash([0x6d, 0x63, 0x76, 0xbe]), next: 4061224 },
),
(
Head { number: 4061223, ..Default::default() },
ForkId { hash: ForkHash([0x6d, 0x63, 0x76, 0xbe]), next: 4061224 },
),
(
Head { number: 4061224, timestamp: 1679079599, ..Default::default() },
ForkId { hash: ForkHash([0x03, 0x47, 0x85, 0x69]), next: 1679079600 },
),
(
Head { number: 4061225, timestamp: 1679079600, ..Default::default() },
ForkId { hash: ForkHash([0x6d, 0x43, 0x1d, 0x6c]), next: 1699981200 },
),
(
Head { number: 4061226, timestamp: 1699981199, ..Default::default() },
ForkId { hash: ForkHash([0x6d, 0x43, 0x1d, 0x6c]), next: 1699981200 },
),
(
Head { number: 4061227, timestamp: 1699981200, ..Default::default() },
ForkId { hash: ForkHash([0x7f, 0x4a, 0x72, 0x1f]), next: 1707238800 },
),
(
Head { number: 4061228, timestamp: 1707238799, ..Default::default() },
ForkId { hash: ForkHash([0x7f, 0x4a, 0x72, 0x1f]), next: 1707238800 },
),
(
Head { number: 4061229, timestamp: 1707238800, ..Default::default() },
ForkId { hash: ForkHash([0x18, 0x59, 0x2a, 0x41]), next: 0 },
),
],
);
}
#[cfg(feature = "optimism")]
#[test]
fn base_goerli_forkids() {
test_fork_ids(
&BASE_GOERLI,
&[
(
Head { number: 0, ..Default::default() },
ForkId { hash: ForkHash([0xd4, 0x0c, 0x23, 0x50]), next: 1683219600 },
),
(
Head { number: 1, timestamp: 1683219599, ..Default::default() },
ForkId { hash: ForkHash([0xd4, 0x0c, 0x23, 0x50]), next: 1683219600 },
),
(
Head { number: 2, timestamp: 1683219600, ..Default::default() },
ForkId { hash: ForkHash([0xd5, 0x45, 0x43, 0x5d]), next: 1699981200 },
),
(
Head { number: 3, timestamp: 1699981199, ..Default::default() },
ForkId { hash: ForkHash([0xd5, 0x45, 0x43, 0x5d]), next: 1699981200 },
),
(
Head { number: 4, timestamp: 1699981200, ..Default::default() },
ForkId { hash: ForkHash([0xb3, 0x29, 0x13, 0xde]), next: 1707238800 },
),
(
Head { number: 5, timestamp: 1707238799, ..Default::default() },
ForkId { hash: ForkHash([0xb3, 0x29, 0x13, 0xde]), next: 1707238800 },
),
(
Head { number: 6, timestamp: 1707238800, ..Default::default() },
ForkId { hash: ForkHash([0x21, 0x11, 0x52, 0x97]), next: 0 },
),
],
);
}
/// Checks that time-based forks work
///
/// This is based off of the test vectors here: https://github.com/ethereum/go-ethereum/blob/5c8cc10d1e05c23ff1108022f4150749e73c0ca1/core/forkid/forkid_test.go#L155-L188
@ -3172,6 +3021,20 @@ Post-merge hard forks (timestamp based):
assert_eq!(spec.hardfork_fork_filter(Hardfork::Shanghai), None);
}
#[test]
#[cfg(feature = "optimism")]
fn base_mainnet_genesis() {
let genesis = BASE_MAINNET.genesis_header();
assert_eq!(
genesis.hash_slow(),
b256!("f712aa9241cc24369b143cf6dce85f0902a9731e70d66818a3a5845b296c73dd")
);
let base_fee =
genesis.next_block_base_fee(BASE_MAINNET.base_fee_params(genesis.timestamp)).unwrap();
// <https://base.blockscout.com/block/1>
assert_eq!(base_fee, 980000000);
}
#[test]
#[cfg(feature = "optimism")]
fn base_sepolia_genesis() {

View File

@ -79,21 +79,6 @@ pub const OP_MAINNET_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_CANYON: u64 = 250;
#[cfg(feature = "optimism")]
pub const OP_MAINNET_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u64 = 6;
/// Base fee max change denominator for Optimism Goerli as defined in the Optimism
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
#[cfg(feature = "optimism")]
pub const OP_GOERLI_EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR: u64 = 50;
/// Base fee max change denominator for Optimism Goerli as defined in the Optimism Canyon
/// hardfork.
#[cfg(feature = "optimism")]
pub const OP_GOERLI_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_CANYON: u64 = 250;
/// Base fee max change denominator for Optimism Goerli as defined in the Optimism
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
#[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")]
@ -141,14 +126,6 @@ pub const HOLESKY_GENESIS_HASH: B256 =
pub const DEV_GENESIS_HASH: B256 =
b256!("2f980576711e3617a5e4d83dd539548ec0f7792007d505a3d2e9674833af2d7c");
/// Optimism goerli genesis hash.
pub const GOERLI_OP_GENESIS: B256 =
b256!("c1fc15cd51159b1f1e5cbc4b82e85c1447ddfa33c52cf1d98d14fba0d6354be1");
/// Base goerli genesis hash.
pub const GOERLI_BASE_GENESIS: B256 =
b256!("a3ab140f15ea7f7443a4702da64c10314eb04d488e72974e02e2d728096b4f76");
/// Keccak256 over empty array.
pub const KECCAK_EMPTY: B256 =
b256!("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");

View File

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

View File

@ -288,7 +288,7 @@ mod tests {
#[cfg(feature = "optimism")]
#[test]
fn check_optimism_receipt_root() {
use crate::{Bloom, Bytes, OP_GOERLI};
use crate::{Bloom, Bytes, BASE_SEPOLIA};
let cases = [
// Deposit nonces didn't exist in Bedrock; No need to strip. For the purposes of this
@ -296,7 +296,7 @@ mod tests {
(
"bedrock",
1679079599,
b256!("6eefbb5efb95235476654a8bfbf8cb64a4f5f0b0c80b700b0c5964550beee6d7"),
b256!("e255fed45eae7ede0556fe4fabc77b0d294d18781a5a581cab09127bc4cd9ffb"),
),
// Deposit nonces introduced in Regolith. They weren't included in the receipt RLP,
// so we need to strip them - the receipt root will differ.
@ -537,7 +537,7 @@ mod tests {
bloom: Bloom(hex!("00000000000000000000000000000000400000000000000000000000000000000000004000000000000001000000000000000002000000000100000000000000000000000000000000000008000000000000000000000000000000000000000004000000020000000000000000000800000000000000000000000010200100200008000002000000000000000000800000000000000000000002000000000000000000000000000000080000000000000000000000004000000000000000000000000002000000000000000000000000000000000000200000000000000020002000000000000000002000000000000000000000000000000000000000000000").into()),
},
];
let root = calculate_receipt_root_optimism(&receipts, OP_GOERLI.as_ref(), case.1);
let root = calculate_receipt_root_optimism(&receipts, BASE_SEPOLIA.as_ref(), case.1);
assert_eq!(root, case.2);
}
}
@ -559,7 +559,7 @@ mod tests {
bloom,
};
let receipt = vec![receipt];
let root = calculate_receipt_root_optimism(&receipt, crate::OP_GOERLI.as_ref(), 0);
let root = calculate_receipt_root_optimism(&receipt, crate::BASE_SEPOLIA.as_ref(), 0);
assert_eq!(root, b256!("fe70ae4a136d98944951b2123859698d59ad251a381abc9960fa81cae3d0d4a0"));
}