From cd637ee09188a8b47302a4a9505af499c3c7a800 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 17 Aug 2023 18:55:07 -0600 Subject: [PATCH] conform to the `submitBlock` endpoint --- .../src/blinded_block_relayer/api/client.rs | 15 ++++---------- .../src/blinded_block_relayer/api/server.rs | 6 +++--- mev-rs/src/blinded_block_relayer/mod.rs | 7 ++----- mev-rs/src/types/mod.rs | 20 +++---------------- 4 files changed, 12 insertions(+), 36 deletions(-) diff --git a/mev-rs/src/blinded_block_relayer/api/client.rs b/mev-rs/src/blinded_block_relayer/api/client.rs index e868c1e9..77c8ec43 100644 --- a/mev-rs/src/blinded_block_relayer/api/client.rs +++ b/mev-rs/src/blinded_block_relayer/api/client.rs @@ -1,9 +1,9 @@ use crate::{ blinded_block_relayer::BlindedBlockRelayer, - types::{ProposerSchedule, SignedBidReceipt, SignedBidSubmission}, + types::{ProposerSchedule, SignedBidSubmission}, Error, }; -use beacon_api_client::{mainnet::Client as BeaconApiClient, ApiResult, Error as ApiError}; +use beacon_api_client::{api_error_or_ok, mainnet::Client as BeaconApiClient}; /// A `Client` for a service implementing the Relay APIs. #[derive(Clone)] @@ -24,15 +24,8 @@ impl BlindedBlockRelayer for Client { } // TODO support content types - async fn submit_bid( - &self, - signed_submission: &SignedBidSubmission, - ) -> Result { + async fn submit_bid(&self, signed_submission: &SignedBidSubmission) -> Result<(), Error> { let response = self.api.http_post("/relay/v1/builder/blocks", signed_submission).await?; - let receipt: ApiResult = response.json().await.map_err(ApiError::from)?; - match receipt { - ApiResult::Ok(receipt) => Ok(receipt), - ApiResult::Err(err) => Err(ApiError::from(err).into()), - } + api_error_or_ok(response).await.map_err(From::from) } } diff --git a/mev-rs/src/blinded_block_relayer/api/server.rs b/mev-rs/src/blinded_block_relayer/api/server.rs index a0153cab..79836cef 100644 --- a/mev-rs/src/blinded_block_relayer/api/server.rs +++ b/mev-rs/src/blinded_block_relayer/api/server.rs @@ -1,7 +1,7 @@ use crate::{ blinded_block_relayer::BlindedBlockRelayer, error::Error, - types::{ProposerSchedule, SignedBidReceipt, SignedBidSubmission}, + types::{ProposerSchedule, SignedBidSubmission}, }; use axum::{ extract::{Json, State}, @@ -25,9 +25,9 @@ async fn handle_get_proposal_schedule( async fn handle_submit_bid( State(relayer): State, Json(signed_bid_submission): Json, -) -> Result, Error> { +) -> Result<(), Error> { tracing::info!("handling bid submission"); - Ok(Json(relayer.submit_bid(&signed_bid_submission).await?)) + Ok(relayer.submit_bid(&signed_bid_submission).await?) } pub struct Server { diff --git a/mev-rs/src/blinded_block_relayer/mod.rs b/mev-rs/src/blinded_block_relayer/mod.rs index e85271b1..11b375ef 100644 --- a/mev-rs/src/blinded_block_relayer/mod.rs +++ b/mev-rs/src/blinded_block_relayer/mod.rs @@ -6,7 +6,7 @@ pub use {api::client::Client, api::server::Server}; use crate::{ error::Error, - types::{ProposerSchedule, SignedBidReceipt, SignedBidSubmission}, + types::{ProposerSchedule, SignedBidSubmission}, }; use async_trait::async_trait; @@ -15,8 +15,5 @@ pub trait BlindedBlockRelayer { async fn get_proposal_schedule(&self) -> Result, Error>; // TODO: support cancellations? - async fn submit_bid( - &self, - signed_submission: &SignedBidSubmission, - ) -> Result; + async fn submit_bid(&self, signed_submission: &SignedBidSubmission) -> Result<(), Error>; } diff --git a/mev-rs/src/types/mod.rs b/mev-rs/src/types/mod.rs index 6aabf78a..b7d007d9 100644 --- a/mev-rs/src/types/mod.rs +++ b/mev-rs/src/types/mod.rs @@ -357,7 +357,7 @@ pub struct ProposerSchedule { pub entry: SignedValidatorRegistration, } -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, SimpleSerialize)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BidTrace { #[serde(with = "crate::serde::as_string")] @@ -366,6 +366,8 @@ pub struct BidTrace { pub block_hash: Hash32, #[serde(rename = "builder_pubkey")] pub builder_public_key: BlsPublicKey, + #[serde(rename = "proposer_pubkey")] + pub proposer_public_key: BlsPublicKey, pub proposer_fee_recipient: ExecutionAddress, #[serde(with = "crate::serde::as_string")] pub gas_limit: u64, @@ -378,21 +380,5 @@ pub struct BidTrace { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct SignedBidSubmission { pub message: BidTrace, - pub execution_payload: ExecutionPayload, - pub signature: BlsSignature, -} - -#[derive(Debug, Default, Clone)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct BidReceipt { - #[serde(with = "crate::serde::as_string")] - pub receive_timestamp: u64, - pub bid_trace: BidTrace, -} - -#[derive(Debug, Default, Clone)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct SignedBidReceipt { - pub message: BidReceipt, pub signature: BlsSignature, }