From 5c231898adaa1975920d5ecf47d43c1e7908b3bd Mon Sep 17 00:00:00 2001 From: Steven <112043913+stevencartavia@users.noreply.github.com> Date: Sat, 8 Feb 2025 01:22:22 -0600 Subject: [PATCH] feat: Add `is_vx` helpers for EngineApiMessageVersion (#14323) --- crates/payload/primitives/src/lib.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/payload/primitives/src/lib.rs b/crates/payload/primitives/src/lib.rs index 03977eb9c..03a44dabd 100644 --- a/crates/payload/primitives/src/lib.rs +++ b/crates/payload/primitives/src/lib.rs @@ -58,7 +58,7 @@ pub fn validate_payload_timestamp( timestamp: u64, ) -> Result<(), EngineObjectValidationError> { let is_cancun = chain_spec.is_cancun_active_at_timestamp(timestamp); - if version == EngineApiMessageVersion::V2 && is_cancun { + if version.is_v2() && is_cancun { // From the Engine API spec: // // ### Update the methods of previous forks @@ -79,7 +79,7 @@ pub fn validate_payload_timestamp( return Err(EngineObjectValidationError::UnsupportedFork) } - if version == EngineApiMessageVersion::V3 && !is_cancun { + if version.is_v3() && !is_cancun { // From the Engine API spec: // // @@ -102,7 +102,7 @@ pub fn validate_payload_timestamp( } let is_prague = chain_spec.is_prague_active_at_timestamp(timestamp); - if version == EngineApiMessageVersion::V4 && !is_prague { + if version.is_v4() && !is_prague { // From the Engine API spec: // // @@ -347,6 +347,28 @@ pub enum EngineApiMessageVersion { V4 = 4, } +impl EngineApiMessageVersion { + /// Returns true if the version is V1. + pub const fn is_v1(&self) -> bool { + matches!(self, Self::V1) + } + + /// Returns true if the version is V2. + pub const fn is_v2(&self) -> bool { + matches!(self, Self::V2) + } + + /// Returns true if the version is V3. + pub const fn is_v3(&self) -> bool { + matches!(self, Self::V3) + } + + /// Returns true if the version is V4. + pub const fn is_v4(&self) -> bool { + matches!(self, Self::V4) + } +} + /// Determines how we should choose the payload to return. #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum PayloadKind {