Add version to the response of beacon API getPendingConsolidations (#8251)

* #7440


  


Co-Authored-By: Tan Chee Keong <tanck@sigmaprime.io>
This commit is contained in:
chonghe
2025-10-21 21:58:10 +08:00
committed by GitHub
parent 66f88f6bb4
commit 040d992132
3 changed files with 30 additions and 13 deletions

View File

@@ -1236,8 +1236,8 @@ pub fn serve<T: BeaconChainTypes>(
|state_id: StateId,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>| {
task_spawner.blocking_json_task(Priority::P1, move || {
let (data, execution_optimistic, finalized) = state_id
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| {
@@ -1247,15 +1247,23 @@ pub fn serve<T: BeaconChainTypes>(
));
};
Ok((consolidations.clone(), execution_optimistic, finalized))
Ok((
consolidations.clone(),
execution_optimistic,
finalized,
state.fork_name_unchecked(),
))
},
)?;
Ok(api_types::ExecutionOptimisticFinalizedResponse {
execution_optimistic_finalized_beacon_response(
ResponseIncludesVersion::Yes(fork_name),
execution_optimistic,
finalized,
data,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
})
)
.map(|res| warp::reply::json(&res).into_response())
.map(|resp| add_consensus_version_header(resp, fork_name))
})
},
);

View File

@@ -1369,12 +1369,14 @@ impl ApiTester {
.ok()
.map(|(state, _execution_optimistic, _finalized)| state);
let result = self
let result = match self
.client
.get_beacon_states_pending_consolidations(state_id.0)
.await
.unwrap()
.map(|res| res.data);
{
Ok(response) => response,
Err(e) => panic!("query failed incorrectly: {e:?}"),
};
if result.is_none() && state_opt.is_none() {
continue;
@@ -1383,7 +1385,12 @@ impl ApiTester {
let state = state_opt.as_mut().expect("result should be none");
let expected = state.pending_consolidations().unwrap();
assert_eq!(result.unwrap(), expected.to_vec());
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

View File

@@ -943,7 +943,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_states_pending_consolidations(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticFinalizedResponse<Vec<PendingConsolidation>>>, Error>
) -> Result<Option<ExecutionOptimisticFinalizedBeaconResponse<Vec<PendingConsolidation>>>, Error>
{
let mut path = self.eth_path(V1)?;
@@ -954,7 +954,9 @@ impl BeaconNodeHttpClient {
.push(&state_id.to_string())
.push("pending_consolidations");
self.get_opt(path).await
self.get_fork_contextual(path, |fork| fork)
.await
.map(|opt| opt.map(BeaconResponse::ForkVersioned))
}
/// `GET beacon/light_client/updates`