mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
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:
@@ -3,15 +3,14 @@ use crate::{
|
||||
version::{
|
||||
add_consensus_block_value_header, add_consensus_version_header,
|
||||
add_execution_payload_blinded_header, add_execution_payload_value_header,
|
||||
add_ssz_content_type_header, fork_versioned_response, inconsistent_fork_rejection,
|
||||
add_ssz_content_type_header, beacon_response, inconsistent_fork_rejection,
|
||||
ResponseIncludesVersion,
|
||||
},
|
||||
};
|
||||
use beacon_chain::{
|
||||
BeaconBlockResponseWrapper, BeaconChain, BeaconChainTypes, ProduceBlockVerification,
|
||||
};
|
||||
use eth2::types::{
|
||||
self as api_types, EndpointVersion, ProduceBlockV3Metadata, SkipRandaoVerification,
|
||||
};
|
||||
use eth2::types::{self as api_types, ProduceBlockV3Metadata, SkipRandaoVerification};
|
||||
use ssz::Encode;
|
||||
use std::sync::Arc;
|
||||
use types::{payload::BlockProductionVersion, *};
|
||||
@@ -115,7 +114,7 @@ pub fn build_response_v3<T: BeaconChainTypes>(
|
||||
warp_utils::reject::custom_server_error(format!("failed to create response: {}", e))
|
||||
}),
|
||||
_ => Ok(warp::reply::json(&ForkVersionedResponse {
|
||||
version: Some(fork_name),
|
||||
version: fork_name,
|
||||
metadata,
|
||||
data: block_contents,
|
||||
})
|
||||
@@ -129,7 +128,6 @@ pub fn build_response_v3<T: BeaconChainTypes>(
|
||||
}
|
||||
|
||||
pub async fn produce_blinded_block_v2<T: BeaconChainTypes>(
|
||||
endpoint_version: EndpointVersion,
|
||||
accept_header: Option<api_types::Accept>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
slot: Slot,
|
||||
@@ -155,11 +153,10 @@ pub async fn produce_blinded_block_v2<T: BeaconChainTypes>(
|
||||
.await
|
||||
.map_err(warp_utils::reject::unhandled_error)?;
|
||||
|
||||
build_response_v2(chain, block_response_type, endpoint_version, accept_header)
|
||||
build_response_v2(chain, block_response_type, accept_header)
|
||||
}
|
||||
|
||||
pub async fn produce_block_v2<T: BeaconChainTypes>(
|
||||
endpoint_version: EndpointVersion,
|
||||
accept_header: Option<api_types::Accept>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
slot: Slot,
|
||||
@@ -186,13 +183,12 @@ pub async fn produce_block_v2<T: BeaconChainTypes>(
|
||||
.await
|
||||
.map_err(warp_utils::reject::unhandled_error)?;
|
||||
|
||||
build_response_v2(chain, block_response_type, endpoint_version, accept_header)
|
||||
build_response_v2(chain, block_response_type, accept_header)
|
||||
}
|
||||
|
||||
pub fn build_response_v2<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
block_response: BeaconBlockResponseWrapper<T::EthSpec>,
|
||||
endpoint_version: EndpointVersion,
|
||||
accept_header: Option<api_types::Accept>,
|
||||
) -> Result<Response<Body>, warp::Rejection> {
|
||||
let fork_name = block_response
|
||||
@@ -210,8 +206,10 @@ pub fn build_response_v2<T: BeaconChainTypes>(
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_server_error(format!("failed to create response: {}", e))
|
||||
}),
|
||||
_ => fork_versioned_response(endpoint_version, fork_name, block_contents)
|
||||
.map(|response| warp::reply::json(&response).into_response())
|
||||
.map(|res| add_consensus_version_header(res, fork_name)),
|
||||
_ => Ok(warp::reply::json(&beacon_response(
|
||||
ResponseIncludesVersion::Yes(fork_name),
|
||||
block_contents,
|
||||
))
|
||||
.into_response()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user