Gloas local block building MVP (#8754)

The flow for local block building is
1. Create execution payload and bid
2. Construct beacon block
3. Sign beacon block and publish
4. Sign execution payload and publish

This PR adds the beacon block v4 flow , GET payload envelope and POST payload envelope (local block building only). The spec for these endpoints can be found here:  https://github.com/ethereum/beacon-APIs/pull/552  and is subject to change.

We needed a way to store the unsigned execution payload envelope associated to the execution payload bid that was included in the block. I introduced a new cache that stores these unsigned execution payload envelopes. the GET payload envelope queries this cache directly so that a proposer, after publishing a block, can fetch the payload envelope + sign and publish it.

I kept payload signing and publishing within the validators block service to keep things simple for now. The idea was to build out a block production MVP for devnet 0, try not to affect any non gloas code paths and build things out in such a way that it will be easy to deprecate pre-gloas code paths later on (for example block production v2 and v3).

We will eventually need to track which beacon node was queried for the block so that we can later query it for the payload. But thats not needed for the devnet.


  


Co-Authored-By: Eitan Seri- Levi <eserilev@gmail.com>

Co-Authored-By: Michael Sproul <michael@sigmaprime.io>

Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com>

Co-Authored-By: Eitan Seri-Levi <eserilev@ucsc.edu>
This commit is contained in:
Eitan Seri-Levi
2026-02-16 18:09:35 -08:00
committed by GitHub
parent 945f6637c5
commit eec0700f94
31 changed files with 2656 additions and 346 deletions

View File

@@ -0,0 +1,110 @@
use crate::task_spawner::{Priority, TaskSpawner};
use crate::utils::{
ChainFilter, EthV1Filter, NotWhileSyncingFilter, ResponseFilter, TaskSpawnerFilter,
};
use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2::beacon_response::{EmptyMetadata, ForkVersionedResponse};
use eth2::types::Accept;
use ssz::Encode;
use std::sync::Arc;
use tracing::debug;
use types::Slot;
use warp::http::Response;
use warp::{Filter, Rejection};
// GET validator/execution_payload_envelope/{slot}/{builder_index}
pub fn get_validator_execution_payload_envelope<T: BeaconChainTypes>(
eth_v1: EthV1Filter,
chain_filter: ChainFilter<T>,
not_while_syncing_filter: NotWhileSyncingFilter,
task_spawner_filter: TaskSpawnerFilter<T>,
) -> ResponseFilter {
eth_v1
.and(warp::path("validator"))
.and(warp::path("execution_payload_envelope"))
.and(warp::path::param::<Slot>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid slot".to_string(),
))
}))
.and(warp::path::param::<u64>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid builder_index".to_string(),
))
}))
.and(warp::path::end())
.and(warp::header::optional::<Accept>("accept"))
.and(not_while_syncing_filter)
.and(task_spawner_filter)
.and(chain_filter)
.then(
|slot: Slot,
// TODO(gloas) we're only doing local building
// we'll need to implement builder index logic
// eventually.
_builder_index: u64,
accept_header: Option<Accept>,
not_synced_filter: Result<(), Rejection>,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>| {
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
debug!(?slot, "Execution payload envelope request from HTTP API");
not_synced_filter?;
// Get the envelope from the pending cache (local building only)
let envelope = chain
.pending_payload_envelopes
.read()
.get(slot)
.cloned()
.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!(
"Execution payload envelope not available for slot {slot}"
))
})?;
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(slot);
match accept_header {
Some(Accept::Ssz) => Response::builder()
.status(200)
.header("Content-Type", "application/octet-stream")
.header("Eth-Consensus-Version", fork_name.to_string())
.body(envelope.as_ssz_bytes().into())
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to build SSZ response: {e}"
))
}),
_ => {
let json_response = ForkVersionedResponse {
version: fork_name,
metadata: EmptyMetadata {},
data: envelope,
};
Response::builder()
.status(200)
.header("Content-Type", "application/json")
.header("Eth-Consensus-Version", fork_name.to_string())
.body(
serde_json::to_string(&json_response)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to serialize response: {e}"
))
})?
.into(),
)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to build JSON response: {e}"
))
})
}
}
})
},
)
.boxed()
}

View File

@@ -1,4 +1,6 @@
use crate::produce_block::{produce_blinded_block_v2, produce_block_v2, produce_block_v3};
use crate::produce_block::{
produce_blinded_block_v2, produce_block_v2, produce_block_v3, produce_block_v4,
};
use crate::task_spawner::{Priority, TaskSpawner};
use crate::utils::{
AnyVersionFilter, ChainFilter, EthV1Filter, NetworkTxFilter, NotWhileSyncingFilter,
@@ -31,6 +33,8 @@ use types::{
use warp::{Filter, Rejection, Reply};
use warp_utils::reject::convert_rejection;
pub mod execution_payload_envelope;
/// Uses the `chain.validator_pubkey_cache` to resolve a pubkey to a validator
/// index and then ensures that the validator exists in the given `state`.
pub fn pubkey_to_validator_index<T: BeaconChainTypes>(
@@ -316,7 +320,11 @@ pub fn get_validator_blocks<T: BeaconChainTypes>(
not_synced_filter?;
if endpoint_version == V3 {
// Use V4 block production for Gloas fork
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(slot);
if fork_name.gloas_enabled() {
produce_block_v4(accept_header, chain, slot, query).await
} else if endpoint_version == V3 {
produce_block_v3(accept_header, chain, slot, query).await
} else {
produce_block_v2(accept_header, chain, slot, query).await
@@ -662,15 +670,26 @@ pub fn post_validator_prepare_beacon_proposer<T: BeaconChainTypes>(
)
.await;
chain
.prepare_beacon_proposer(current_slot)
.await
.map_err(|e| {
warp_utils::reject::custom_bad_request(format!(
"error updating proposer preparations: {:?}",
e
))
})?;
// TODO(gloas): verify this is correct. We skip proposer preparation for
// GLOAS because the execution payload is no longer embedded in the beacon
// block (it's in the payload envelope), so the head block's
// execution_payload() is unavailable.
let next_slot = current_slot + 1;
if !chain
.spec
.fork_name_at_slot::<T::EthSpec>(next_slot)
.gloas_enabled()
{
chain
.prepare_beacon_proposer(current_slot)
.await
.map_err(|e| {
warp_utils::reject::custom_bad_request(format!(
"error updating proposer preparations: {:?}",
e
))
})?;
}
if chain.spec.is_peer_das_scheduled() {
let (finalized_beacon_state, _, _) =