Skip to content

Commit 661ee56

Browse files
committed
Initial commit
1 parent 4a3e248 commit 661ee56

File tree

2 files changed

+138
-5
lines changed
  • beacon_node

2 files changed

+138
-5
lines changed

beacon_node/builder_client/src/lib.rs

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,25 @@ impl BuilderHttpClient {
292292
Ok(())
293293
}
294294

295-
/// `POST /eth/v1/builder/blinded_blocks` with SSZ serialized request body
296295
pub async fn post_builder_blinded_blocks_ssz<E: EthSpec>(
297296
&self,
298297
blinded_block: &SignedBlindedBeaconBlock<E>,
298+
) -> Result<Option<FullPayloadContents<E>>, Error> {
299+
if blinded_block.fork_name_unchecked().fulu_enabled() {
300+
self.post_builder_blinded_blocks_v2_ssz(blinded_block)
301+
.await
302+
.map(|_| None)
303+
} else {
304+
self.post_builder_blinded_blocks_v1_ssz(blinded_block)
305+
.await
306+
.map(Some)
307+
}
308+
}
309+
310+
/// `POST /eth/v1/builder/blinded_blocks` with SSZ serialized request body
311+
pub async fn post_builder_blinded_blocks_v1_ssz<E: EthSpec>(
312+
&self,
313+
blinded_block: &SignedBlindedBeaconBlock<E>,
299314
) -> Result<FullPayloadContents<E>, Error> {
300315
let mut path = self.server.full.clone();
301316

@@ -340,10 +355,73 @@ impl BuilderHttpClient {
340355
.map_err(Error::InvalidSsz)
341356
}
342357

343-
/// `POST /eth/v1/builder/blinded_blocks`
358+
/// `POST /eth/v2/builder/blinded_blocks` with SSZ serialized request body
359+
pub async fn post_builder_blinded_blocks_v2_ssz<E: EthSpec>(
360+
&self,
361+
blinded_block: &SignedBlindedBeaconBlock<E>,
362+
) -> Result<(), Error> {
363+
let mut path = self.server.full.clone();
364+
365+
let body = blinded_block.as_ssz_bytes();
366+
367+
path.path_segments_mut()
368+
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
369+
.push("eth")
370+
.push("v2")
371+
.push("builder")
372+
.push("blinded_blocks");
373+
374+
let mut headers = HeaderMap::new();
375+
headers.insert(
376+
CONSENSUS_VERSION_HEADER,
377+
HeaderValue::from_str(&blinded_block.fork_name_unchecked().to_string())
378+
.map_err(|e| Error::InvalidHeaders(format!("{}", e)))?,
379+
);
380+
headers.insert(
381+
CONTENT_TYPE_HEADER,
382+
HeaderValue::from_str(SSZ_CONTENT_TYPE_HEADER)
383+
.map_err(|e| Error::InvalidHeaders(format!("{}", e)))?,
384+
);
385+
headers.insert(
386+
ACCEPT,
387+
HeaderValue::from_str(PREFERENCE_ACCEPT_VALUE)
388+
.map_err(|e| Error::InvalidHeaders(format!("{}", e)))?,
389+
);
390+
391+
let result = self
392+
.post_ssz_with_raw_response(
393+
path,
394+
body,
395+
headers,
396+
Some(self.timeouts.post_blinded_blocks),
397+
)
398+
.await?;
399+
400+
if result.status() == StatusCode::ACCEPTED {
401+
Ok(())
402+
} else {
403+
// ACCEPTED is the only valid status code response
404+
Err(Error::StatusCode(result.status()))
405+
}
406+
}
407+
344408
pub async fn post_builder_blinded_blocks<E: EthSpec>(
345409
&self,
346410
blinded_block: &SignedBlindedBeaconBlock<E>,
411+
) -> Result<Option<ForkVersionedResponse<FullPayloadContents<E>>>, Error> {
412+
if blinded_block.fork_name_unchecked().fulu_enabled() {
413+
self.post_builder_blinded_blocks_v2(blinded_block)
414+
.await
415+
.map(|_| None)
416+
} else {
417+
self.post_builder_blinded_blocks_v1(blinded_block).await.map(Some)
418+
}
419+
}
420+
421+
/// `POST /eth/v1/builder/blinded_blocks`
422+
pub async fn post_builder_blinded_blocks_v1<E: EthSpec>(
423+
&self,
424+
blinded_block: &SignedBlindedBeaconBlock<E>,
347425
) -> Result<ForkVersionedResponse<FullPayloadContents<E>>, Error> {
348426
let mut path = self.server.full.clone();
349427

@@ -383,6 +461,54 @@ impl BuilderHttpClient {
383461
.await?)
384462
}
385463

464+
/// `POST /eth/v2/builder/blinded_blocks`
465+
pub async fn post_builder_blinded_blocks_v2<E: EthSpec>(
466+
&self,
467+
blinded_block: &SignedBlindedBeaconBlock<E>,
468+
) -> Result<(), Error> {
469+
let mut path = self.server.full.clone();
470+
471+
path.path_segments_mut()
472+
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
473+
.push("eth")
474+
.push("v2")
475+
.push("builder")
476+
.push("blinded_blocks");
477+
478+
let mut headers = HeaderMap::new();
479+
headers.insert(
480+
CONSENSUS_VERSION_HEADER,
481+
HeaderValue::from_str(&blinded_block.fork_name_unchecked().to_string())
482+
.map_err(|e| Error::InvalidHeaders(format!("{}", e)))?,
483+
);
484+
headers.insert(
485+
CONTENT_TYPE_HEADER,
486+
HeaderValue::from_str(JSON_CONTENT_TYPE_HEADER)
487+
.map_err(|e| Error::InvalidHeaders(format!("{}", e)))?,
488+
);
489+
headers.insert(
490+
ACCEPT,
491+
HeaderValue::from_str(JSON_ACCEPT_VALUE)
492+
.map_err(|e| Error::InvalidHeaders(format!("{}", e)))?,
493+
);
494+
495+
let result = self
496+
.post_with_raw_response(
497+
path,
498+
&blinded_block,
499+
headers,
500+
Some(self.timeouts.post_blinded_blocks),
501+
)
502+
.await?;
503+
504+
if result.status() == StatusCode::ACCEPTED {
505+
Ok(())
506+
} else {
507+
// ACCEPTED is the only valid status code response
508+
Err(Error::StatusCode(result.status()))
509+
}
510+
}
511+
386512
/// `GET /eth/v1/builder/header`
387513
pub async fn get_builder_header<E: EthSpec>(
388514
&self,

beacon_node/execution_layer/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ impl<E: EthSpec> ExecutionLayer<E> {
18931893
&self,
18941894
block_root: Hash256,
18951895
block: &SignedBlindedBeaconBlock<E>,
1896-
) -> Result<FullPayloadContents<E>, Error> {
1896+
) -> Result<Option<FullPayloadContents<E>>, Error> {
18971897
debug!(?block_root, "Sending block to builder");
18981898

18991899
if let Some(builder) = self.builder() {
@@ -1915,13 +1915,13 @@ impl<E: EthSpec> ExecutionLayer<E> {
19151915
.post_builder_blinded_blocks(block)
19161916
.await
19171917
.map_err(Error::Builder)
1918-
.map(|d| d.data)
1918+
.map(|d| d.map(|resp| resp.data))
19191919
}
19201920
})
19211921
.await;
19221922

19231923
match &payload_result {
1924-
Ok(unblinded_response) => {
1924+
Ok(Some(unblinded_response)) => {
19251925
metrics::inc_counter_vec(
19261926
&metrics::EXECUTION_LAYER_BUILDER_REVEAL_PAYLOAD_OUTCOME,
19271927
&[metrics::SUCCESS],
@@ -1936,6 +1936,13 @@ impl<E: EthSpec> ExecutionLayer<E> {
19361936
"Builder successfully revealed payload"
19371937
)
19381938
}
1939+
Ok(None) => {
1940+
info!(
1941+
relay_response_ms = duration.as_millis(),
1942+
?block_root,
1943+
"Builder returned a successful response"
1944+
);
1945+
}
19391946
Err(e) => {
19401947
metrics::inc_counter_vec(
19411948
&metrics::EXECUTION_LAYER_BUILDER_REVEAL_PAYLOAD_OUTCOME,

0 commit comments

Comments
 (0)