Skip to content

Commit 2302b75

Browse files
committed
Made unblinded block payloads optional for v2 support
1 parent fb7dddb commit 2302b75

4 files changed

Lines changed: 41 additions & 38 deletions

File tree

crates/common/src/pbs/event.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub enum BuilderEvent {
3030
GetStatusEvent,
3131
GetStatusResponse,
3232
SubmitBlockRequest(Box<SignedBlindedBeaconBlock>, BuilderApiVersion),
33-
SubmitBlockResponse(Box<SubmitBlindedBlockResponse>, BuilderApiVersion),
33+
SubmitBlockResponseV1(Box<SubmitBlindedBlockResponse>),
34+
SubmitBlockResponseV2,
3435
MissedPayload {
3536
/// Hash for the block for which no payload was received
3637
block_hash: B256,

crates/pbs/src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub trait BuilderApi<S: BuilderApiState>: 'static {
3939
req_headers: HeaderMap,
4040
state: PbsState<S>,
4141
api_version: &BuilderApiVersion,
42-
) -> eyre::Result<SubmitBlindedBlockResponse> {
42+
) -> eyre::Result<Option<SubmitBlindedBlockResponse>> {
4343
mev_boost::submit_block(signed_blinded_block, req_headers, state, api_version).await
4444
}
4545

crates/pbs/src/mev_boost/submit_block.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub async fn submit_block<S: BuilderApiState>(
3131
req_headers: HeaderMap,
3232
state: PbsState<S>,
3333
api_version: &BuilderApiVersion,
34-
) -> eyre::Result<SubmitBlindedBlockResponse> {
34+
) -> eyre::Result<Option<SubmitBlindedBlockResponse>> {
3535
// prepare headers
3636
let mut send_headers = HeaderMap::new();
3737
send_headers.insert(HEADER_START_TIME_UNIX_MS, HeaderValue::from(utcnow_ms()));
@@ -64,7 +64,7 @@ async fn submit_block_with_timeout(
6464
headers: HeaderMap,
6565
timeout_ms: u64,
6666
api_version: &BuilderApiVersion,
67-
) -> Result<SubmitBlindedBlockResponse, PbsError> {
67+
) -> Result<Option<SubmitBlindedBlockResponse>, PbsError> {
6868
let url = relay.submit_block_url(api_version.clone())?;
6969
let mut remaining_timeout_ms = timeout_ms;
7070
let mut retry = 0;
@@ -79,7 +79,7 @@ async fn submit_block_with_timeout(
7979
headers.clone(),
8080
remaining_timeout_ms,
8181
retry,
82-
*api_version == BuilderApiVersion::V1, // only validate unblinded block for v1
82+
api_version,
8383
)
8484
.await
8585
{
@@ -113,8 +113,8 @@ async fn send_submit_block(
113113
headers: HeaderMap,
114114
timeout_ms: u64,
115115
retry: u32,
116-
validate_unblinded_block: bool,
117-
) -> Result<SubmitBlindedBlockResponse, PbsError> {
116+
api_version: &BuilderApiVersion,
117+
) -> Result<Option<SubmitBlindedBlockResponse>, PbsError> {
118118
let start_request = Instant::now();
119119
let res = match relay
120120
.client
@@ -158,6 +158,10 @@ async fn send_submit_block(
158158
warn!(relay_id = relay.id.as_ref(), retry, %err, "failed to get payload (this might be ok if other relays have it)");
159159
return Err(err);
160160
};
161+
if api_version != &BuilderApiVersion::V1 {
162+
// v2 response is going to be empty, so just break here
163+
return Ok(None);
164+
}
161165

162166
let block_response = match serde_json::from_slice::<SubmitBlindedBlockResponse>(&response_bytes)
163167
{
@@ -187,16 +191,14 @@ async fn send_submit_block(
187191

188192
// request has different type so cant be deserialized in the wrong version,
189193
// response has a "version" field
190-
if validate_unblinded_block {
191-
match (&signed_blinded_block.message, &block_response) {
192-
(
193-
BlindedBeaconBlock::Electra(signed_blinded_block),
194-
VersionedResponse::Electra(block_response),
195-
) => validate_unblinded_block_electra(signed_blinded_block, block_response),
196-
}?;
197-
}
198-
199-
Ok(block_response)
194+
match (&signed_blinded_block.message, &block_response) {
195+
(
196+
BlindedBeaconBlock::Electra(signed_blinded_block),
197+
VersionedResponse::Electra(block_response),
198+
) => validate_unblinded_block_electra(signed_blinded_block, block_response),
199+
}?;
200+
201+
Ok(Some(block_response))
200202
}
201203

202204
fn validate_unblinded_block_electra(

crates/pbs/src/routes/submit_block.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,29 @@ async fn handle_submit_block_impl<S: BuilderApiState, A: BuilderApi<S>>(
7272
info!(ua, ms_into_slot = now.saturating_sub(slot_start_ms), "new request");
7373

7474
match A::submit_block(signed_blinded_block, req_headers, state.clone(), &api_version).await {
75-
Ok(res) => {
76-
trace!(?res);
77-
state.publish_event(BuilderEvent::SubmitBlockResponse(
78-
Box::new(res.clone()),
79-
api_version.clone(),
80-
));
81-
info!("received unblinded block");
75+
Ok(res) => match res {
76+
Some(block_response) => {
77+
trace!(?block_response);
78+
state.publish_event(BuilderEvent::SubmitBlockResponseV1(Box::new(
79+
block_response.clone(),
80+
)));
81+
info!("received unblinded block (v1)");
8282

83-
match api_version {
84-
BuilderApiVersion::V1 => {
85-
BEACON_NODE_STATUS
86-
.with_label_values(&["200", SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG])
87-
.inc();
88-
Ok((StatusCode::OK, Json(res).into_response()))
89-
}
90-
BuilderApiVersion::V2 => {
91-
BEACON_NODE_STATUS
92-
.with_label_values(&["202", SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG])
93-
.inc();
94-
Ok((StatusCode::ACCEPTED, "".into_response()))
95-
}
83+
BEACON_NODE_STATUS
84+
.with_label_values(&["200", SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG])
85+
.inc();
86+
Ok((StatusCode::OK, Json(block_response).into_response()))
9687
}
97-
}
88+
None => {
89+
state.publish_event(BuilderEvent::SubmitBlockResponseV2);
90+
info!("received unblinded block (v2)");
91+
92+
BEACON_NODE_STATUS
93+
.with_label_values(&["202", SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG])
94+
.inc();
95+
Ok((StatusCode::ACCEPTED, "".into_response()))
96+
}
97+
},
9898

9999
Err(err) => {
100100
error!(%err, %block_hash, "CRITICAL: no payload received from relays. Check previous logs or use the Relay Data API");

0 commit comments

Comments
 (0)