ContextDeserialize and Beacon API Improvements (#7372)

* #7286
* BeaconAPI is not returning a versioned response when it should for some V1 endpoints
* these [strange functions with vX in the name that still accept `endpoint_version` arguments](https://github.com/sigp/lighthouse/blob/stable/beacon_node/http_api/src/produce_block.rs#L192)

This refactor is a prerequisite to get the fulu EF tests running.
This commit is contained in:
ethDreamer
2025-05-19 00:05:16 -05:00
committed by GitHub
parent fcfcbf9a11
commit 7684d1f866
92 changed files with 1863 additions and 827 deletions

View File

@@ -1,14 +1,15 @@
use crate::version::{
add_consensus_version_header, add_ssz_content_type_header, fork_versioned_response, V1,
add_consensus_version_header, add_ssz_content_type_header, beacon_response,
ResponseIncludesVersion,
};
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
use eth2::types::{
self as api_types, ChainSpec, ForkVersionedResponse, LightClientUpdate,
LightClientUpdateResponseChunk, LightClientUpdateResponseChunkInner, LightClientUpdatesQuery,
self as api_types, ChainSpec, LightClientUpdate, LightClientUpdateResponseChunk,
LightClientUpdateResponseChunkInner, LightClientUpdatesQuery,
};
use ssz::Encode;
use std::sync::Arc;
use types::{ForkName, Hash256, LightClientBootstrap};
use types::{BeaconResponse, ForkName, Hash256, LightClientBootstrap};
use warp::{
hyper::{Body, Response},
reply::Reply,
@@ -52,7 +53,7 @@ pub fn get_light_client_updates<T: BeaconChainTypes>(
let fork_versioned_response = light_client_updates
.iter()
.map(|update| map_light_client_update_to_json_response::<T>(&chain, update.clone()))
.collect::<Result<Vec<ForkVersionedResponse<LightClientUpdate<T::EthSpec>>>, Rejection>>()?;
.collect::<Vec<BeaconResponse<LightClientUpdate<T::EthSpec>>>>();
Ok(warp::reply::json(&fork_versioned_response).into_response())
}
}
@@ -88,10 +89,8 @@ pub fn get_light_client_bootstrap<T: BeaconChainTypes>(
warp_utils::reject::custom_server_error(format!("failed to create response: {}", e))
}),
_ => {
let fork_versioned_response = map_light_client_bootstrap_to_json_response::<T>(
fork_name,
light_client_bootstrap,
)?;
let fork_versioned_response =
map_light_client_bootstrap_to_json_response::<T>(fork_name, light_client_bootstrap);
Ok(warp::reply::json(&fork_versioned_response).into_response())
}
}
@@ -177,17 +176,20 @@ fn map_light_client_update_to_ssz_chunk<T: BeaconChainTypes>(
fn map_light_client_bootstrap_to_json_response<T: BeaconChainTypes>(
fork_name: ForkName,
light_client_bootstrap: LightClientBootstrap<T::EthSpec>,
) -> Result<ForkVersionedResponse<LightClientBootstrap<T::EthSpec>>, Rejection> {
fork_versioned_response(V1, fork_name, light_client_bootstrap)
) -> BeaconResponse<LightClientBootstrap<T::EthSpec>> {
beacon_response(
ResponseIncludesVersion::Yes(fork_name),
light_client_bootstrap,
)
}
fn map_light_client_update_to_json_response<T: BeaconChainTypes>(
chain: &BeaconChain<T>,
light_client_update: LightClientUpdate<T::EthSpec>,
) -> Result<ForkVersionedResponse<LightClientUpdate<T::EthSpec>>, Rejection> {
) -> BeaconResponse<LightClientUpdate<T::EthSpec>> {
let fork_name = chain
.spec
.fork_name_at_slot::<T::EthSpec>(*light_client_update.signature_slot());
fork_versioned_response(V1, fork_name, light_client_update)
beacon_response(ResponseIncludesVersion::Yes(fork_name), light_client_update)
}