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

@@ -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}"