diff --git a/beacon_node/builder_client/src/lib.rs b/beacon_node/builder_client/src/lib.rs index 089e576f504..aebc3f5e2be 100644 --- a/beacon_node/builder_client/src/lib.rs +++ b/beacon_node/builder_client/src/lib.rs @@ -1,8 +1,8 @@ use eth2::types::builder_bid::SignedBuilderBid; use eth2::types::payload::FullPayloadContents; use eth2::types::{ - AbstractExecPayload, BlindedPayload, EthSpec, ExecutionBlockHash, ForkVersionedResponse, - PublicKeyBytes, SignedBlockContents, SignedValidatorRegistrationData, Slot, + BlindedPayload, EthSpec, ExecutionBlockHash, ForkVersionedResponse, PublicKeyBytes, + SignedBlockContents, SignedValidatorRegistrationData, Slot, }; pub use eth2::Error; use eth2::{ok_or_error, StatusCode}; @@ -163,12 +163,12 @@ impl BuilderHttpClient { } /// `GET /eth/v1/builder/header` - pub async fn get_builder_header>( + pub async fn get_builder_header( &self, slot: Slot, parent_hash: ExecutionBlockHash, pubkey: &PublicKeyBytes, - ) -> Result>>, Error> { + ) -> Result>>, Error> { let mut path = self.server.full.clone(); path.path_segments_mut() diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index ff49583b9da..6709abbae9e 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -89,23 +89,29 @@ pub enum ProvenancedPayload

{ Builder(P), } -impl> TryFrom> +impl> TryFrom> for ProvenancedPayload> { type Error = Error; - fn try_from(value: BuilderBid) -> Result { + fn try_from(value: BuilderBid) -> Result { let block_proposal_contents = match value { BuilderBid::Merge(builder_bid) => BlockProposalContents::Payload { - payload: builder_bid.header.into(), + payload: ExecutionPayloadHeader::Merge(builder_bid.header) + .try_into() + .map_err(|_| Error::InvalidPayloadConversion)?, block_value: builder_bid.value, }, BuilderBid::Capella(builder_bid) => BlockProposalContents::Payload { - payload: builder_bid.header.into(), + payload: ExecutionPayloadHeader::Capella(builder_bid.header) + .try_into() + .map_err(|_| Error::InvalidPayloadConversion)?, block_value: builder_bid.value, }, BuilderBid::Deneb(builder_bid) => BlockProposalContents::PayloadAndBlobs { - payload: builder_bid.header.into(), + payload: ExecutionPayloadHeader::Deneb(builder_bid.header) + .try_into() + .map_err(|_| Error::InvalidPayloadConversion)?, block_value: builder_bid.value, kzg_commitments: builder_bid.blinded_blobs_bundle.commitments, blobs: BlobItems::try_from_blob_roots(builder_bid.blinded_blobs_bundle.blob_roots) @@ -138,6 +144,7 @@ pub enum Error { InvalidJWTSecret(String), InvalidForkForPayload, InvalidPayloadBody(String), + InvalidPayloadConversion, InvalidBlobConversion(String), BeaconStateError(BeaconStateError), } @@ -844,7 +851,7 @@ impl ExecutionLayer { let ((relay_result, relay_duration), (local_result, local_duration)) = tokio::join!( timed_future(metrics::GET_BLINDED_PAYLOAD_BUILDER, async { builder - .get_builder_header::(slot, parent_hash, &pubkey) + .get_builder_header::(slot, parent_hash, &pubkey) .await }), timed_future(metrics::GET_BLINDED_PAYLOAD_LOCAL, async { @@ -1991,8 +1998,8 @@ impl fmt::Display for InvalidBuilderPayload { } /// Perform some cursory, non-exhaustive validation of the bid returned from the builder. -fn verify_builder_bid>( - bid: &ForkVersionedResponse>, +fn verify_builder_bid( + bid: &ForkVersionedResponse>, parent_hash: ExecutionBlockHash, payload_attributes: &PayloadAttributes, block_number: Option, @@ -2019,7 +2026,7 @@ fn verify_builder_bid>( .ok() .cloned() .map(|withdrawals| Withdrawals::::from(withdrawals).tree_hash_root()); - let payload_withdrawals_root = header.withdrawals_root().ok(); + let payload_withdrawals_root = header.withdrawals_root().ok().copied(); if *payload_value < profit_threshold { Err(Box::new(InvalidBuilderPayload::LowValue { diff --git a/consensus/types/src/builder_bid.rs b/consensus/types/src/builder_bid.rs index 8d4927f0bfd..e0c0bb306e8 100644 --- a/consensus/types/src/builder_bid.rs +++ b/consensus/types/src/builder_bid.rs @@ -1,7 +1,8 @@ use crate::beacon_block_body::KzgCommitments; use crate::{ - AbstractExecPayload, BlobRootsList, ChainSpec, EthSpec, ExecPayload, ForkName, - ForkVersionDeserialize, KzgProofs, SignedRoot, Uint256, + BlobRootsList, ChainSpec, EthSpec, ExecutionPayloadHeaderCapella, ExecutionPayloadHeaderDeneb, + ExecutionPayloadHeaderMerge, ExecutionPayloadHeaderRef, ForkName, ForkVersionDeserialize, + KzgProofs, SignedRoot, Uint256, }; use bls::PublicKeyBytes; use bls::Signature; @@ -22,26 +23,20 @@ pub struct BlindedBlobsBundle { variants(Merge, Capella, Deneb), variant_attributes( derive(PartialEq, Debug, Serialize, Deserialize, TreeHash, Clone), - serde( - bound = "E: EthSpec, Payload: AbstractExecPayload", - deny_unknown_fields - ) - ) + serde(bound = "E: EthSpec", deny_unknown_fields) + ), + map_ref_into(ExecutionPayloadHeaderRef) )] #[derive(PartialEq, Debug, Serialize, Deserialize, TreeHash, Clone)] -#[serde( - bound = "E: EthSpec, Payload: AbstractExecPayload", - deny_unknown_fields, - untagged -)] +#[serde(bound = "E: EthSpec", deny_unknown_fields, untagged)] #[tree_hash(enum_behaviour = "transparent")] -pub struct BuilderBid> { +pub struct BuilderBid { #[superstruct(only(Merge), partial_getter(rename = "header_merge"))] - pub header: Payload::Merge, + pub header: ExecutionPayloadHeaderMerge, #[superstruct(only(Capella), partial_getter(rename = "header_capella"))] - pub header: Payload::Capella, + pub header: ExecutionPayloadHeaderCapella, #[superstruct(only(Deneb), partial_getter(rename = "header_deneb"))] - pub header: Payload::Deneb, + pub header: ExecutionPayloadHeaderDeneb, #[superstruct(only(Deneb))] pub blinded_blobs_bundle: BlindedBlobsBundle, #[serde(with = "serde_utils::quoted_u256")] @@ -49,35 +44,31 @@ pub struct BuilderBid> { pub pubkey: PublicKeyBytes, } -impl> BuilderBid { - pub fn header(&self) -> Payload::Ref<'_> { +impl BuilderBid { + pub fn header(&self) -> ExecutionPayloadHeaderRef<'_, E> { self.to_ref().header() } } -impl<'a, T: EthSpec, Payload: AbstractExecPayload> BuilderBidRef<'a, T, Payload> { - pub fn header(&self) -> Payload::Ref<'a> { - match self { - Self::Merge(bid) => Payload::Ref::from(&bid.header), - Self::Capella(bid) => Payload::Ref::from(&bid.header), - Self::Deneb(bid) => Payload::Ref::from(&bid.header), - } +impl<'a, E: EthSpec> BuilderBidRef<'a, E> { + pub fn header(&self) -> ExecutionPayloadHeaderRef<'a, E> { + map_builder_bid_ref_into_execution_payload_header_ref!(&'a _, self, |bid, cons| cons( + &bid.header + )) } } -impl> SignedRoot for BuilderBid {} +impl SignedRoot for BuilderBid {} /// Validator registration, for use in interacting with servers implementing the builder API. #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)] -#[serde(bound = "E: EthSpec, Payload: ExecPayload")] -pub struct SignedBuilderBid> { - pub message: BuilderBid, +#[serde(bound = "E: EthSpec")] +pub struct SignedBuilderBid { + pub message: BuilderBid, pub signature: Signature, } -impl> ForkVersionDeserialize - for BuilderBid -{ +impl ForkVersionDeserialize for BuilderBid { fn deserialize_by_fork<'de, D: Deserializer<'de>>( value: serde_json::value::Value, fork_name: ForkName, @@ -99,9 +90,7 @@ impl> ForkVersionDeserialize } } -impl> ForkVersionDeserialize - for SignedBuilderBid -{ +impl ForkVersionDeserialize for SignedBuilderBid { fn deserialize_by_fork<'de, D: Deserializer<'de>>( value: serde_json::value::Value, fork_name: ForkName, @@ -120,7 +109,7 @@ impl> ForkVersionDeserialize } } -impl> SignedBuilderBid { +impl SignedBuilderBid { pub fn verify_signature(&self, spec: &ChainSpec) -> bool { self.message .pubkey()