From 954442fd87be346f26ac898187ab0bb180ba43b5 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 27 Dec 2024 16:08:25 +0100 Subject: [PATCH] feat: add try into block with sidecar --- crates/rpc-types-engine/src/payload.rs | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/rpc-types-engine/src/payload.rs b/crates/rpc-types-engine/src/payload.rs index c5b539cc9b5..85e6320bdb9 100644 --- a/crates/rpc-types-engine/src/payload.rs +++ b/crates/rpc-types-engine/src/payload.rs @@ -1,6 +1,6 @@ //! Payload types. -use crate::PayloadError; +use crate::{ExecutionPayloadSidecar, PayloadError}; use alloc::{ string::{String, ToString}, vec::Vec, @@ -682,7 +682,34 @@ pub enum ExecutionPayload { } impl ExecutionPayload { - /// Converts [`ExecutionPayloadV1`] to [`Block`] + /// Tries to create a new unsealed block from the given payload and payload sidecar. + /// + /// Performs additional validation of `extra_data` and `base_fee_per_gas` fields. + /// + /// # Note + /// + /// The log bloom is assumed to be validated during serialization. + /// + /// See + pub fn try_into_block_with_sidecar( + self, + sidecar: &ExecutionPayloadSidecar, + ) -> Result, PayloadError> { + let mut base_payload = self.try_into_block()?; + base_payload.header.parent_beacon_block_root = sidecar.parent_beacon_block_root(); + base_payload.header.requests_hash = sidecar.requests_hash(); + + Ok(base_payload) + } + + /// Converts [`ExecutionPayloadV1`] to [`Block`]. + /// + /// Caution: This does not set fields that are not part of the payload and only part of the + /// [`ExecutionPayloadSidecar`]: + /// - parent_beacon_block_root + /// - requests_hash + /// + /// See also: [`ExecutionPayload::try_into_block_with_sidecar`] pub fn try_into_block(self) -> Result, PayloadError> { match self { Self::V1(payload) => payload.try_into_block(),