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

chore: flatten eip-7685 requests into a single opaque list #1383

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ alloy-chains = { version = "0.1.18", default-features = false }

# eips
alloy-eip2930 = { version = "0.1.0", default-features = false }
alloy-eip7702 = { version = "0.1.1", default-features = false }
alloy-eip7702 = { version = "0.2.0", default-features = false }

# ethereum
ethereum_ssz_derive = "0.8"
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ mod tests {
storage_keys: vec![B256::left_padding_from(&[9])],
}]),
authorization_list: vec![(Authorization {
chain_id: U256::from(1),
chain_id: 1,
address: Address::left_padding_from(&[10]),
nonce: 1u64,
})
Expand Down Expand Up @@ -1051,7 +1051,7 @@ mod tests {
storage_keys: vec![B256::random()],
}]),
authorization_list: vec![(Authorization {
chain_id: U256::from(1),
chain_id: 1,
address: Address::left_padding_from(&[1]),
nonce: 1u64,
})
Expand Down
4 changes: 2 additions & 2 deletions crates/network/src/ethereum/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ mod tests {
};
use alloy_consensus::{BlobTransactionSidecar, TxEip1559, TxType, TypedTransaction};
use alloy_eips::eip7702::Authorization;
use alloy_primitives::{Address, Signature, U256};
use alloy_primitives::{Address, Signature};
use alloy_rpc_types_eth::{AccessList, TransactionRequest};
use std::str::FromStr;

Expand Down Expand Up @@ -268,7 +268,7 @@ mod tests {
.with_to(Address::ZERO)
.with_access_list(AccessList::default())
.with_authorization_list(vec![(Authorization {
chain_id: U256::from(1),
chain_id: 1,
address: Address::left_padding_from(&[1]),
nonce: 1u64,
})
Expand Down
17 changes: 11 additions & 6 deletions crates/provider/src/ext/engine.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::Provider;
use alloy_network::Network;
use alloy_primitives::{BlockHash, B256};
use alloy_primitives::{BlockHash, Bytes, 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,10 @@ 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,
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,12 +211,16 @@ where

async fn new_payload_v4(
&self,
payload: ExecutionPayloadV4,
payload: ExecutionPayloadV3,
versioned_hashes: Vec<B256>,
parent_beacon_block_root: B256,
execution_requests: Vec<Bytes>,
) -> TransportResult<PayloadStatus> {
self.client()
.request("engine_newPayloadV4", (payload, versioned_hashes, parent_beacon_block_root))
.request(
"engine_newPayloadV4",
(payload, versioned_hashes, parent_beacon_block_root, execution_requests),
)
.await
}

Expand Down
84 changes: 1 addition & 83 deletions crates/rpc-types-beacon/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
//! See also <https://github.com/ethereum/consensus-specs/blob/master/specs/deneb/beacon-chain.md#executionpayload>

use crate::{withdrawals::BeaconWithdrawal, BlsPublicKey};
use alloy_eips::{
eip4895::Withdrawal, eip6110::DepositRequest, eip7002::WithdrawalRequest,
eip7251::ConsolidationRequest,
};
use alloy_eips::eip4895::Withdrawal;
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 +402,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 +412,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 +423,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 +441,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 +457,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
9 changes: 5 additions & 4 deletions crates/rpc-types-beacon/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
//! See also <https://flashbots.github.io/relay-specs/>

use crate::{BlsPublicKey, BlsSignature};
use alloy_primitives::{Address, B256, U256};
use alloy_primitives::{Address, Bytes, 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