From 040d992132a62eafb4c80108f5eed77da97894bc Mon Sep 17 00:00:00 2001 From: chonghe <44791194+chong-he@users.noreply.github.com> Date: Tue, 21 Oct 2025 21:58:10 +0800 Subject: [PATCH] Add `version` to the response of beacon API `getPendingConsolidations` (#8251) * #7440 Co-Authored-By: Tan Chee Keong --- beacon_node/http_api/src/lib.rs | 22 +++++++++++++++------- beacon_node/http_api/tests/tests.rs | 15 +++++++++++---- common/eth2/src/lib.rs | 6 ++++-- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 7f6c97a0f8..170012b04b 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -1236,8 +1236,8 @@ pub fn serve( |state_id: StateId, task_spawner: TaskSpawner, chain: Arc>| { - 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( )); }; - 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)) }) }, ); diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 9c18a7c1e8..7c2282a488 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -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 diff --git a/common/eth2/src/lib.rs b/common/eth2/src/lib.rs index 0423794d0d..995e6966ea 100644 --- a/common/eth2/src/lib.rs +++ b/common/eth2/src/lib.rs @@ -943,7 +943,7 @@ impl BeaconNodeHttpClient { pub async fn get_beacon_states_pending_consolidations( &self, state_id: StateId, - ) -> Result>>, Error> + ) -> Result>>, 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`