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

@@ -37,7 +37,7 @@ use proto_array::ExecutionStatus;
use reqwest::{RequestBuilder, Response, StatusCode};
use sensitive_url::SensitiveUrl;
use slot_clock::SlotClock;
use ssz::BitList;
use ssz::{BitList, Decode};
use state_processing::per_block_processing::get_expected_withdrawals;
use state_processing::per_slot_processing;
use state_processing::state_advance::partial_state_advance;
@@ -1409,6 +1409,72 @@ impl ApiTester {
self
}
pub async fn test_beacon_states_proposer_lookahead(self) -> Self {
for state_id in self.interesting_state_ids() {
let mut state_opt = state_id
.state(&self.chain)
.ok()
.map(|(state, _execution_optimistic, _finalized)| state);
let result = match self
.client
.get_beacon_states_proposer_lookahead(state_id.0)
.await
{
Ok(response) => response,
Err(e) => panic!("query failed incorrectly: {e:?}"),
};
if result.is_none() && state_opt.is_none() {
continue;
}
let state = state_opt.as_mut().expect("result should be none");
let expected = state.proposer_lookahead().unwrap();
let response = result.unwrap();
assert_eq!(response.data(), &expected.to_vec());
// Check that the version header is returned in the response
let fork_name = state.fork_name(&self.chain.spec).unwrap();
assert_eq!(response.version(), Some(fork_name),);
}
self
}
pub async fn test_beacon_states_proposer_lookahead_ssz(self) -> Self {
for state_id in self.interesting_state_ids() {
let mut state_opt = state_id
.state(&self.chain)
.ok()
.map(|(state, _execution_optimistic, _finalized)| state);
let result = match self
.client
.get_beacon_states_proposer_lookahead_ssz(state_id.0)
.await
{
Ok(response) => response,
Err(e) => panic!("query failed incorrectly: {e:?}"),
};
if result.is_none() && state_opt.is_none() {
continue;
}
let state = state_opt.as_mut().expect("result should be none");
let expected = state.proposer_lookahead().unwrap();
let ssz_bytes = result.unwrap();
let decoded = Vec::<u64>::from_ssz_bytes(&ssz_bytes)
.expect("should decode SSZ proposer lookahead");
assert_eq!(decoded, expected.to_vec());
}
self
}
pub async fn test_beacon_headers_all_slots(self) -> Self {
for slot in 0..CHAIN_LENGTH {
let slot = Slot::from(slot);
@@ -7360,6 +7426,23 @@ async fn beacon_get_state_info_electra() {
.await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn beacon_get_state_info_fulu() {
let mut config = ApiTesterConfig::default();
config.spec.altair_fork_epoch = Some(Epoch::new(0));
config.spec.bellatrix_fork_epoch = Some(Epoch::new(0));
config.spec.capella_fork_epoch = Some(Epoch::new(0));
config.spec.deneb_fork_epoch = Some(Epoch::new(0));
config.spec.electra_fork_epoch = Some(Epoch::new(0));
config.spec.fulu_fork_epoch = Some(Epoch::new(0));
ApiTester::new_from_config(config)
.await
.test_beacon_states_proposer_lookahead()
.await
.test_beacon_states_proposer_lookahead_ssz()
.await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn beacon_get_blocks() {
ApiTester::new()