From 60acd18844aa84c378046cf659af521b52dc90b4 Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Thu, 26 Sep 2024 15:11:13 +0200 Subject: [PATCH] chore: flatten eip-7685 requests into a single list --- crates/rpc-types-beacon/Cargo.toml | 1 + crates/rpc-types-beacon/src/payload.rs | 33 ++++------------------ crates/rpc-types-engine/src/payload.rs | 39 +++++++------------------- 3 files changed, 17 insertions(+), 56 deletions(-) diff --git a/crates/rpc-types-beacon/Cargo.toml b/crates/rpc-types-beacon/Cargo.toml index e4219e81dda..b4287d6d3ea 100644 --- a/crates/rpc-types-beacon/Cargo.toml +++ b/crates/rpc-types-beacon/Cargo.toml @@ -19,6 +19,7 @@ workspace = true [dependencies] # ethereum +alloy-consensus = { workspace = true, features = ["serde"] } alloy-eips = { workspace = true, features = ["serde"] } alloy-rpc-types-engine = { workspace = true, features = ["serde"] } alloy-primitives.workspace = true diff --git a/crates/rpc-types-beacon/src/payload.rs b/crates/rpc-types-beacon/src/payload.rs index 3029755fc1d..2eea8465ab9 100644 --- a/crates/rpc-types-beacon/src/payload.rs +++ b/crates/rpc-types-beacon/src/payload.rs @@ -9,6 +9,7 @@ //! See also use crate::{withdrawals::BeaconWithdrawal, BlsPublicKey}; +use alloy_consensus::Requests; use alloy_eips::{ eip4895::Withdrawal, eip6110::DepositRequest, eip7002::WithdrawalRequest, eip7251::ConsolidationRequest, @@ -412,42 +413,20 @@ struct BeaconExecutionPayloadV4<'a> { /// Inner V1 payload #[serde(flatten)] payload_inner: BeaconExecutionPayloadV3<'a>, - deposit_requests: Vec, - withdrawal_requests: Vec, - consolidation_requests: Vec, + requests: Requests, } impl<'a> From> for ExecutionPayloadV4 { fn from(payload: BeaconExecutionPayloadV4<'a>) -> Self { - let BeaconExecutionPayloadV4 { - payload_inner, - deposit_requests, - withdrawal_requests, - consolidation_requests, - } = payload; - Self { - payload_inner: payload_inner.into(), - deposit_requests, - withdrawal_requests, - consolidation_requests, - } + let BeaconExecutionPayloadV4 { payload_inner, requests } = payload; + Self { payload_inner: payload_inner.into(), requests } } } impl<'a> From<&'a ExecutionPayloadV4> for BeaconExecutionPayloadV4<'a> { fn from(value: &'a ExecutionPayloadV4) -> Self { - let ExecutionPayloadV4 { - payload_inner, - deposit_requests, - withdrawal_requests, - consolidation_requests, - } = value; - BeaconExecutionPayloadV4 { - payload_inner: payload_inner.into(), - deposit_requests: deposit_requests.clone(), - withdrawal_requests: withdrawal_requests.clone(), - consolidation_requests: consolidation_requests.clone(), - } + let ExecutionPayloadV4 { payload_inner, requests } = value; + BeaconExecutionPayloadV4 { payload_inner: payload_inner.into(), requests: requests.clone() } } } diff --git a/crates/rpc-types-engine/src/payload.rs b/crates/rpc-types-engine/src/payload.rs index 86c030f9503..c3481c4af51 100644 --- a/crates/rpc-types-engine/src/payload.rs +++ b/crates/rpc-types-engine/src/payload.rs @@ -4,7 +4,7 @@ use alloc::{ string::{String, ToString}, vec::Vec, }; -use alloy_consensus::{Blob, Bytes48}; +use alloy_consensus::{Blob, Bytes48, Requests}; use alloy_eips::{ eip4844::BlobTransactionSidecar, eip4895::Withdrawal, eip6110::DepositRequest, eip7002::WithdrawalRequest, eip7251::ConsolidationRequest, BlockNumHash, @@ -460,15 +460,8 @@ pub struct ExecutionPayloadV4 { /// Array of deposit requests. /// /// This maps directly to the deposit requests defined in [EIP-6110](https://eips.ethereum.org/EIPS/eip-6110). - pub deposit_requests: Vec, - /// Array of execution layer triggerable withdrawal requests. - /// - /// See [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002). - pub withdrawal_requests: Vec, - /// Array of consolidation requests. - /// - /// See [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251). - pub consolidation_requests: Vec, + // todo + pub requests: Requests, } impl ExecutionPayloadV4 { @@ -539,9 +532,7 @@ impl ssz::Decode for ExecutionPayloadV4 { blob_gas_used: decoder.decode_next()?, excess_blob_gas: decoder.decode_next()?, }, - deposit_requests: decoder.decode_next()?, - withdrawal_requests: decoder.decode_next()?, - consolidation_requests: decoder.decode_next()?, + requests: decoder.decode_next()?, }) } } @@ -579,9 +570,7 @@ impl ssz::Encode for ExecutionPayloadV4 { encoder.append(&self.payload_inner.payload_inner.withdrawals); encoder.append(&self.payload_inner.blob_gas_used); encoder.append(&self.payload_inner.excess_blob_gas); - encoder.append(&self.deposit_requests); - encoder.append(&self.withdrawal_requests); - encoder.append(&self.consolidation_requests); + encoder.append(&self.requests); encoder.finalize(); } @@ -589,9 +578,7 @@ impl ssz::Encode for ExecutionPayloadV4 { fn ssz_bytes_len(&self) -> usize { ::ssz_bytes_len(&self.payload_inner) + ssz::BYTES_PER_LENGTH_OFFSET * 3 - + self.deposit_requests.ssz_bytes_len() - + self.withdrawal_requests.ssz_bytes_len() - + self.consolidation_requests.ssz_bytes_len() + + self.requests.ssz_bytes_len() } } @@ -1020,8 +1007,9 @@ pub struct ExecutionPayloadBodyV1 { pub withdrawals: Option>, } +// todo update /// This structure has the syntax of [`ExecutionPayloadBodyV1`] and appends the new fields: -/// depositRequests and withdrawalRequests. +/// requests. /// /// See also: #[derive(Clone, Debug, PartialEq, Eq)] @@ -1034,18 +1022,11 @@ pub struct ExecutionPayloadBodyV2 { /// /// Will always be `None` if pre shanghai. pub withdrawals: Option>, + // todo update /// Array of deposits requests. /// /// Will always be `None` if pre prague. - pub deposit_requests: Option>, - /// Array of withdrawal requests. - /// - /// Will always be `None` if pre prague. - pub withdrawal_requests: Option>, - /// Array of consolidation requests. - /// - /// Will always be `None` if pre prague. - pub consolidation_requests: Option>, + pub requests: Option, } /// This structure contains the attributes required to initiate a payload build process in the