From 8b6c14bb69bce95a4866f0171097cf1f6c0adeac Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 13 Sep 2023 16:16:35 -0700 Subject: [PATCH 1/8] add query param --- mev-build-rs/src/reth_builder/builder.rs | 8 ++++++-- mev-build-rs/src/reth_builder/service.rs | 3 ++- mev-rs/src/blinded_block_relayer/api/client.rs | 18 +++++++++++++++--- mev-rs/src/blinded_block_relayer/api/server.rs | 5 +++-- mev-rs/src/blinded_block_relayer/mod.rs | 6 +++++- mev-rs/src/relay.rs | 8 ++++++-- 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/mev-build-rs/src/reth_builder/builder.rs b/mev-build-rs/src/reth_builder/builder.rs index 4e2a32b8..6e78f60b 100644 --- a/mev-build-rs/src/reth_builder/builder.rs +++ b/mev-build-rs/src/reth_builder/builder.rs @@ -276,7 +276,11 @@ impl Builder { self.state.lock().unwrap().cancels.remove(id); } - pub async fn submit_bid(&self, id: &BuildIdentifier) -> Result<(), Error> { + pub async fn submit_bid( + &self, + id: &BuildIdentifier, + with_cancellations: Option<&String>, + ) -> Result<(), Error> { let build = self.build_for(id).ok_or_else(|| Error::MissingBuild(id.clone()))?; let context = &build.context; @@ -292,7 +296,7 @@ impl Builder { let block_hash = &signed_submission.message.block_hash; let value = &signed_submission.message.value; tracing::info!(id = %id, relay = ?relay, slot, %parent_hash, %block_hash, ?value, %builder_payment, "submitting bid"); - match relay.submit_bid(&signed_submission).await { + match relay.submit_bid(&signed_submission, with_cancellations).await { Ok(_) => tracing::info!(%id, ?relay, "successfully submitted bid"), Err(err) => { tracing::warn!(%err, %id,?relay, "error submitting bid"); diff --git a/mev-build-rs/src/reth_builder/service.rs b/mev-build-rs/src/reth_builder/service.rs index dc08d4bf..3b058b4d 100644 --- a/mev-build-rs/src/reth_builder/service.rs +++ b/mev-build-rs/src/reth_builder/service.rs @@ -159,7 +159,8 @@ impl< loop { match bidder.bid_for(&build).await { Ok(Some(bid)) => { - if let Err(err) = builder.submit_bid(&id).await { + //NOTE for now we + if let Err(err) = builder.submit_bid(&id, None).await { tracing::warn!(id = %id, slot=?build.context.slot, err = %err, "error submitting bid for build"); } match bid { diff --git a/mev-rs/src/blinded_block_relayer/api/client.rs b/mev-rs/src/blinded_block_relayer/api/client.rs index aa0bfc30..10a62148 100644 --- a/mev-rs/src/blinded_block_relayer/api/client.rs +++ b/mev-rs/src/blinded_block_relayer/api/client.rs @@ -3,7 +3,7 @@ use crate::{ types::{ProposerSchedule, SignedBidSubmission}, Error, }; -use beacon_api_client::{api_error_or_ok, mainnet::Client as BeaconApiClient}; +use beacon_api_client::{api_error_or_ok, mainnet::Client as BeaconApiClient, Error as ApiError}; /// A `Client` for a service implementing the Relay APIs. #[derive(Clone)] @@ -23,8 +23,20 @@ impl BlindedBlockRelayer for Client { self.api.get("/relay/v1/builder/validators").await.map_err(From::from) } - async fn submit_bid(&self, signed_submission: &SignedBidSubmission) -> Result<(), Error> { - let response = self.api.http_post("/relay/v1/builder/blocks", signed_submission).await?; + async fn submit_bid( + &self, + signed_submission: &SignedBidSubmission, + with_cancellations: Option<&String>, + ) -> Result<(), Error> { + let path = format!("/relay/v1/builder/blocks"); + let target = self.api.endpoint.join(&path).map_err(ApiError::from)?; + let mut request = self.api.http.post(target).json(signed_submission); + if let Some(cancellation) = with_cancellations { + if cancellation == "1" { + request = request.query(&[("cancellations", with_cancellations)]) + } + }; + let response = request.send().await.map_err(ApiError::from)?; 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 4b7d6840..708c2326 100644 --- a/mev-rs/src/blinded_block_relayer/api/server.rs +++ b/mev-rs/src/blinded_block_relayer/api/server.rs @@ -4,7 +4,7 @@ use crate::{ types::{ProposerSchedule, SignedBidSubmission}, }; use axum::{ - extract::{Json, State}, + extract::{Json, Query, State}, routing::{get, post, IntoMakeService}, Router, }; @@ -24,10 +24,11 @@ async fn handle_get_proposal_schedule( async fn handle_submit_bid( State(relayer): State, + Query(with_cancellations): Query, Json(signed_bid_submission): Json, ) -> Result<(), Error> { tracing::info!("handling bid submission"); - relayer.submit_bid(&signed_bid_submission).await + relayer.submit_bid(&signed_bid_submission, Some(&with_cancellations)).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 00d39390..ccfdd142 100644 --- a/mev-rs/src/blinded_block_relayer/mod.rs +++ b/mev-rs/src/blinded_block_relayer/mod.rs @@ -14,5 +14,9 @@ use async_trait::async_trait; pub trait BlindedBlockRelayer { async fn get_proposal_schedule(&self) -> Result, Error>; - async fn submit_bid(&self, signed_submission: &SignedBidSubmission) -> Result<(), Error>; + async fn submit_bid( + &self, + signed_submission: &SignedBidSubmission, + with_cancellations: Option<&String>, + ) -> Result<(), Error>; } diff --git a/mev-rs/src/relay.rs b/mev-rs/src/relay.rs index 9432a32a..3938dce6 100644 --- a/mev-rs/src/relay.rs +++ b/mev-rs/src/relay.rs @@ -68,8 +68,12 @@ impl BlindedBlockRelayer for Relay { self.relayer.get_proposal_schedule().await } - async fn submit_bid(&self, signed_submission: &SignedBidSubmission) -> Result<(), Error> { - self.relayer.submit_bid(signed_submission).await + async fn submit_bid( + &self, + signed_submission: &SignedBidSubmission, + with_cancellations: Option<&String>, + ) -> Result<(), Error> { + self.relayer.submit_bid(signed_submission, with_cancellations).await } } From 8f9fa6751663bbd9e5bf53bfd6722e1861e4fd7e Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 13 Sep 2023 16:20:14 -0700 Subject: [PATCH 2/8] nit --- mev-build-rs/src/reth_builder/service.rs | 1 - mev-rs/src/blinded_block_relayer/api/client.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mev-build-rs/src/reth_builder/service.rs b/mev-build-rs/src/reth_builder/service.rs index 3b058b4d..a83d3c6f 100644 --- a/mev-build-rs/src/reth_builder/service.rs +++ b/mev-build-rs/src/reth_builder/service.rs @@ -159,7 +159,6 @@ impl< loop { match bidder.bid_for(&build).await { Ok(Some(bid)) => { - //NOTE for now we if let Err(err) = builder.submit_bid(&id, None).await { tracing::warn!(id = %id, slot=?build.context.slot, err = %err, "error submitting bid for build"); } diff --git a/mev-rs/src/blinded_block_relayer/api/client.rs b/mev-rs/src/blinded_block_relayer/api/client.rs index 10a62148..f2029f57 100644 --- a/mev-rs/src/blinded_block_relayer/api/client.rs +++ b/mev-rs/src/blinded_block_relayer/api/client.rs @@ -31,8 +31,8 @@ impl BlindedBlockRelayer for Client { let path = format!("/relay/v1/builder/blocks"); let target = self.api.endpoint.join(&path).map_err(ApiError::from)?; let mut request = self.api.http.post(target).json(signed_submission); - if let Some(cancellation) = with_cancellations { - if cancellation == "1" { + if let Some(cancellations) = with_cancellations { + if cancellations == "1" { request = request.query(&[("cancellations", with_cancellations)]) } }; From 9498f5612143fb0598b0743980fff66eaf371906 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 14 Sep 2023 10:39:45 -0700 Subject: [PATCH 3/8] switch cancellation parameter to bool --- mev-build-rs/src/reth_builder/service.rs | 2 +- mev-rs/src/blinded_block_relayer/api/client.rs | 8 ++------ mev-rs/src/blinded_block_relayer/api/server.rs | 4 ++-- mev-rs/src/blinded_block_relayer/mod.rs | 2 +- mev-rs/src/relay.rs | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/mev-build-rs/src/reth_builder/service.rs b/mev-build-rs/src/reth_builder/service.rs index a83d3c6f..4ef3877b 100644 --- a/mev-build-rs/src/reth_builder/service.rs +++ b/mev-build-rs/src/reth_builder/service.rs @@ -159,7 +159,7 @@ impl< loop { match bidder.bid_for(&build).await { Ok(Some(bid)) => { - if let Err(err) = builder.submit_bid(&id, None).await { + if let Err(err) = builder.submit_bid(&id, false).await { tracing::warn!(id = %id, slot=?build.context.slot, err = %err, "error submitting bid for build"); } match bid { diff --git a/mev-rs/src/blinded_block_relayer/api/client.rs b/mev-rs/src/blinded_block_relayer/api/client.rs index f2029f57..1493c296 100644 --- a/mev-rs/src/blinded_block_relayer/api/client.rs +++ b/mev-rs/src/blinded_block_relayer/api/client.rs @@ -26,16 +26,12 @@ impl BlindedBlockRelayer for Client { async fn submit_bid( &self, signed_submission: &SignedBidSubmission, - with_cancellations: Option<&String>, + with_cancellations: bool, ) -> Result<(), Error> { let path = format!("/relay/v1/builder/blocks"); let target = self.api.endpoint.join(&path).map_err(ApiError::from)?; let mut request = self.api.http.post(target).json(signed_submission); - if let Some(cancellations) = with_cancellations { - if cancellations == "1" { - request = request.query(&[("cancellations", with_cancellations)]) - } - }; + if with_cancellations { request = request.query(&[("cancellations", with_cancellations)]) }; let response = request.send().await.map_err(ApiError::from)?; 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 708c2326..94a97964 100644 --- a/mev-rs/src/blinded_block_relayer/api/server.rs +++ b/mev-rs/src/blinded_block_relayer/api/server.rs @@ -24,11 +24,11 @@ async fn handle_get_proposal_schedule( async fn handle_submit_bid( State(relayer): State, - Query(with_cancellations): Query, + Query(with_cancellations): Query, Json(signed_bid_submission): Json, ) -> Result<(), Error> { tracing::info!("handling bid submission"); - relayer.submit_bid(&signed_bid_submission, Some(&with_cancellations)).await + relayer.submit_bid(&signed_bid_submission, with_cancellations).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 ccfdd142..4081b84c 100644 --- a/mev-rs/src/blinded_block_relayer/mod.rs +++ b/mev-rs/src/blinded_block_relayer/mod.rs @@ -17,6 +17,6 @@ pub trait BlindedBlockRelayer { async fn submit_bid( &self, signed_submission: &SignedBidSubmission, - with_cancellations: Option<&String>, + with_cancellations: bool, ) -> Result<(), Error>; } diff --git a/mev-rs/src/relay.rs b/mev-rs/src/relay.rs index 3938dce6..96ea7e5a 100644 --- a/mev-rs/src/relay.rs +++ b/mev-rs/src/relay.rs @@ -71,7 +71,7 @@ impl BlindedBlockRelayer for Relay { async fn submit_bid( &self, signed_submission: &SignedBidSubmission, - with_cancellations: Option<&String>, + with_cancellations: bool, ) -> Result<(), Error> { self.relayer.submit_bid(signed_submission, with_cancellations).await } From 95865dbc25da992ea163c6a83fe9de9c0c615885 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 14 Sep 2023 10:40:12 -0700 Subject: [PATCH 4/8] change builder param --- mev-build-rs/src/reth_builder/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mev-build-rs/src/reth_builder/builder.rs b/mev-build-rs/src/reth_builder/builder.rs index 6e78f60b..5193ffba 100644 --- a/mev-build-rs/src/reth_builder/builder.rs +++ b/mev-build-rs/src/reth_builder/builder.rs @@ -279,7 +279,7 @@ impl Builder { pub async fn submit_bid( &self, id: &BuildIdentifier, - with_cancellations: Option<&String>, + with_cancellations: bool, ) -> Result<(), Error> { let build = self.build_for(id).ok_or_else(|| Error::MissingBuild(id.clone()))?; From dc0c299eb69e6ebad54479d18f058440f7e543da Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 14 Sep 2023 15:14:55 -0700 Subject: [PATCH 5/8] confirm to spec --- mev-rs/src/blinded_block_relayer/api/client.rs | 2 +- mev-rs/src/blinded_block_relayer/api/server.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mev-rs/src/blinded_block_relayer/api/client.rs b/mev-rs/src/blinded_block_relayer/api/client.rs index 1493c296..7097be51 100644 --- a/mev-rs/src/blinded_block_relayer/api/client.rs +++ b/mev-rs/src/blinded_block_relayer/api/client.rs @@ -31,7 +31,7 @@ impl BlindedBlockRelayer for Client { let path = format!("/relay/v1/builder/blocks"); let target = self.api.endpoint.join(&path).map_err(ApiError::from)?; let mut request = self.api.http.post(target).json(signed_submission); - if with_cancellations { request = request.query(&[("cancellations", with_cancellations)]) }; + if with_cancellations { request = request.query(&[("cancellations", "1")]) }; let response = request.send().await.map_err(ApiError::from)?; 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 94a97964..5b10278c 100644 --- a/mev-rs/src/blinded_block_relayer/api/server.rs +++ b/mev-rs/src/blinded_block_relayer/api/server.rs @@ -24,10 +24,11 @@ async fn handle_get_proposal_schedule( async fn handle_submit_bid( State(relayer): State, - Query(with_cancellations): Query, + Query(with_cancellations): Query, Json(signed_bid_submission): Json, ) -> Result<(), Error> { tracing::info!("handling bid submission"); + let with_cancellations = if with_cancellations == "1" { true } else { false }; relayer.submit_bid(&signed_bid_submission, with_cancellations).await } From d233e7c8572ecaccef719f3eb135e33b41a7ea85 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 14 Sep 2023 15:17:48 -0700 Subject: [PATCH 6/8] fmt --- mev-rs/src/blinded_block_relayer/api/client.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mev-rs/src/blinded_block_relayer/api/client.rs b/mev-rs/src/blinded_block_relayer/api/client.rs index 7097be51..938f59a7 100644 --- a/mev-rs/src/blinded_block_relayer/api/client.rs +++ b/mev-rs/src/blinded_block_relayer/api/client.rs @@ -31,7 +31,9 @@ impl BlindedBlockRelayer for Client { let path = format!("/relay/v1/builder/blocks"); let target = self.api.endpoint.join(&path).map_err(ApiError::from)?; let mut request = self.api.http.post(target).json(signed_submission); - if with_cancellations { request = request.query(&[("cancellations", "1")]) }; + if with_cancellations { + request = request.query(&[("cancellations", "1")]) + }; let response = request.send().await.map_err(ApiError::from)?; api_error_or_ok(response).await.map_err(From::from) } From 9d651b42fc21b7a1501c036ffcb54c7766164a01 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 15 Sep 2023 12:56:35 -0700 Subject: [PATCH 7/8] fix lint --- mev-rs/src/blinded_block_relayer/api/client.rs | 2 +- mev-rs/src/blinded_block_relayer/api/server.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mev-rs/src/blinded_block_relayer/api/client.rs b/mev-rs/src/blinded_block_relayer/api/client.rs index 938f59a7..d1976fae 100644 --- a/mev-rs/src/blinded_block_relayer/api/client.rs +++ b/mev-rs/src/blinded_block_relayer/api/client.rs @@ -28,7 +28,7 @@ impl BlindedBlockRelayer for Client { signed_submission: &SignedBidSubmission, with_cancellations: bool, ) -> Result<(), Error> { - let path = format!("/relay/v1/builder/blocks"); + let path = "/relay/v1/builder/blocks".to_string(); let target = self.api.endpoint.join(&path).map_err(ApiError::from)?; let mut request = self.api.http.post(target).json(signed_submission); if with_cancellations { diff --git a/mev-rs/src/blinded_block_relayer/api/server.rs b/mev-rs/src/blinded_block_relayer/api/server.rs index 5b10278c..0828478b 100644 --- a/mev-rs/src/blinded_block_relayer/api/server.rs +++ b/mev-rs/src/blinded_block_relayer/api/server.rs @@ -28,7 +28,7 @@ async fn handle_submit_bid( Json(signed_bid_submission): Json, ) -> Result<(), Error> { tracing::info!("handling bid submission"); - let with_cancellations = if with_cancellations == "1" { true } else { false }; + let with_cancellations = with_cancellations == "1"; relayer.submit_bid(&signed_bid_submission, with_cancellations).await } From 4eaafcd0e415fa80d47227352d8b1ea17a21c5ee Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 18 Sep 2023 13:46:11 -0500 Subject: [PATCH 8/8] nit --- mev-rs/src/blinded_block_relayer/api/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mev-rs/src/blinded_block_relayer/api/client.rs b/mev-rs/src/blinded_block_relayer/api/client.rs index d1976fae..0bd66572 100644 --- a/mev-rs/src/blinded_block_relayer/api/client.rs +++ b/mev-rs/src/blinded_block_relayer/api/client.rs @@ -28,7 +28,7 @@ impl BlindedBlockRelayer for Client { signed_submission: &SignedBidSubmission, with_cancellations: bool, ) -> Result<(), Error> { - let path = "/relay/v1/builder/blocks".to_string(); + let path = "/relay/v1/builder/blocks"; let target = self.api.endpoint.join(&path).map_err(ApiError::from)?; let mut request = self.api.http.post(target).json(signed_submission); if with_cancellations {