Skip to content

Commit

Permalink
chore: update engine api
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored and onbjerg committed Oct 18, 2024
1 parent 3170c6f commit c5911ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 272 deletions.
10 changes: 6 additions & 4 deletions crates/provider/src/ext/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use alloy_primitives::{BlockHash, B256};
use alloy_rpc_types_engine::{
ClientVersionV1, ExecutionPayloadBodiesV1, ExecutionPayloadEnvelopeV2,
ExecutionPayloadEnvelopeV3, ExecutionPayloadEnvelopeV4, ExecutionPayloadInputV2,
ExecutionPayloadV1, ExecutionPayloadV3, ExecutionPayloadV4, ForkchoiceState, ForkchoiceUpdated,
PayloadAttributes, PayloadId, PayloadStatus,
ExecutionPayloadV1, ExecutionPayloadV3, ForkchoiceState, ForkchoiceUpdated, PayloadAttributes,
PayloadId, PayloadStatus,
};
use alloy_transport::{Transport, TransportResult};

Expand Down Expand Up @@ -46,9 +46,11 @@ pub trait EngineApi<N, T>: Send + Sync {
/// See also <https://github.com/ethereum/execution-apis/blob/03911ffc053b8b806123f1fc237184b0092a485a/src/engine/prague.md#engine_newpayloadv4>
async fn new_payload_v4(
&self,
payload: ExecutionPayloadV4,
payload: ExecutionPayloadV3,
versioned_hashes: Vec<B256>,
parent_beacon_block_root: B256,
// TODO
execution_requests: Vec<Bytes>,
) -> TransportResult<PayloadStatus>;

/// Updates the execution layer client with the given fork choice, as specified for the Paris
Expand Down Expand Up @@ -210,7 +212,7 @@ where

async fn new_payload_v4(
&self,
payload: ExecutionPayloadV4,
payload: ExecutionPayloadV3,
versioned_hashes: Vec<B256>,
parent_beacon_block_root: B256,
) -> TransportResult<PayloadStatus> {
Expand Down
79 changes: 0 additions & 79 deletions crates/rpc-types-beacon/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use alloy_eips::{
use alloy_primitives::{Address, Bloom, Bytes, B256, U256};
use alloy_rpc_types_engine::{
ExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3,
ExecutionPayloadV4,
};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::{serde_as, DeserializeAs, DisplayFromStr, SerializeAs};
Expand Down Expand Up @@ -406,76 +405,6 @@ pub mod beacon_payload_v3 {
}
}

#[serde_as]
#[derive(Debug, Serialize, Deserialize)]
struct BeaconExecutionPayloadV4<'a> {
/// Inner V1 payload
#[serde(flatten)]
payload_inner: BeaconExecutionPayloadV3<'a>,
deposit_requests: Vec<DepositRequest>,
withdrawal_requests: Vec<WithdrawalRequest>,
consolidation_requests: Vec<ConsolidationRequest>,
}

impl<'a> From<BeaconExecutionPayloadV4<'a>> 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,
}
}
}

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(),
}
}
}

/// A helper serde module to convert from/to the Beacon API which uses quoted decimals rather than
/// big-endian hex.
pub mod beacon_payload_v4 {
use super::*;

/// Serialize the payload attributes for the beacon API.
pub fn serialize<S>(
payload_attributes: &ExecutionPayloadV4,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
BeaconExecutionPayloadV4::from(payload_attributes).serialize(serializer)
}

/// Deserialize the payload attributes for the beacon API.
pub fn deserialize<'de, D>(deserializer: D) -> Result<ExecutionPayloadV4, D::Error>
where
D: Deserializer<'de>,
{
BeaconExecutionPayloadV4::deserialize(deserializer).map(Into::into)
}
}

/// Represents all possible payload versions.
#[derive(Debug, Serialize)]
#[serde(untagged)]
Expand All @@ -486,8 +415,6 @@ enum BeaconExecutionPayload<'a> {
V2(BeaconExecutionPayloadV2<'a>),
/// V3 payload
V3(BeaconExecutionPayloadV3<'a>),
/// V4 payload
V4(BeaconExecutionPayloadV4<'a>),
}

// Deserializes untagged ExecutionPayload by trying each variant in falling order
Expand All @@ -499,13 +426,11 @@ impl<'de> Deserialize<'de> for BeaconExecutionPayload<'de> {
#[derive(Deserialize)]
#[serde(untagged)]
enum BeaconExecutionPayloadDesc<'a> {
V4(BeaconExecutionPayloadV4<'a>),
V3(BeaconExecutionPayloadV3<'a>),
V2(BeaconExecutionPayloadV2<'a>),
V1(BeaconExecutionPayloadV1<'a>),
}
match BeaconExecutionPayloadDesc::deserialize(deserializer)? {
BeaconExecutionPayloadDesc::V4(payload) => Ok(Self::V4(payload)),
BeaconExecutionPayloadDesc::V3(payload) => Ok(Self::V3(payload)),
BeaconExecutionPayloadDesc::V2(payload) => Ok(Self::V2(payload)),
BeaconExecutionPayloadDesc::V1(payload) => Ok(Self::V1(payload)),
Expand All @@ -519,7 +444,6 @@ impl<'a> From<BeaconExecutionPayload<'a>> for ExecutionPayload {
BeaconExecutionPayload::V1(payload) => Self::V1(ExecutionPayloadV1::from(payload)),
BeaconExecutionPayload::V2(payload) => Self::V2(ExecutionPayloadV2::from(payload)),
BeaconExecutionPayload::V3(payload) => Self::V3(ExecutionPayloadV3::from(payload)),
BeaconExecutionPayload::V4(payload) => Self::V4(ExecutionPayloadV4::from(payload)),
}
}
}
Expand All @@ -536,9 +460,6 @@ impl<'a> From<&'a ExecutionPayload> for BeaconExecutionPayload<'a> {
ExecutionPayload::V3(payload) => {
BeaconExecutionPayload::V3(BeaconExecutionPayloadV3::from(payload))
}
ExecutionPayload::V4(payload) => {
BeaconExecutionPayload::V4(BeaconExecutionPayloadV4::from(payload))
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/rpc-types-beacon/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{BlsPublicKey, BlsSignature};
use alloy_primitives::{Address, B256, U256};
use alloy_rpc_types_engine::{
BlobsBundleV1, ExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3,
ExecutionPayloadV4,
};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
Expand Down Expand Up @@ -148,10 +147,12 @@ pub struct SignedBidSubmissionV4 {
/// The [`BidTrace`] message associated with the submission.
pub message: BidTrace,
/// The execution payload for the submission.
#[serde(with = "crate::payload::beacon_payload_v4")]
pub execution_payload: ExecutionPayloadV4,
#[serde(with = "crate::payload::beacon_payload_v3")]
pub execution_payload: ExecutionPayloadV3,
/// The Electra block bundle for this bid.
pub blobs_bundle: BlobsBundleV1,
/// The Pectra execution requests for this bid.
pub execution_requests: Vec<Bytes>,
/// The signature associated with the submission.
pub signature: BlsSignature,
}
Expand Down
Loading

0 comments on commit c5911ff

Please sign in to comment.