Skip to content

Commit 053d450

Browse files
committed
Complete Fulu builder API changes.
1 parent 661ee56 commit 053d450

File tree

3 files changed

+123
-59
lines changed

3 files changed

+123
-59
lines changed

beacon_node/builder_client/src/lib.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,6 @@ impl BuilderHttpClient {
292292
Ok(())
293293
}
294294

295-
pub async fn post_builder_blinded_blocks_ssz<E: EthSpec>(
296-
&self,
297-
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-
310295
/// `POST /eth/v1/builder/blinded_blocks` with SSZ serialized request body
311296
pub async fn post_builder_blinded_blocks_v1_ssz<E: EthSpec>(
312297
&self,
@@ -405,19 +390,6 @@ impl BuilderHttpClient {
405390
}
406391
}
407392

408-
pub async fn post_builder_blinded_blocks<E: EthSpec>(
409-
&self,
410-
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-
421393
/// `POST /eth/v1/builder/blinded_blocks`
422394
pub async fn post_builder_blinded_blocks_v1<E: EthSpec>(
423395
&self,

beacon_node/execution_layer/src/lib.rs

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ pub enum FailedCondition {
411411
EpochsSinceFinalization,
412412
}
413413

414+
pub enum SubmitBlindedBlockResponse<E: EthSpec> {
415+
V1(Box<FullPayloadContents<E>>),
416+
V2,
417+
}
418+
414419
type PayloadContentsRefTuple<'a, E> = (ExecutionPayloadRef<'a, E>, Option<&'a BlobsBundle<E>>);
415420

416421
struct Inner<E: EthSpec> {
@@ -1893,35 +1898,51 @@ impl<E: EthSpec> ExecutionLayer<E> {
18931898
&self,
18941899
block_root: Hash256,
18951900
block: &SignedBlindedBeaconBlock<E>,
1896-
) -> Result<Option<FullPayloadContents<E>>, Error> {
1901+
spec: &ChainSpec,
1902+
) -> Result<SubmitBlindedBlockResponse<E>, Error> {
18971903
debug!(?block_root, "Sending block to builder");
1904+
if spec.is_fulu_scheduled() {
1905+
self.post_builder_blinded_blocks_v2(block_root, block)
1906+
.await
1907+
.map(|()| SubmitBlindedBlockResponse::V2)
1908+
} else {
1909+
self.post_builder_blinded_blocks_v1(block_root, block)
1910+
.await
1911+
.map(|full_payload| SubmitBlindedBlockResponse::V1(Box::new(full_payload)))
1912+
}
1913+
}
18981914

1915+
async fn post_builder_blinded_blocks_v1(
1916+
&self,
1917+
block_root: Hash256,
1918+
block: &SignedBlindedBeaconBlock<E>,
1919+
) -> Result<FullPayloadContents<E>, Error> {
18991920
if let Some(builder) = self.builder() {
19001921
let (payload_result, duration) =
19011922
timed_future(metrics::POST_BLINDED_PAYLOAD_BUILDER, async {
19021923
let ssz_enabled = builder.is_ssz_available();
19031924
debug!(
19041925
?block_root,
19051926
ssz = ssz_enabled,
1906-
"Calling submit_blinded_block on builder"
1927+
"Calling submit_blinded_block v1 on builder"
19071928
);
19081929
if ssz_enabled {
19091930
builder
1910-
.post_builder_blinded_blocks_ssz(block)
1931+
.post_builder_blinded_blocks_v1_ssz(block)
19111932
.await
19121933
.map_err(Error::Builder)
19131934
} else {
19141935
builder
1915-
.post_builder_blinded_blocks(block)
1936+
.post_builder_blinded_blocks_v1(block)
19161937
.await
19171938
.map_err(Error::Builder)
1918-
.map(|d| d.map(|resp| resp.data))
1939+
.map(|d| d.data)
19191940
}
19201941
})
19211942
.await;
19221943

19231944
match &payload_result {
1924-
Ok(Some(unblinded_response)) => {
1945+
Ok(unblinded_response) => {
19251946
metrics::inc_counter_vec(
19261947
&metrics::EXECUTION_LAYER_BUILDER_REVEAL_PAYLOAD_OUTCOME,
19271948
&[metrics::SUCCESS],
@@ -1936,13 +1957,6 @@ impl<E: EthSpec> ExecutionLayer<E> {
19361957
"Builder successfully revealed payload"
19371958
)
19381959
}
1939-
Ok(None) => {
1940-
info!(
1941-
relay_response_ms = duration.as_millis(),
1942-
?block_root,
1943-
"Builder returned a successful response"
1944-
);
1945-
}
19461960
Err(e) => {
19471961
metrics::inc_counter_vec(
19481962
&metrics::EXECUTION_LAYER_BUILDER_REVEAL_PAYLOAD_OUTCOME,
@@ -1968,6 +1982,66 @@ impl<E: EthSpec> ExecutionLayer<E> {
19681982
Err(Error::NoPayloadBuilder)
19691983
}
19701984
}
1985+
1986+
async fn post_builder_blinded_blocks_v2(
1987+
&self,
1988+
block_root: Hash256,
1989+
block: &SignedBlindedBeaconBlock<E>,
1990+
) -> Result<(), Error> {
1991+
if let Some(builder) = self.builder() {
1992+
let (result, duration) = timed_future(metrics::POST_BLINDED_PAYLOAD_BUILDER, async {
1993+
let ssz_enabled = builder.is_ssz_available();
1994+
debug!(
1995+
?block_root,
1996+
ssz = ssz_enabled,
1997+
"Calling submit_blinded_block v2 on builder"
1998+
);
1999+
if ssz_enabled {
2000+
builder
2001+
.post_builder_blinded_blocks_v2_ssz(block)
2002+
.await
2003+
.map_err(Error::Builder)
2004+
} else {
2005+
builder
2006+
.post_builder_blinded_blocks_v2(block)
2007+
.await
2008+
.map_err(Error::Builder)
2009+
}
2010+
})
2011+
.await;
2012+
2013+
match result {
2014+
Ok(()) => {
2015+
metrics::inc_counter_vec(
2016+
&metrics::EXECUTION_LAYER_BUILDER_REVEAL_PAYLOAD_OUTCOME,
2017+
&[metrics::SUCCESS],
2018+
);
2019+
info!(
2020+
relay_response_ms = duration.as_millis(),
2021+
?block_root,
2022+
"Successfully submitted blinded block to the builder"
2023+
)
2024+
}
2025+
Err(e) => {
2026+
metrics::inc_counter_vec(
2027+
&metrics::EXECUTION_LAYER_BUILDER_REVEAL_PAYLOAD_OUTCOME,
2028+
&[metrics::FAILURE],
2029+
);
2030+
error!(
2031+
info = "this may result in a missed block proposal",
2032+
error = ?e,
2033+
relay_response_ms = duration.as_millis(),
2034+
?block_root,
2035+
"Failed to submit blinded block to the builder"
2036+
)
2037+
}
2038+
}
2039+
2040+
Ok(())
2041+
} else {
2042+
Err(Error::NoPayloadBuilder)
2043+
}
2044+
}
19712045
}
19722046

19732047
#[derive(AsRefStr)]

beacon_node/http_api/src/publish_blocks.rs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use eth2::types::{
1313
BlobsBundle, BroadcastValidation, ErrorMessage, ExecutionPayloadAndBlobs, FullPayloadContents,
1414
PublishBlockRequest, SignedBlockContents,
1515
};
16-
use execution_layer::ProvenancedPayload;
16+
use execution_layer::{ProvenancedPayload, SubmitBlindedBlockResponse};
1717
use futures::TryFutureExt;
1818
use lighthouse_network::{NetworkGlobals, PubsubMessage};
1919
use network::NetworkMessage;
@@ -636,27 +636,37 @@ pub async fn publish_blinded_block<T: BeaconChainTypes>(
636636
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
637637
) -> Result<Response, Rejection> {
638638
let block_root = blinded_block.canonical_root();
639-
let full_block = reconstruct_block(chain.clone(), block_root, blinded_block).await?;
640-
publish_block::<T, _>(
641-
Some(block_root),
642-
full_block,
643-
chain,
644-
network_tx,
645-
validation_level,
646-
duplicate_status_code,
647-
network_globals,
648-
)
649-
.await
639+
let full_block_opt = reconstruct_block(chain.clone(), block_root, blinded_block).await?;
640+
641+
if let Some(full_block) = full_block_opt {
642+
publish_block::<T, _>(
643+
Some(block_root),
644+
full_block,
645+
chain,
646+
network_tx,
647+
validation_level,
648+
duplicate_status_code,
649+
network_globals,
650+
)
651+
.await
652+
} else {
653+
// From the fulu fork, builders are responsible for publishing and
654+
// will no longer return the full payload and blobs.
655+
Ok(warp::reply().into_response())
656+
}
650657
}
651658

652659
/// Deconstruct the given blinded block, and construct a full block. This attempts to use the
653660
/// execution layer's payload cache, and if that misses, attempts a blind block proposal to retrieve
654661
/// the full payload.
662+
///
663+
/// From the Fulu fork, external builders no longer return the full payload and blobs, and this
664+
/// function will always return `Ok(None)` on successful submission of blinded block.
655665
pub async fn reconstruct_block<T: BeaconChainTypes>(
656666
chain: Arc<BeaconChain<T>>,
657667
block_root: Hash256,
658668
block: Arc<SignedBlindedBeaconBlock<T::EthSpec>>,
659-
) -> Result<ProvenancedBlock<T, Arc<SignedBeaconBlock<T::EthSpec>>>, Rejection> {
669+
) -> Result<Option<ProvenancedBlock<T, Arc<SignedBeaconBlock<T::EthSpec>>>>, Rejection> {
660670
let full_payload_opt = if let Ok(payload_header) = block.message().body().execution_payload() {
661671
let el = chain.execution_layer.as_ref().ok_or_else(|| {
662672
warp_utils::reject::custom_server_error("Missing execution layer".to_string())
@@ -696,17 +706,24 @@ pub async fn reconstruct_block<T: BeaconChainTypes>(
696706
"builder",
697707
);
698708

699-
let full_payload = el
700-
.propose_blinded_beacon_block(block_root, &block)
709+
match el
710+
.propose_blinded_beacon_block(block_root, &block, &chain.spec)
701711
.await
702712
.map_err(|e| {
703713
warp_utils::reject::custom_server_error(format!(
704714
"Blind block proposal failed: {:?}",
705715
e
706716
))
707-
})?;
708-
info!(block_hash = ?full_payload.block_hash(), "Successfully published a block to the builder network");
709-
ProvenancedPayload::Builder(full_payload)
717+
})? {
718+
SubmitBlindedBlockResponse::V1(full_payload) => {
719+
info!(block_root = ?block_root, "Successfully published a block to the builder network");
720+
ProvenancedPayload::Builder(*full_payload)
721+
}
722+
SubmitBlindedBlockResponse::V2 => {
723+
info!(block_root = ?block_root, "Successfully published a block to the builder network");
724+
return Ok(None);
725+
}
726+
}
710727
};
711728

712729
Some(full_payload_contents)
@@ -734,6 +751,7 @@ pub async fn reconstruct_block<T: BeaconChainTypes>(
734751
.map(|(block, blobs)| ProvenancedBlock::builder(block, blobs))
735752
}
736753
}
754+
.map(Some)
737755
.map_err(|e| {
738756
warp_utils::reject::custom_server_error(format!("Unable to add payload to block: {e:?}"))
739757
})

0 commit comments

Comments
 (0)