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

@@ -38,8 +38,11 @@ use types::{
ExecutionPayloadHeaderRefMut, ExecutionRequests, ForkName, ForkVersionDecode, Hash256,
SignedBlindedBeaconBlock, SignedRoot, SignedValidatorRegistrationData, Slot, Uint256,
};
use warp::reply::{self, Reply};
use warp::{Filter, Rejection};
use warp::{
Filter, Rejection,
http::StatusCode,
reply::{self, Reply},
};
pub const DEFAULT_FEE_RECIPIENT: Address = Address::repeat_byte(42);
pub const DEFAULT_GAS_LIMIT: u64 = 60_000_000;
@@ -1063,11 +1066,10 @@ pub fn serve<E: EthSpec>(
.unwrap(),
)
} else {
Ok(warp::http::Response::builder()
.status(202)
.body(&[] as &'static [u8])
.map(|res| add_consensus_version_header(res, fork_name))
.unwrap())
Ok(add_consensus_version_header(
StatusCode::ACCEPTED.into_response(),
fork_name,
))
}
},
);
@@ -1114,11 +1116,10 @@ pub fn serve<E: EthSpec>(
.unwrap(),
)
} else {
Ok(warp::http::Response::builder()
.status(202)
.body("".to_string())
.map(|res| add_consensus_version_header(res, fork_name))
.unwrap())
Ok(add_consensus_version_header(
StatusCode::ACCEPTED.into_response(),
fork_name,
))
}
},
);
@@ -1184,9 +1185,21 @@ pub fn serve<E: EthSpec>(
.or(warp::get().and(status).or(header))
.map(|reply| warp::reply::with_header(reply, "Server", "lighthouse-mock-builder-server"));
let (listening_socket, server) = warp::serve(routes)
.try_bind_ephemeral(SocketAddrV4::new(listen_addr, listen_port))
// Use a `std::net::TcpListener` here which keeps the parent `serve` function from needing to be async.
// Once the mock_builder server has been migrated to Axum, we can use the tokio listener directly
// since we will require async anyway.
let std_listener = std::net::TcpListener::bind(SocketAddrV4::new(listen_addr, listen_port))
.expect("mock builder server should start");
std_listener
.set_nonblocking(true)
.expect("mock builder server should set nonblocking");
let listener = tokio::net::TcpListener::from_std(std_listener)
.expect("mock builder server should convert to tokio listener");
let listening_socket = listener
.local_addr()
.expect("mock builder server should have a local address");
let server = warp::serve(routes).incoming(listener).run();
Ok((listening_socket, server))
}

View File

@@ -495,6 +495,12 @@ impl From<String> for Error {
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Other(e.to_string())
}
}
#[derive(Debug)]
struct MissingIdField;
@@ -725,12 +731,18 @@ pub fn serve<E: EthSpec>(
// Add a `Server` header.
.map(|reply| warp::reply::with_header(reply, "Server", "lighthouse-mock-execution-client"));
let (listening_socket, server) = warp::serve(routes).try_bind_with_graceful_shutdown(
SocketAddrV4::new(config.listen_addr, config.listen_port),
async {
let std_listener =
std::net::TcpListener::bind(SocketAddrV4::new(config.listen_addr, config.listen_port))?;
std_listener.set_nonblocking(true)?;
let listener = tokio::net::TcpListener::from_std(std_listener)?;
let listening_socket = listener.local_addr()?;
let server = warp::serve(routes)
.incoming(listener)
.graceful(async {
shutdown.await;
},
)?;
})
.run();
info!(
listen_address = listening_socket.to_string(),