Skip to content

Commit

Permalink
remove generic from builder bid
Browse files Browse the repository at this point in the history
  • Loading branch information
realbigsean authored and jimmygchen committed Aug 9, 2023
1 parent 1ac148c commit ee2f1a1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 49 deletions.
8 changes: 4 additions & 4 deletions beacon_node/builder_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -163,12 +163,12 @@ impl BuilderHttpClient {
}

/// `GET /eth/v1/builder/header`
pub async fn get_builder_header<E: EthSpec, Payload: AbstractExecPayload<E>>(
pub async fn get_builder_header<E: EthSpec>(
&self,
slot: Slot,
parent_hash: ExecutionBlockHash,
pubkey: &PublicKeyBytes,
) -> Result<Option<ForkVersionedResponse<SignedBuilderBid<E, Payload>>>, Error> {
) -> Result<Option<ForkVersionedResponse<SignedBuilderBid<E>>>, Error> {
let mut path = self.server.full.clone();

path.path_segments_mut()
Expand Down
25 changes: 16 additions & 9 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,29 @@ pub enum ProvenancedPayload<P> {
Builder(P),
}

impl<E: EthSpec, Payload: AbstractExecPayload<E>> TryFrom<BuilderBid<E, Payload>>
impl<E: EthSpec, Payload: AbstractExecPayload<E>> TryFrom<BuilderBid<E>>
for ProvenancedPayload<BlockProposalContents<E, Payload>>
{
type Error = Error;

fn try_from(value: BuilderBid<E, Payload>) -> Result<Self, Error> {
fn try_from(value: BuilderBid<E>) -> Result<Self, Error> {
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)
Expand Down Expand Up @@ -138,6 +144,7 @@ pub enum Error {
InvalidJWTSecret(String),
InvalidForkForPayload,
InvalidPayloadBody(String),
InvalidPayloadConversion,
InvalidBlobConversion(String),
BeaconStateError(BeaconStateError),
}
Expand Down Expand Up @@ -844,7 +851,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
let ((relay_result, relay_duration), (local_result, local_duration)) = tokio::join!(
timed_future(metrics::GET_BLINDED_PAYLOAD_BUILDER, async {
builder
.get_builder_header::<T, Payload>(slot, parent_hash, &pubkey)
.get_builder_header::<T>(slot, parent_hash, &pubkey)
.await
}),
timed_future(metrics::GET_BLINDED_PAYLOAD_LOCAL, async {
Expand Down Expand Up @@ -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<T: EthSpec, Payload: AbstractExecPayload<T>>(
bid: &ForkVersionedResponse<SignedBuilderBid<T, Payload>>,
fn verify_builder_bid<T: EthSpec>(
bid: &ForkVersionedResponse<SignedBuilderBid<T>>,
parent_hash: ExecutionBlockHash,
payload_attributes: &PayloadAttributes,
block_number: Option<u64>,
Expand All @@ -2019,7 +2026,7 @@ fn verify_builder_bid<T: EthSpec, Payload: AbstractExecPayload<T>>(
.ok()
.cloned()
.map(|withdrawals| Withdrawals::<T>::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 {
Expand Down
61 changes: 25 additions & 36 deletions consensus/types/src/builder_bid.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,62 +23,52 @@ pub struct BlindedBlobsBundle<E: EthSpec> {
variants(Merge, Capella, Deneb),
variant_attributes(
derive(PartialEq, Debug, Serialize, Deserialize, TreeHash, Clone),
serde(
bound = "E: EthSpec, Payload: AbstractExecPayload<E>",
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<E>",
deny_unknown_fields,
untagged
)]
#[serde(bound = "E: EthSpec", deny_unknown_fields, untagged)]
#[tree_hash(enum_behaviour = "transparent")]
pub struct BuilderBid<E: EthSpec, Payload: AbstractExecPayload<E>> {
pub struct BuilderBid<E: EthSpec> {
#[superstruct(only(Merge), partial_getter(rename = "header_merge"))]
pub header: Payload::Merge,
pub header: ExecutionPayloadHeaderMerge<E>,
#[superstruct(only(Capella), partial_getter(rename = "header_capella"))]
pub header: Payload::Capella,
pub header: ExecutionPayloadHeaderCapella<E>,
#[superstruct(only(Deneb), partial_getter(rename = "header_deneb"))]
pub header: Payload::Deneb,
pub header: ExecutionPayloadHeaderDeneb<E>,
#[superstruct(only(Deneb))]
pub blinded_blobs_bundle: BlindedBlobsBundle<E>,
#[serde(with = "serde_utils::quoted_u256")]
pub value: Uint256,
pub pubkey: PublicKeyBytes,
}

impl<E: EthSpec, Payload: AbstractExecPayload<E>> BuilderBid<E, Payload> {
pub fn header(&self) -> Payload::Ref<'_> {
impl<E: EthSpec> BuilderBid<E> {
pub fn header(&self) -> ExecutionPayloadHeaderRef<'_, E> {
self.to_ref().header()
}
}

impl<'a, T: EthSpec, Payload: AbstractExecPayload<T>> 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<E: EthSpec, Payload: AbstractExecPayload<E>> SignedRoot for BuilderBid<E, Payload> {}
impl<E: EthSpec> SignedRoot for BuilderBid<E> {}

/// Validator registration, for use in interacting with servers implementing the builder API.
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[serde(bound = "E: EthSpec, Payload: ExecPayload<E>")]
pub struct SignedBuilderBid<E: EthSpec, Payload: AbstractExecPayload<E>> {
pub message: BuilderBid<E, Payload>,
#[serde(bound = "E: EthSpec")]
pub struct SignedBuilderBid<E: EthSpec> {
pub message: BuilderBid<E>,
pub signature: Signature,
}

impl<T: EthSpec, Payload: AbstractExecPayload<T>> ForkVersionDeserialize
for BuilderBid<T, Payload>
{
impl<T: EthSpec> ForkVersionDeserialize for BuilderBid<T> {
fn deserialize_by_fork<'de, D: Deserializer<'de>>(
value: serde_json::value::Value,
fork_name: ForkName,
Expand All @@ -99,9 +90,7 @@ impl<T: EthSpec, Payload: AbstractExecPayload<T>> ForkVersionDeserialize
}
}

impl<T: EthSpec, Payload: AbstractExecPayload<T>> ForkVersionDeserialize
for SignedBuilderBid<T, Payload>
{
impl<T: EthSpec> ForkVersionDeserialize for SignedBuilderBid<T> {
fn deserialize_by_fork<'de, D: Deserializer<'de>>(
value: serde_json::value::Value,
fork_name: ForkName,
Expand All @@ -120,7 +109,7 @@ impl<T: EthSpec, Payload: AbstractExecPayload<T>> ForkVersionDeserialize
}
}

impl<E: EthSpec, Payload: AbstractExecPayload<E>> SignedBuilderBid<E, Payload> {
impl<E: EthSpec> SignedBuilderBid<E> {
pub fn verify_signature(&self, spec: &ChainSpec) -> bool {
self.message
.pubkey()
Expand Down

0 comments on commit ee2f1a1

Please sign in to comment.