mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(op-reth): Canyon hardfork spec (#5503)
This commit is contained in:
@ -278,7 +278,7 @@ where
|
||||
return Poll::Ready(Some(Err(err.into())))
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
Poll::Pending => {
|
||||
|
||||
@ -274,6 +274,8 @@ pub static OP_GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
|
||||
),
|
||||
(Hardfork::Bedrock, ForkCondition::Block(4061224)),
|
||||
(Hardfork::Regolith, ForkCondition::Timestamp(1679079600)),
|
||||
(Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)),
|
||||
(Hardfork::Canyon, ForkCondition::Timestamp(1699981200)),
|
||||
]),
|
||||
base_fee_params: BaseFeeParams::optimism(),
|
||||
prune_delete_limit: 1700,
|
||||
@ -315,6 +317,8 @@ pub static BASE_GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
|
||||
),
|
||||
(Hardfork::Bedrock, ForkCondition::Block(0)),
|
||||
(Hardfork::Regolith, ForkCondition::Timestamp(1683219600)),
|
||||
(Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)),
|
||||
(Hardfork::Canyon, ForkCondition::Timestamp(1699981200)),
|
||||
]),
|
||||
base_fee_params: BaseFeeParams::optimism_goerli(),
|
||||
prune_delete_limit: 1700,
|
||||
@ -1032,9 +1036,7 @@ impl ChainSpecBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Enable Regolith at the timestamp of activation.
|
||||
/// For post-bedrock op-stack chains, this will be at genesis.
|
||||
/// For pre-bedrock op-stack chains, this will be at the timestamp of regolith activation.
|
||||
/// Enable Regolith at genesis
|
||||
#[cfg(feature = "optimism")]
|
||||
pub fn regolith_activated(mut self) -> Self {
|
||||
self = self.bedrock_activated();
|
||||
@ -1042,6 +1044,16 @@ impl ChainSpecBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Enable Canyon at genesis
|
||||
#[cfg(feature = "optimism")]
|
||||
pub fn canyon_activated(mut self) -> Self {
|
||||
self = self.regolith_activated();
|
||||
// Canyon also activates changes from L1's Shanghai hardfork
|
||||
self.hardforks.insert(Hardfork::Shanghai, ForkCondition::Timestamp(0));
|
||||
self.hardforks.insert(Hardfork::Canyon, ForkCondition::Timestamp(0));
|
||||
self
|
||||
}
|
||||
|
||||
/// Build the resulting [`ChainSpec`].
|
||||
///
|
||||
/// # Panics
|
||||
@ -1984,13 +1996,55 @@ Post-merge hard forks (timestamp based):
|
||||
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: 4061224, timestamp: 1679079600, ..Default::default() },
|
||||
ForkId { hash: ForkHash([0x6d, 0x43, 0x1d, 0x6c]), next: 0 },
|
||||
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: 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: 0 },
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@ -37,16 +37,19 @@ pub enum Hardfork {
|
||||
GrayGlacier,
|
||||
/// Paris.
|
||||
Paris,
|
||||
/// Shanghai.
|
||||
Shanghai,
|
||||
/// Cancun.
|
||||
Cancun,
|
||||
/// Bedrock.
|
||||
#[cfg(feature = "optimism")]
|
||||
Bedrock,
|
||||
/// Regolith
|
||||
#[cfg(feature = "optimism")]
|
||||
Regolith,
|
||||
/// Shanghai.
|
||||
Shanghai,
|
||||
/// Canyon
|
||||
#[cfg(feature = "optimism")]
|
||||
Canyon,
|
||||
/// Cancun.
|
||||
Cancun,
|
||||
}
|
||||
|
||||
impl Hardfork {
|
||||
@ -95,6 +98,8 @@ impl FromStr for Hardfork {
|
||||
"bedrock" => Hardfork::Bedrock,
|
||||
#[cfg(feature = "optimism")]
|
||||
"regolith" => Hardfork::Regolith,
|
||||
#[cfg(feature = "optimism")]
|
||||
"canyon" => Hardfork::Canyon,
|
||||
_ => return Err(format!("Unknown hardfork: {s}")),
|
||||
};
|
||||
Ok(hardfork)
|
||||
@ -163,8 +168,8 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(feature = "optimism")]
|
||||
fn check_op_hardfork_from_str() {
|
||||
let hardfork_str = ["beDrOck", "rEgOlITH"];
|
||||
let expected_hardforks = [Hardfork::Bedrock, Hardfork::Regolith];
|
||||
let hardfork_str = ["beDrOck", "rEgOlITH", "cAnYoN"];
|
||||
let expected_hardforks = [Hardfork::Bedrock, Hardfork::Regolith, Hardfork::Canyon];
|
||||
|
||||
let hardforks: Vec<Hardfork> =
|
||||
hardfork_str.iter().map(|h| Hardfork::from_str(h).unwrap()).collect();
|
||||
|
||||
@ -10,7 +10,9 @@ pub fn revm_spec_by_timestamp_after_merge(
|
||||
) -> revm_primitives::SpecId {
|
||||
#[cfg(feature = "optimism")]
|
||||
if chain_spec.is_optimism() {
|
||||
if chain_spec.fork(Hardfork::Regolith).active_at_timestamp(timestamp) {
|
||||
if chain_spec.fork(Hardfork::Canyon).active_at_timestamp(timestamp) {
|
||||
return revm_primitives::CANYON
|
||||
} else if chain_spec.fork(Hardfork::Regolith).active_at_timestamp(timestamp) {
|
||||
return revm_primitives::REGOLITH
|
||||
} else {
|
||||
return revm_primitives::BEDROCK
|
||||
@ -30,7 +32,9 @@ pub fn revm_spec_by_timestamp_after_merge(
|
||||
pub fn revm_spec(chain_spec: &ChainSpec, block: Head) -> revm_primitives::SpecId {
|
||||
#[cfg(feature = "optimism")]
|
||||
if chain_spec.is_optimism() {
|
||||
if chain_spec.fork(Hardfork::Regolith).active_at_head(&block) {
|
||||
if chain_spec.fork(Hardfork::Canyon).active_at_head(&block) {
|
||||
return revm_primitives::CANYON
|
||||
} else if chain_spec.fork(Hardfork::Regolith).active_at_head(&block) {
|
||||
return revm_primitives::REGOLITH
|
||||
} else if chain_spec.fork(Hardfork::Bedrock).active_at_head(&block) {
|
||||
return revm_primitives::BEDROCK
|
||||
@ -138,6 +142,10 @@ mod tests {
|
||||
f(cs).build()
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
revm_spec(&op_cs(|cs| cs.canyon_activated()), Head::default()),
|
||||
revm_primitives::CANYON
|
||||
);
|
||||
assert_eq!(
|
||||
revm_spec(&op_cs(|cs| cs.bedrock_activated()), Head::default()),
|
||||
revm_primitives::BEDROCK
|
||||
|
||||
Reference in New Issue
Block a user