Bump warp and begin axum migration (#9001)

- Bump `warp` to 0.4. This unifies `warp` and `axum` onto the same `http`, `hyper`, `h2`, `rustls`, etc versions.
- Create `axum_utils` which contain common functions and types
- Begins migration of all HTTP API servers from warp to axum


Co-Authored-By: Mac L <mjladson@pm.me>
This commit is contained in:
Mac L
2026-06-25 18:19:29 +04:00
committed by GitHub
parent a4c4cccf04
commit 8c2a909061
41 changed files with 1333 additions and 543 deletions

View File

@@ -6,6 +6,8 @@ edition = { workspace = true }
autotests = false # using a single test binary compiles faster
[dependencies]
axum = { workspace = true }
axum_utils = { workspace = true }
beacon_chain = { workspace = true }
beacon_processor = { workspace = true }
bls = { workspace = true }
@@ -44,6 +46,7 @@ store = { workspace = true }
sysinfo = { workspace = true }
system_health = { path = "../../common/system_health" }
task_executor = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tokio-stream = { workspace = true }
tracing = { workspace = true }

View File

@@ -6,10 +6,7 @@ use eth2::types::{self, EndpointVersion, Hash256, Slot};
use std::sync::Arc;
use types::beacon_response::EmptyMetadata;
use types::{CommitteeIndex, ForkVersionedResponse};
use warp::{
hyper::{Body, Response},
reply::Reply,
};
use warp::reply::{Reply, Response};
pub fn get_aggregate_attestation<T: BeaconChainTypes>(
slot: Slot,
@@ -17,7 +14,7 @@ pub fn get_aggregate_attestation<T: BeaconChainTypes>(
committee_index: Option<CommitteeIndex>,
endpoint_version: EndpointVersion,
chain: Arc<BeaconChain<T>>,
) -> Result<Response<Body>, warp::reject::Rejection> {
) -> Result<Response, warp::reject::Rejection> {
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(slot);
let aggregate_attestation = if fork_name.electra_enabled() {
let Some(committee_index) = committee_index else {

View File

@@ -12,7 +12,10 @@ use std::sync::Arc;
use tokio::sync::mpsc::UnboundedSender;
use tracing::{debug, warn};
use types::SignedExecutionPayloadBid;
use warp::{Filter, Rejection, Reply, hyper::Body, hyper::Response};
use warp::{
Filter, Rejection,
reply::{Reply, Response},
};
// POST /eth/v1/beacon/execution_payload_bids (SSZ)
pub(crate) fn post_beacon_execution_payload_bids_ssz<T: BeaconChainTypes>(
@@ -78,7 +81,7 @@ pub fn publish_execution_payload_bid<T: BeaconChainTypes>(
bid: SignedExecutionPayloadBid<T::EthSpec>,
chain: &Arc<BeaconChain<T>>,
network_tx: &UnboundedSender<NetworkMessage<T::EthSpec>>,
) -> Result<Response<Body>, Rejection> {
) -> Result<Response, Rejection> {
let slot = bid.slot();
let builder_index = bid.message.builder_index;

View File

@@ -22,8 +22,9 @@ use tokio::sync::mpsc::UnboundedSender;
use tracing::{debug, error, info, warn};
use types::{BlockImportSource, EthSpec, SignedExecutionPayloadEnvelope};
use warp::{
Filter, Rejection, Reply,
hyper::{Body, Response},
Filter, Rejection,
http::response::Builder,
reply::{Reply, Response},
};
// POST beacon/execution_payload_envelopes (SSZ)
@@ -93,7 +94,7 @@ pub async fn publish_execution_payload_envelope<T: BeaconChainTypes>(
envelope: SignedExecutionPayloadEnvelope<T::EthSpec>,
chain: Arc<BeaconChain<T>>,
network_tx: &UnboundedSender<NetworkMessage<T::EthSpec>>,
) -> Result<Response<Body>, Rejection> {
) -> Result<Response, Rejection> {
let slot = envelope.slot();
let beacon_block_root = envelope.message.beacon_block_root;
@@ -345,10 +346,10 @@ pub(crate) fn get_beacon_execution_payload_envelopes<T: BeaconChainTypes>(
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(envelope.slot());
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(envelope.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(envelope.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",

View File

@@ -18,10 +18,7 @@ use types::{
AttestationShufflingId, BeaconStateError, CommitteeCache, EthSpec, RelativeEpoch,
RelativeEpochError,
};
use warp::filters::BoxedFilter;
use warp::http::Response;
use warp::hyper::Body;
use warp::{Filter, Reply};
use warp::{Filter, Reply, filters::BoxedFilter, http::response::Builder};
use warp_utils::query::multi_key_query;
type BeaconStatesPath<T> = BoxedFilter<(
@@ -205,10 +202,10 @@ pub fn get_beacon_state_proposer_lookahead<T: BeaconChainTypes>(
)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(data.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(data.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",

View File

@@ -51,6 +51,9 @@ use crate::utils::{AnyVersionFilter, EthV1Filter};
use crate::validator::post_validator_liveness_epoch;
use crate::validator::*;
use crate::version::beacon_response;
use axum::Router;
use axum_utils::server::Server;
use axum_utils::tls::TlsConfig;
use beacon::states;
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes, WhenSlotSkipped};
use beacon_processor::BeaconProcessorSend;
@@ -85,7 +88,6 @@ pub use state_id::StateId;
use std::future::Future;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::path::PathBuf;
use std::pin::Pin;
use std::str::FromStr;
use std::sync::Arc;
use sysinfo::{System, SystemExt};
@@ -107,27 +109,14 @@ use version::{
execution_optimistic_finalized_beacon_response, inconsistent_fork_rejection,
unsupported_version_rejection,
};
use warp::Reply;
use warp::hyper::Body;
use warp::sse::Event;
use warp::{Filter, Rejection, http::Response};
use warp::{Filter, Rejection, Reply, http::response::Builder, reply::Response, sse::Event};
use warp_utils::{query::multi_key_query, uor::UnifyingOrFilter};
const API_PREFIX: &str = "eth";
/// A custom type which allows for both unsecured and TLS-enabled HTTP servers.
type HttpServer = (SocketAddr, Pin<Box<dyn Future<Output = ()> + Send>>);
/// Alias for readability.
pub type ExecutionOptimistic = bool;
/// Configuration used when serving the HTTP server over TLS.
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct TlsConfig {
pub cert: PathBuf,
pub key: PathBuf,
}
/// A wrapper around all the items required to spawn the HTTP server.
///
/// The server will gracefully handle the case where any fields are `None`.
@@ -176,18 +165,18 @@ impl Default for Config {
}
}
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
Warp(warp::Error),
#[error("Builder error: {0}")]
Builder(#[from] axum_utils::server::BuilderError),
#[error("Server error: {0}")]
Server(#[from] axum_utils::server::ServerError),
#[error("Warp error: {0}")]
Warp(#[from] warp::Error),
#[error("{0}")]
Other(String),
}
impl From<warp::Error> for Error {
fn from(e: warp::Error) -> Self {
Error::Warp(e)
}
}
impl From<String> for Error {
fn from(e: String) -> Self {
Error::Other(e)
@@ -339,10 +328,10 @@ pub fn tracing_logging() -> warp::filters::log::Log<impl Fn(warp::filters::log::
///
/// Returns an error if the server is unable to bind or there is another error during
/// configuration.
pub fn serve<T: BeaconChainTypes>(
pub async fn serve<T: BeaconChainTypes>(
ctx: Arc<Context<T>>,
shutdown: impl Future<Output = ()> + Send + Sync + 'static,
) -> Result<HttpServer, Error> {
) -> Result<(SocketAddr, impl Future<Output = ()>), Error> {
let config = ctx.config.clone();
// Configure CORS.
@@ -1175,10 +1164,10 @@ pub fn serve<T: BeaconChainTypes>(
};
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(block.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(block.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -1311,10 +1300,10 @@ pub fn serve<T: BeaconChainTypes>(
.map_err(inconsistent_fork_rejection)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(block.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(block.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -1367,10 +1356,10 @@ pub fn serve<T: BeaconChainTypes>(
.map_err(inconsistent_fork_rejection)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(blob_sidecar_list_filtered.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(blob_sidecar_list_filtered.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -1416,10 +1405,10 @@ pub fn serve<T: BeaconChainTypes>(
block_id.get_blobs_by_versioned_hashes(versioned_hashes, &chain)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(response.data.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(response.data.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -1641,10 +1630,10 @@ pub fn serve<T: BeaconChainTypes>(
get_next_withdrawals::<T>(&chain, state, state_id, proposal_slot)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(withdrawals.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(withdrawals.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -1727,10 +1716,10 @@ pub fn serve<T: BeaconChainTypes>(
.spec
.fork_name_at_slot::<T::EthSpec>(update.get_slot());
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(update.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(update.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -1775,10 +1764,10 @@ pub fn serve<T: BeaconChainTypes>(
.spec
.fork_name_at_slot::<T::EthSpec>(update.signature_slot());
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(update.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(update.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -2000,10 +1989,10 @@ pub fn serve<T: BeaconChainTypes>(
block_id.get_data_columns(indices, &chain)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(data_columns.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(data_columns.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -2066,13 +2055,11 @@ pub fn serve<T: BeaconChainTypes>(
"HTTP state load"
);
Response::builder()
Builder::new()
.status(200)
.body(response_bytes.into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.map(|resp: warp::reply::Response| {
add_consensus_version_header(resp, fork_name)
})
.body(response_bytes)
.map(add_ssz_content_type_header)
.map(|resp: Response| add_consensus_version_header(resp, fork_name))
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -3521,34 +3508,40 @@ pub fn serve<T: BeaconChainTypes>(
.with(cors_builder.build())
.boxed();
let http_socket: SocketAddr = SocketAddr::new(config.listen_addr, config.listen_port);
let http_server: HttpServer = match config.tls_config {
Some(tls_config) => {
let (socket, server) = warp::serve(routes)
.tls()
.cert_path(tls_config.cert)
.key_path(tls_config.key)
.try_bind_with_graceful_shutdown(http_socket, async {
shutdown.await;
})?;
let axum_router = Router::new().fallback_service(warp::service(routes));
info!("HTTP API is being served over TLS");
let address = SocketAddr::new(config.listen_addr, config.listen_port);
(socket, Box::pin(server))
}
None => {
let (socket, server) =
warp::serve(routes).try_bind_with_graceful_shutdown(http_socket, async {
shutdown.await;
})?;
(socket, Box::pin(server))
}
};
let mut server_builder = Server::builder(axum_router, address);
let tls_enabled = config.tls_config.is_some();
if let Some(tls_config) = config.tls_config {
server_builder = server_builder.with_tls(tls_config);
}
let server = server_builder.build().await?;
let (address, server) = server.serve_with_shutdown(shutdown).await?;
if tls_enabled {
info!("HTTP API is being served over TLS");
}
info!(
listen_address = %http_server.0,
listen_address = %address,
"HTTP API started"
);
Ok(http_server)
let server_future = async move {
match server.await {
Ok(()) => {
info!("HTTP API server stopped");
}
Err(e) => {
tracing::error!(error = ?e, "HTTP API server error");
}
}
};
Ok((address, server_future))
}

View File

@@ -13,8 +13,8 @@ use std::sync::Arc;
use types::{EthSpec, ForkName, Hash256, LightClientBootstrap};
use warp::{
Rejection,
hyper::{Body, Response},
reply::Reply,
http::response::Builder,
reply::{Reply, Response},
};
const MAX_REQUEST_LIGHT_CLIENT_UPDATES: u64 = 128;
@@ -23,7 +23,7 @@ pub fn get_light_client_updates<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
query: LightClientUpdatesQuery,
accept_header: Option<api_types::Accept>,
) -> Result<Response<Body>, Rejection> {
) -> Result<Response, Rejection> {
validate_light_client_updates_request(&chain, &query)?;
let light_client_updates = chain
@@ -34,17 +34,17 @@ pub fn get_light_client_updates<T: BeaconChainTypes>(
match accept_header {
Some(api_types::Accept::Ssz) => {
let response_chunks = light_client_updates
let response_chunks: Vec<u8> = light_client_updates
.into_iter()
.flat_map(|update| {
map_light_client_update_to_response_chunk::<T>(&chain, update).as_ssz_bytes()
})
.collect();
Response::builder()
Builder::new()
.status(200)
.body(response_chunks)
.map(|res: Response<Vec<u8>>| add_ssz_content_type_header(res))
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
@@ -66,7 +66,7 @@ pub fn get_light_client_bootstrap<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
block_root: &Hash256,
accept_header: Option<api_types::Accept>,
) -> Result<Response<Body>, Rejection> {
) -> Result<Response, Rejection> {
let (light_client_bootstrap, fork_name) = chain
.get_light_client_bootstrap(block_root)
.map_err(|err| {
@@ -83,11 +83,11 @@ pub fn get_light_client_bootstrap<T: BeaconChainTypes>(
))?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(light_client_bootstrap.as_ssz_bytes().into())
.map(|res: Response<Body>| add_consensus_version_header(res, fork_name))
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.body(light_client_bootstrap.as_ssz_bytes())
.map(|res| add_consensus_version_header(res, fork_name))
.map(add_ssz_content_type_header)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!("failed to create response: {}", e))
}),

View File

@@ -18,8 +18,8 @@ use std::sync::Arc;
use tracing::instrument;
use types::{execution::BlockProductionVersion, *};
use warp::{
Reply,
hyper::{Body, Response},
http::response::Builder,
reply::{Reply, Response},
};
/// If default boost factor is provided in validator/blocks v3 request, we will skip the calculation
@@ -54,7 +54,7 @@ pub async fn produce_block_v4<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
slot: Slot,
query: api_types::ValidatorBlocksQuery,
) -> Result<Response<Body>, warp::Rejection> {
) -> Result<Response, warp::Rejection> {
let randao_reveal = query.randao_reveal.decompress().map_err(|e| {
warp_utils::reject::custom_bad_request(format!(
"randao reveal is not a valid BLS signature: {:?}",
@@ -106,7 +106,7 @@ pub async fn produce_block_v3<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
slot: Slot,
query: api_types::ValidatorBlocksQuery,
) -> Result<Response<Body>, warp::Rejection> {
) -> Result<Response, warp::Rejection> {
let randao_reveal = query.randao_reveal.decompress().map_err(|e| {
warp_utils::reject::custom_bad_request(format!(
"randao reveal is not a valid BLS signature: {:?}",
@@ -146,7 +146,7 @@ pub fn build_response_v4<T: BeaconChainTypes>(
execution_payload_included: bool,
accept_header: Option<api_types::Accept>,
spec: &ChainSpec,
) -> Result<Response<Body>, warp::Rejection> {
) -> Result<Response, warp::Rejection> {
let fork_name = block
.to_ref()
.fork_name(spec)
@@ -161,11 +161,11 @@ pub fn build_response_v4<T: BeaconChainTypes>(
};
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(block.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.map(|res: Response<Body>| add_consensus_version_header(res, fork_name))
.body(block.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map(|res| add_consensus_version_header(res, fork_name))
.map(|res| add_consensus_block_value_header(res, consensus_block_value_wei))
.map(|res| add_execution_payload_included_header(res, execution_payload_included))
.map_err(|e| -> warp::Rejection {
@@ -187,7 +187,7 @@ pub fn build_response_v3<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
block_response: BeaconBlockResponseWrapper<T::EthSpec>,
accept_header: Option<api_types::Accept>,
) -> Result<Response<Body>, warp::Rejection> {
) -> Result<Response, warp::Rejection> {
let fork_name = block_response
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;
@@ -205,15 +205,13 @@ pub fn build_response_v3<T: BeaconChainTypes>(
let block_contents = build_block_contents::build_block_contents(fork_name, block_response)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(block_contents.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.map(|res: Response<Body>| add_consensus_version_header(res, fork_name))
.body(block_contents.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map(|res| add_consensus_version_header(res, fork_name))
.map(|res| add_execution_payload_blinded_header(res, execution_payload_blinded))
.map(|res: Response<Body>| {
add_execution_payload_value_header(res, execution_payload_value)
})
.map(|res| add_execution_payload_value_header(res, execution_payload_value))
.map(|res| add_consensus_block_value_header(res, consensus_block_value))
.map_err(|e| -> warp::Rejection {
warp_utils::reject::custom_server_error(format!("failed to create response: {}", e))
@@ -224,7 +222,6 @@ pub fn build_response_v3<T: BeaconChainTypes>(
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))
@@ -237,7 +234,7 @@ pub async fn produce_blinded_block_v2<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
slot: Slot,
query: api_types::ValidatorBlocksQuery,
) -> Result<Response<Body>, warp::Rejection> {
) -> Result<Response, warp::Rejection> {
let randao_reveal = query.randao_reveal.decompress().map_err(|e| {
warp_utils::reject::custom_bad_request(format!(
"randao reveal is not a valid BLS signature: {:?}",
@@ -273,7 +270,7 @@ pub async fn produce_block_v2<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
slot: Slot,
query: api_types::ValidatorBlocksQuery,
) -> Result<Response<Body>, warp::Rejection> {
) -> Result<Response, warp::Rejection> {
let randao_reveal = query.randao_reveal.decompress().map_err(|e| {
warp_utils::reject::custom_bad_request(format!(
"randao reveal is not a valid BLS signature: {:?}",
@@ -303,7 +300,7 @@ pub fn build_response_v2<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
block_response: BeaconBlockResponseWrapper<T::EthSpec>,
accept_header: Option<api_types::Accept>,
) -> Result<Response<Body>, warp::Rejection> {
) -> Result<Response, warp::Rejection> {
let fork_name = block_response
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;
@@ -311,11 +308,11 @@ pub fn build_response_v2<T: BeaconChainTypes>(
let block_contents = build_block_contents::build_block_contents(fork_name, block_response)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
Some(api_types::Accept::Ssz) => Builder::new()
.status(200)
.body(block_contents.as_ssz_bytes().into())
.map(|res: Response<Body>| add_ssz_content_type_header(res))
.map(|res: Response<Body>| add_consensus_version_header(res, fork_name))
.body(block_contents.as_ssz_bytes())
.map(add_ssz_content_type_header)
.map(|res| add_consensus_version_header(res, fork_name))
.map_err(|e| {
warp_utils::reject::custom_server_error(format!("failed to create response: {}", e))
}),

View File

@@ -298,8 +298,9 @@ pub async fn create_api_server_with_config<T: BeaconChainTypes>(
)),
});
let (listening_socket, server) =
crate::serve(ctx.clone(), test_runtime.task_executor.exit()).unwrap();
let (listening_socket, server) = crate::serve(ctx.clone(), test_runtime.task_executor.exit())
.await
.unwrap();
ApiServer {
ctx,

View File

@@ -9,8 +9,7 @@ use ssz::Encode;
use std::sync::Arc;
use tracing::debug;
use types::Slot;
use warp::http::Response;
use warp::{Filter, Rejection};
use warp::{Filter, Rejection, http::response::Builder, reply::Reply};
// GET validator/execution_payload_envelopes/{slot}
pub fn get_validator_execution_payload_envelopes<T: BeaconChainTypes>(
@@ -58,11 +57,12 @@ pub fn get_validator_execution_payload_envelopes<T: BeaconChainTypes>(
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(slot);
match accept_header {
Some(Accept::Ssz) => Response::builder()
Some(Accept::Ssz) => Builder::new()
.status(200)
.header("Content-Type", "application/octet-stream")
.header("Eth-Consensus-Version", fork_name.to_string())
.body(envelope.as_ssz_bytes().into())
.body(envelope.as_ssz_bytes())
.map(|res| res.into_response())
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to build SSZ response: {e}"
@@ -74,19 +74,16 @@ pub fn get_validator_execution_payload_envelopes<T: BeaconChainTypes>(
metadata: EmptyMetadata {},
data: envelope,
};
Response::builder()
Builder::new()
.status(200)
.header("Content-Type", "application/json")
.header("Eth-Consensus-Version", fork_name.to_string())
.body(
serde_json::to_string(&json_response)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to serialize response: {e}"
))
})?
.into(),
)
.body(serde_json::to_string(&json_response).map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to serialize response: {e}"
))
})?)
.map(|res| res.into_response())
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to build JSON response: {e}"

View File

@@ -33,7 +33,7 @@ use types::{
SignedContributionAndProof, SignedProposerPreferences, SignedValidatorRegistrationData, Slot,
SyncContributionData, ValidatorSubscription,
};
use warp::{Filter, Rejection, Reply};
use warp::{Filter, Rejection, Reply, http::response::Builder};
use warp_utils::reject::convert_rejection;
pub mod execution_payload_envelopes;
@@ -299,7 +299,6 @@ pub fn get_validator_payload_attestation_data<T: BeaconChainTypes>(
) -> ResponseFilter {
use eth2::beacon_response::{EmptyMetadata, ForkVersionedResponse};
use ssz::Encode;
use warp::http::Response;
eth_v1
.and(warp::path("validator"))
@@ -351,12 +350,12 @@ pub fn get_validator_payload_attestation_data<T: BeaconChainTypes>(
})?;
match accept_header {
Some(Accept::Ssz) => Response::builder()
Some(Accept::Ssz) => Builder::new()
.status(200)
.header("Content-Type", "application/octet-stream")
.header("Eth-Consensus-Version", fork_name.to_string())
.body(payload_attestation_data.as_ssz_bytes().into())
.map(|res: Response<warp::hyper::Body>| res)
.body(payload_attestation_data.as_ssz_bytes())
.map(|res| res.into_response())
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to build SSZ response: {e}"
@@ -368,19 +367,16 @@ pub fn get_validator_payload_attestation_data<T: BeaconChainTypes>(
metadata: EmptyMetadata {},
data: payload_attestation_data,
};
Response::builder()
Builder::new()
.status(200)
.header("Content-Type", "application/json")
.header("Eth-Consensus-Version", fork_name.to_string())
.body(
serde_json::to_string(&json_response)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to serialize response: {e}"
))
})?
.into(),
)
.body(serde_json::to_string(&json_response).map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to serialize response: {e}"
))
})?)
.map(|res| res.into_response())
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to build JSON response: {e}"