Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add fjordTime to OP genesis config #8571

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,8 @@ impl From<Genesis> for ChainSpec {
(Hardfork::Canyon, optimism_genesis_info.canyon_time),
#[cfg(feature = "optimism")]
(Hardfork::Ecotone, optimism_genesis_info.ecotone_time),
#[cfg(feature = "optimism")]
(Hardfork::Fjord, optimism_genesis_info.fjord_time),
];

let time_hardforks = time_hardfork_opts
Expand Down Expand Up @@ -1302,6 +1304,14 @@ impl ChainSpecBuilder {
self
}

/// Enable Fjord at genesis
#[cfg(feature = "optimism")]
pub fn fjord_activated(mut self) -> Self {
self = self.ecotone_activated();
self.hardforks.insert(Hardfork::Fjord, ForkCondition::Timestamp(0));
self
}

/// Build the resulting [`ChainSpec`].
///
/// # Panics
Expand Down Expand Up @@ -1631,8 +1641,9 @@ impl DepositContract {
struct OptimismGenesisInfo {
bedrock_block: Option<u64>,
regolith_time: Option<u64>,
ecotone_time: Option<u64>,
canyon_time: Option<u64>,
ecotone_time: Option<u64>,
fjord_time: Option<u64>,
base_fee_params: BaseFeeParamsKind,
}

Expand Down Expand Up @@ -1699,6 +1710,11 @@ impl OptimismGenesisInfo {
.extra_fields
.get("ecotoneTime")
.and_then(|value| value.as_u64()),
fjord_time: genesis
.config
.extra_fields
.get("fjordTime")
.and_then(|value| value.as_u64()),
base_fee_params,
}
}
Expand Down Expand Up @@ -3308,9 +3324,10 @@ Post-merge hard forks (timestamp based):
"regolithTime": 20,
"canyonTime": 30,
"ecotoneTime": 40,
"fjordTime": 50,
"optimism": {
"eip1559Elasticity": 50,
"eip1559Denominator": 60
"eip1559Elasticity": 60,
"eip1559Denominator": 70
}
}
}
Expand All @@ -3325,32 +3342,36 @@ Post-merge hard forks (timestamp based):
assert_eq!(actual_canyon_timestamp, Some(serde_json::Value::from(30)).as_ref());
let actual_ecotone_timestamp = genesis.config.extra_fields.get("ecotoneTime");
assert_eq!(actual_ecotone_timestamp, Some(serde_json::Value::from(40)).as_ref());
let actual_fjord_timestamp = genesis.config.extra_fields.get("fjordTime");
assert_eq!(actual_fjord_timestamp, Some(serde_json::Value::from(50)).as_ref());

let optimism_object = genesis.config.extra_fields.get("optimism").unwrap();
assert_eq!(
optimism_object,
&serde_json::json!({
"eip1559Elasticity": 50,
"eip1559Denominator": 60,
"eip1559Elasticity": 60,
"eip1559Denominator": 70,
})
);

let chain_spec: ChainSpec = genesis.into();

assert_eq!(
chain_spec.base_fee_params,
BaseFeeParamsKind::Constant(BaseFeeParams::new(60, 50))
BaseFeeParamsKind::Constant(BaseFeeParams::new(70, 60))
);

assert!(!chain_spec.is_fork_active_at_block(Hardfork::Bedrock, 0));
assert!(!chain_spec.is_fork_active_at_timestamp(Hardfork::Regolith, 0));
assert!(!chain_spec.is_fork_active_at_timestamp(Hardfork::Canyon, 0));
assert!(!chain_spec.is_fork_active_at_timestamp(Hardfork::Ecotone, 0));
assert!(!chain_spec.is_fork_active_at_timestamp(Hardfork::Fjord, 0));

assert!(chain_spec.is_fork_active_at_block(Hardfork::Bedrock, 10));
assert!(chain_spec.is_fork_active_at_timestamp(Hardfork::Regolith, 20));
assert!(chain_spec.is_fork_active_at_timestamp(Hardfork::Canyon, 30));
assert!(chain_spec.is_fork_active_at_timestamp(Hardfork::Ecotone, 40));
assert!(chain_spec.is_fork_active_at_timestamp(Hardfork::Fjord, 50));
}

#[cfg(feature = "optimism")]
Expand All @@ -3363,10 +3384,11 @@ Post-merge hard forks (timestamp based):
"regolithTime": 20,
"canyonTime": 30,
"ecotoneTime": 40,
"fjordTime": 50,
"optimism": {
"eip1559Elasticity": 50,
"eip1559Denominator": 60,
"eip1559DenominatorCanyon": 70
"eip1559Elasticity": 60,
"eip1559Denominator": 70,
"eip1559DenominatorCanyon": 80
}
}
}
Expand All @@ -3381,14 +3403,16 @@ Post-merge hard forks (timestamp based):
assert_eq!(actual_canyon_timestamp, Some(serde_json::Value::from(30)).as_ref());
let actual_ecotone_timestamp = genesis.config.extra_fields.get("ecotoneTime");
assert_eq!(actual_ecotone_timestamp, Some(serde_json::Value::from(40)).as_ref());
let actual_fjord_timestamp = genesis.config.extra_fields.get("fjordTime");
assert_eq!(actual_fjord_timestamp, Some(serde_json::Value::from(50)).as_ref());

let optimism_object = genesis.config.extra_fields.get("optimism").unwrap();
assert_eq!(
optimism_object,
&serde_json::json!({
"eip1559Elasticity": 50,
"eip1559Denominator": 60,
"eip1559DenominatorCanyon": 70
"eip1559Elasticity": 60,
"eip1559Denominator": 70,
"eip1559DenominatorCanyon": 80
})
);

Expand All @@ -3398,8 +3422,8 @@ Post-merge hard forks (timestamp based):
chain_spec.base_fee_params,
BaseFeeParamsKind::Variable(
vec![
(Hardfork::London, BaseFeeParams::new(60, 50)),
(Hardfork::Canyon, BaseFeeParams::new(70, 50)),
(Hardfork::London, BaseFeeParams::new(70, 60)),
(Hardfork::Canyon, BaseFeeParams::new(80, 60)),
]
.into()
)
Expand All @@ -3409,10 +3433,12 @@ Post-merge hard forks (timestamp based):
assert!(!chain_spec.is_fork_active_at_timestamp(Hardfork::Regolith, 0));
assert!(!chain_spec.is_fork_active_at_timestamp(Hardfork::Canyon, 0));
assert!(!chain_spec.is_fork_active_at_timestamp(Hardfork::Ecotone, 0));
assert!(!chain_spec.is_fork_active_at_timestamp(Hardfork::Fjord, 0));

assert!(chain_spec.is_fork_active_at_block(Hardfork::Bedrock, 10));
assert!(chain_spec.is_fork_active_at_timestamp(Hardfork::Regolith, 20));
assert!(chain_spec.is_fork_active_at_timestamp(Hardfork::Canyon, 30));
assert!(chain_spec.is_fork_active_at_timestamp(Hardfork::Ecotone, 40));
assert!(chain_spec.is_fork_active_at_timestamp(Hardfork::Fjord, 50));
}
}
9 changes: 7 additions & 2 deletions crates/primitives/src/revm/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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::Ecotone).active_at_head(&block) {
if chain_spec.fork(Hardfork::Fjord).active_at_head(&block) {
return revm_primitives::FJORD
} else if chain_spec.fork(Hardfork::Ecotone).active_at_head(&block) {
return revm_primitives::ECOTONE
} else if chain_spec.fork(Hardfork::Canyon).active_at_head(&block) {
return revm_primitives::CANYON
Expand Down Expand Up @@ -149,7 +151,10 @@ mod tests {
let cs = ChainSpecBuilder::mainnet().chain(crate::Chain::from_id(10));
f(cs).build()
}

assert_eq!(
revm_spec(&op_cs(|cs| cs.fjord_activated()), Head::default()),
revm_primitives::FJORD
);
assert_eq!(
revm_spec(&op_cs(|cs| cs.ecotone_activated()), Head::default()),
revm_primitives::ECOTONE
Expand Down
Loading