diff --git a/crates/payload/primitives/src/lib.rs b/crates/payload/primitives/src/lib.rs index 03977eb9ce..03a44dabd8 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 {