Implement proposer lookahead endpoint (#8815)

closes #8809


  Implement GET /eth/v1/beacon/states/{state_id}/proposer_lookahead ([beacon-APIs#565](https://github.com/ethereum/beacon-APIs/pull/565)). Returns the proposer lookahead from Fulu+ states; 400 for pre-Fulu. Includes integration test.


Co-Authored-By: romeoscript <romeobourne211@gmail.com>

Co-Authored-By: Tan Chee Keong <tanck@sigmaprime.io>
This commit is contained in:
Romeo
2026-03-10 14:36:58 +01:00
committed by GitHub
parent 081229b748
commit 906400ed34
4 changed files with 196 additions and 3 deletions

View File

@@ -3,17 +3,20 @@ use crate::task_spawner::{Priority, TaskSpawner};
use crate::utils::ResponseFilter;
use crate::validator::pubkey_to_validator_index;
use crate::version::{
ResponseIncludesVersion, add_consensus_version_header,
ResponseIncludesVersion, add_consensus_version_header, add_ssz_content_type_header,
execution_optimistic_finalized_beacon_response,
};
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes, WhenSlotSkipped};
use eth2::types::{
ValidatorBalancesRequestBody, ValidatorId, ValidatorIdentitiesRequestBody,
self as api_types, ValidatorBalancesRequestBody, ValidatorId, ValidatorIdentitiesRequestBody,
ValidatorsRequestBody,
};
use ssz::Encode;
use std::sync::Arc;
use types::{AttestationShufflingId, BeaconStateError, CommitteeCache, EthSpec, RelativeEpoch};
use warp::filters::BoxedFilter;
use warp::http::Response;
use warp::hyper::Body;
use warp::{Filter, Reply};
use warp_utils::query::multi_key_query;
@@ -160,6 +163,67 @@ pub fn get_beacon_state_pending_deposits<T: BeaconChainTypes>(
.boxed()
}
// GET beacon/states/{state_id}/proposer_lookahead
pub fn get_beacon_state_proposer_lookahead<T: BeaconChainTypes>(
beacon_states_path: BeaconStatesPath<T>,
) -> ResponseFilter {
beacon_states_path
.clone()
.and(warp::path("proposer_lookahead"))
.and(warp::path::end())
.and(warp::header::optional::<api_types::Accept>("accept"))
.then(
|state_id: StateId,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>,
accept_header: Option<api_types::Accept>| {
task_spawner.blocking_response_task(Priority::P1, move || {
let (data, execution_optimistic, finalized, fork_name) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic, finalized| {
let Ok(lookahead) = state.proposer_lookahead() else {
return Err(warp_utils::reject::custom_bad_request(
"Proposer lookahead is not available for pre-Fulu states"
.to_string(),
));
};
Ok((
lookahead.to_vec(),
execution_optimistic,
finalized,
state.fork_name_unchecked(),
))
},
)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
.status(200)
.body(data.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
e
))
}),
_ => execution_optimistic_finalized_beacon_response(
ResponseIncludesVersion::Yes(fork_name),
execution_optimistic,
finalized,
data,
)
.map(|res| warp::reply::json(&res).into_response()),
}
.map(|resp| add_consensus_version_header(resp, fork_name))
})
},
)
.boxed()
}
// GET beacon/states/{state_id}/randao?epoch
pub fn get_beacon_state_randao<T: BeaconChainTypes>(
beacon_states_path: BeaconStatesPath<T>,

View File

@@ -650,6 +650,10 @@ pub fn serve<T: BeaconChainTypes>(
let get_beacon_state_pending_consolidations =
states::get_beacon_state_pending_consolidations(beacon_states_path.clone());
// GET beacon/states/{state_id}/proposer_lookahead
let get_beacon_state_proposer_lookahead =
states::get_beacon_state_proposer_lookahead(beacon_states_path.clone());
// GET beacon/headers
//
// Note: this endpoint only returns information about blocks in the canonical chain. Given that
@@ -3284,6 +3288,7 @@ pub fn serve<T: BeaconChainTypes>(
.uor(get_beacon_state_pending_deposits)
.uor(get_beacon_state_pending_partial_withdrawals)
.uor(get_beacon_state_pending_consolidations)
.uor(get_beacon_state_proposer_lookahead)
.uor(get_beacon_headers)
.uor(get_beacon_headers_block_id)
.uor(get_beacon_block)