From 75b31efb0d1a00cb0d4d12acbbccc56804f730fc Mon Sep 17 00:00:00 2001 From: Joseph Zhao <65984904+programskillforverification@users.noreply.github.com> Date: Thu, 19 Dec 2024 19:36:57 +0800 Subject: [PATCH] [Feature] Use Upstream Forkchoice Version (#347) ## Motivation close #326 --- crates/rpc-types-engine/Cargo.toml | 1 - crates/rpc-types-engine/src/lib.rs | 3 +- crates/rpc-types-engine/src/versions.rs | 69 ------------------------- 3 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 crates/rpc-types-engine/src/versions.rs diff --git a/crates/rpc-types-engine/Cargo.toml b/crates/rpc-types-engine/Cargo.toml index 5aadd780..40743c4b 100644 --- a/crates/rpc-types-engine/Cargo.toml +++ b/crates/rpc-types-engine/Cargo.toml @@ -18,7 +18,6 @@ workspace = true # Workspace op-alloy-consensus.workspace = true op-alloy-protocol.workspace = true -op-alloy-genesis.workspace = true # Alloy alloy-primitives.workspace = true diff --git a/crates/rpc-types-engine/src/lib.rs b/crates/rpc-types-engine/src/lib.rs index 41d73a35..fe13334a 100644 --- a/crates/rpc-types-engine/src/lib.rs +++ b/crates/rpc-types-engine/src/lib.rs @@ -9,8 +9,7 @@ extern crate alloc; -mod versions; -pub use versions::ForkchoiceUpdateVersion; +pub use alloy_rpc_types_engine::ForkchoiceUpdateVersion; mod attributes; pub use attributes::{OpAttributesWithParent, OpPayloadAttributes}; diff --git a/crates/rpc-types-engine/src/versions.rs b/crates/rpc-types-engine/src/versions.rs deleted file mode 100644 index 24e5456b..00000000 --- a/crates/rpc-types-engine/src/versions.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! Versions for the engine api. - -use op_alloy_genesis::RollupConfig; - -/// The version of the engine api. -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[repr(u32)] -pub enum ForkchoiceUpdateVersion { - /// Version 1 of the engine api. - V1 = 1, - /// Version 2 of the engine api. - V2 = 2, - /// Version 3 of the engine api. - V3 = 3, - /// Version 4 of the engine api. - V4 = 4, -} - -impl ForkchoiceUpdateVersion { - /// Constructs a `ForkchoiceUpdateVersion` from a [RollupConfig] and timestamp. - /// - /// See: - pub fn from_config(config: &RollupConfig, timestamp: u64) -> Self { - if config.is_ecotone_active(timestamp) { - // Cancun - Self::V3 - } else if config.is_canyon_active(timestamp) { - // Shanghai - Self::V2 - } else { - // According to Ethereum engine API spec, we can use fcuV2 here, - // but upstream Geth v1.13.11 does not accept V2 before Shanghai. - Self::V1 - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_fcu_from_config_ecotone() { - let config = - RollupConfig { ecotone_time: Some(10), canyon_time: Some(5), ..Default::default() }; - let expected = ForkchoiceUpdateVersion::V3; - assert_eq!(ForkchoiceUpdateVersion::from_config(&config, 10), expected); - let expected = ForkchoiceUpdateVersion::V2; - assert_eq!(ForkchoiceUpdateVersion::from_config(&config, 5), expected); - let expected = ForkchoiceUpdateVersion::V1; - assert_eq!(ForkchoiceUpdateVersion::from_config(&config, 0), expected); - } - - #[test] - fn test_fcu_from_config_canyon() { - let config = RollupConfig { canyon_time: Some(1), ..Default::default() }; - let expected = ForkchoiceUpdateVersion::V2; - assert_eq!(ForkchoiceUpdateVersion::from_config(&config, 1), expected); - let expected = ForkchoiceUpdateVersion::V1; - assert_eq!(ForkchoiceUpdateVersion::from_config(&config, 0), expected); - } - - #[test] - fn test_fcu_from_config() { - let config = RollupConfig::default(); - let expected = ForkchoiceUpdateVersion::V1; - assert_eq!(ForkchoiceUpdateVersion::from_config(&config, 0), expected); - } -}