mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 21:34:46 +00:00
Clean up blockv3 metadata and client (#5015)
* Improve block production v3 client * Delete wayward line * Overhaul JSON endpoint as well * Rename timeout param * Update tests * I broke everything * Ah this is an insane fix * Remove unnecessary optionals * Doc fix
This commit is contained in:
@@ -1,17 +1,3 @@
|
||||
use bytes::Bytes;
|
||||
use std::sync::Arc;
|
||||
use types::{payload::BlockProductionVersion, *};
|
||||
|
||||
use beacon_chain::{
|
||||
BeaconBlockResponseWrapper, BeaconChain, BeaconChainTypes, ProduceBlockVerification,
|
||||
};
|
||||
use eth2::types::{self as api_types, EndpointVersion, SkipRandaoVerification};
|
||||
use ssz::Encode;
|
||||
use warp::{
|
||||
hyper::{Body, Response},
|
||||
Reply,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
build_block_contents,
|
||||
version::{
|
||||
@@ -20,6 +6,20 @@ use crate::{
|
||||
fork_versioned_response, inconsistent_fork_rejection,
|
||||
},
|
||||
};
|
||||
use beacon_chain::{
|
||||
BeaconBlockResponseWrapper, BeaconChain, BeaconChainTypes, ProduceBlockVerification,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use eth2::types::{
|
||||
self as api_types, EndpointVersion, ProduceBlockV3Metadata, SkipRandaoVerification,
|
||||
};
|
||||
use ssz::Encode;
|
||||
use std::sync::Arc;
|
||||
use types::{payload::BlockProductionVersion, *};
|
||||
use warp::{
|
||||
hyper::{Body, Response},
|
||||
Reply,
|
||||
};
|
||||
|
||||
pub fn get_randao_verification(
|
||||
query: &api_types::ValidatorBlocksQuery,
|
||||
@@ -40,7 +40,6 @@ pub fn get_randao_verification(
|
||||
}
|
||||
|
||||
pub async fn produce_block_v3<T: BeaconChainTypes>(
|
||||
endpoint_version: EndpointVersion,
|
||||
accept_header: Option<api_types::Accept>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
slot: Slot,
|
||||
@@ -68,13 +67,12 @@ pub async fn produce_block_v3<T: BeaconChainTypes>(
|
||||
warp_utils::reject::custom_bad_request(format!("failed to fetch a block: {:?}", e))
|
||||
})?;
|
||||
|
||||
build_response_v3(chain, block_response_type, endpoint_version, accept_header)
|
||||
build_response_v3(chain, block_response_type, accept_header)
|
||||
}
|
||||
|
||||
pub fn build_response_v3<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
|
||||
@@ -84,6 +82,13 @@ pub fn build_response_v3<T: BeaconChainTypes>(
|
||||
let consensus_block_value = block_response.consensus_block_value();
|
||||
let execution_payload_blinded = block_response.is_blinded();
|
||||
|
||||
let metadata = ProduceBlockV3Metadata {
|
||||
consensus_version: fork_name,
|
||||
execution_payload_blinded,
|
||||
execution_payload_value,
|
||||
consensus_block_value,
|
||||
};
|
||||
|
||||
let block_contents = build_block_contents::build_block_contents(fork_name, block_response)?;
|
||||
|
||||
match accept_header {
|
||||
@@ -100,12 +105,17 @@ pub fn build_response_v3<T: BeaconChainTypes>(
|
||||
.map_err(|e| -> warp::Rejection {
|
||||
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))
|
||||
.map(|res| add_execution_payload_blinded_header(res, execution_payload_blinded))
|
||||
.map(|res| add_execution_payload_value_header(res, execution_payload_value))
|
||||
.map(|res| add_consensus_block_value_header(res, consensus_block_value)),
|
||||
_ => Ok(warp::reply::json(&ForkVersionedResponse {
|
||||
version: Some(fork_name),
|
||||
metadata,
|
||||
data: block_contents,
|
||||
})
|
||||
.into_response())
|
||||
.map(|res| res.into_response())
|
||||
.map(|res| add_consensus_version_header(res, fork_name))
|
||||
.map(|res| add_execution_payload_blinded_header(res, execution_payload_blinded))
|
||||
.map(|res| add_execution_payload_value_header(res, execution_payload_value))
|
||||
.map(|res| add_consensus_block_value_header(res, consensus_block_value)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user