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(l2-withdrawals): Impl conversion to block for OpExecutionPayloadV4 #435

Merged
merged 1 commit into from
Feb 13, 2025
Merged
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
21 changes: 20 additions & 1 deletion crates/rpc-types-engine/src/payload/v4.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Optimism execution payload envelope V3.

use alloc::vec::Vec;
use alloy_consensus::Block;
use alloy_eips::Decodable2718;
use alloy_primitives::{Bytes, B256, U256};
use alloy_rpc_types_engine::{BlobsBundleV1, ExecutionPayloadV3};
use alloy_rpc_types_engine::{BlobsBundleV1, ExecutionPayloadV3, PayloadError};

/// The Opstack execution payload for `newPayloadV4` of the engine API introduced with isthmus.
/// See also <https://specs.optimism.io/protocol/isthmus/exec-engine.html#engine_newpayloadv4-api>
Expand All @@ -19,6 +21,23 @@ pub struct OpExecutionPayloadV4 {
pub withdrawals_root: B256,
}

impl OpExecutionPayloadV4 {
/// Converts [`OpExecutionPayloadV4`] to [`Block`].
///
/// This performs the same conversion as the underlying V3 payload, but inserts the L2
/// withdrawals root.
///
/// See also [`ExecutionPayloadV3::try_into_block`].
pub fn try_into_block<T: Decodable2718>(self) -> Result<Block<T>, PayloadError> {
let mut base_block = self.payload_inner.try_into_block()?;

// overwrite l1 withdrawals root with l2 withdrawals root
base_block.header.withdrawals_root = Some(self.withdrawals_root);

Ok(base_block)
}
}

/// This structure maps for the return value of `engine_getPayload` of the beacon chain spec, for
/// V4.
///
Expand Down