Skip to content

Commit

Permalink
chore: update hyper et al
Browse files Browse the repository at this point in the history
Update a number of http related libraries, including but not limited to:
- hyper
- rustls
- axum
  • Loading branch information
bmwill committed Jul 26, 2024
1 parent e8b092e commit da6dd18
Show file tree
Hide file tree
Showing 59 changed files with 765 additions and 709 deletions.
594 changes: 314 additions & 280 deletions Cargo.lock

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ arrow = "52"
arrow-array = "52"
arc-swap = { version = "1.5.1", features = ["serde"] }
assert_cmd = "2.0.6"
async-graphql = "6.0.7"
async-graphql-axum = "6.0.7"
async-graphql-value = "6.0.7"
async-graphql = "=7.0.1"
async-graphql-axum = "=7.0.1"
async-graphql-value = "=7.0.1"
async-recursion = "1.0.4"
async-trait = "0.1.61"
atomic_float = "0.1"
Expand All @@ -253,8 +253,7 @@ aws-sdk-dynamodb = "0.29.0"
aws-sdk-s3 = "0.29.0"
aws-smithy-http = "0.56"
aws-smithy-runtime-api = "0.56"
axum = { version = "0.6.6", default-features = false, features = [
"headers",
axum = { version = "0.7", default-features = false, features = [
"tokio",
"http1",
"http2",
Expand All @@ -265,8 +264,8 @@ axum = { version = "0.6.6", default-features = false, features = [
"query",
"ws",
] }
axum-extra = "0.4.2"
axum-server = { version = "0.5.1", default-features = false, features = [
axum-extra = { version = "0.9", features = ["typed-header"] }
axum-server = { git = "https://github.com/bmwill/axum-server.git", rev = "f44323e271afdd1365fd0c8b0a4c0bbdf4956cb7", version = "0.6", default-features = false, features = [
"tls-rustls",
] }
backoff = { version = "0.4.0", features = [
Expand Down Expand Up @@ -342,11 +341,12 @@ hdrhistogram = "7.5.1"
hex = "0.4.3"
hex-literal = "0.3.4"
highlight = "all"
http = "0.2.8"
http-body = "0.4.5"
http = "1"
http-body = "1"
humantime = "2.1.0"
hyper = "0.14.20"
hyper-rustls = { version = "0.24", features = ["webpki-roots", "http2"] }
hyper = "1"
hyper-util = "0.1.6"
hyper-rustls = { version = "0.27", default-features = false, features = ["webpki-roots", "http2", "ring", "tls12"] }
im = "15"
impl-trait-for-tuples = "0.2.0"
indexmap = { version = "2.1.0", features = ["serde"] }
Expand Down Expand Up @@ -405,15 +405,15 @@ prometheus-http-query = { version = "0.8", default_features = false, features =
prometheus-parse = { git = "https://github.com/asonnino/prometheus-parser.git", rev = "75334db" }
proptest = "1.1.0"
proptest-derive = "0.3.0"
prost = "0.12.3"
prost-build = "0.12.3"
prost = "0.13"
prost-build = "0.13"
protobuf = { version = "2.28", features = ["with-bytes"] }
protobuf-src = "1.1.0"
quinn-proto = "0.11"
quote = "1.0.23"
rand = "0.8.5"
rayon = "1.5.3"
rcgen = "0.9.2"
rcgen = "0.13"
regex = "1.7.1"
reqwest = { version = "0.12", default_features = false, features = [
"blocking",
Expand All @@ -439,8 +439,8 @@ rusoto_kms = { version = "0.48.0", default_features = false, features = [
russh = "0.38.0"
russh-keys = "0.38.0"
rust-version = "1.56.1"
rustls = { version = "0.21.12", features = ["dangerous_configuration"] }
rustls-pemfile = "1.0.2"
rustls = { version = "0.23", default-features = false, features = ["std", "tls12", "ring"] }
rustls-pemfile = "2"
rustversion = "1.0.9"
rustyline = "9.1.2"
rustyline-derive = "0.7.0"
Expand Down Expand Up @@ -483,25 +483,25 @@ thiserror = "1.0.40"
tiny-bip39 = "1.0.0"
tokio = "1.36.0"
tokio-retry = "0.3"
tokio-rustls = "0.24"
tokio-rustls = { version = "0.26", default-features = false, features = ["tls12", "ring"] }
tokio-stream = { version = "0.1.14", features = ["sync", "net"] }
tokio-util = "0.7.10"
toml = { version = "0.7.4", features = ["preserve_order"] }
toml_edit = { version = "0.19.10" }
# NOTE: do not enable the `tls` feature on tonic. It will break custom TLS handling
# for self signed certificates. Unit tests under consensus/core and other integration
# tests will fail.
tonic = { version = "0.11", features = ["transport"] }
tonic-build = { version = "0.11", features = ["prost", "transport"] }
tonic-health = "0.11"
tonic = { version = "0.12", features = ["transport"] }
tonic-build = { version = "0.12", features = ["prost", "transport"] }
tonic-health = "0.12"
tower = { version = "0.4.12", features = [
"full",
"util",
"timeout",
"load-shed",
"limit",
] }
tower-http = { version = "0.3.4", features = [
tower-http = { version = "0.5", features = [
"cors",
"full",
"trace",
Expand All @@ -528,7 +528,7 @@ unescape = "0.1.0"
ureq = "2.9.1"
url = "2.3.1"
uuid = { version = "1.1.2", features = ["v4", "fast-rng"] }
webpki = { version = "0.101.0", package = "rustls-webpki", features = [
webpki = { version = "0.102", package = "rustls-webpki", features = [
"alloc",
"std",
] }
Expand Down
1 change: 1 addition & 0 deletions consensus/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fastcrypto.workspace = true
futures.workspace = true
http.workspace = true
hyper.workspace = true
hyper-util.workspace = true
hyper-rustls.workspace = true
itertools.workspace = true
quinn-proto.workspace = true
Expand Down
31 changes: 18 additions & 13 deletions consensus/core/src/network/tonic_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use bytes::Bytes;
use cfg_if::cfg_if;
use consensus_config::{AuthorityIndex, NetworkKeyPair, NetworkPublicKey};
use futures::{stream, Stream, StreamExt as _};
use hyper::server::conn::Http;
use hyper_util::rt::tokio::TokioIo;
use hyper_util::service::TowerToHyperService;
use mysten_common::sync::notify_once::NotifyOnce;
use mysten_metrics::monitored_future;
use mysten_network::{
Expand Down Expand Up @@ -144,15 +145,18 @@ impl NetworkClient for TonicClient {
let response = client.subscribe_blocks(request).await.map_err(|e| {
ConsensusError::NetworkRequest(format!("subscribe_blocks failed: {e:?}"))
})?;
let stream = response.into_inner().filter_map(move |b| async move {
match b {
Ok(response) => Some(response.block),
Err(e) => {
debug!("Network error received from {}: {e:?}", peer);
None
let stream = response
.into_inner()
.take_while(|b| futures::future::ready(b.is_ok()))
.filter_map(move |b| async move {
match b {
Ok(response) => Some(response.block),
Err(e) => {
debug!("Network error received from {}: {e:?}", peer);
None
}
}
}
});
});
let rate_limited_stream =
tokio_stream::StreamExt::throttle(stream, self.context.parameters.min_round_delay / 2)
.boxed();
Expand Down Expand Up @@ -692,13 +696,14 @@ impl<S: NetworkService> NetworkManager<S> for TonicManager {
.max_encoding_message_size(config.message_size_limit)
.max_decoding_message_size(config.message_size_limit),
)
.into_service();
.into_router();

let inbound_metrics = self.context.metrics.network_metrics.inbound.clone();
let excessive_message_size = self.context.parameters.tonic.excessive_message_size;

let mut http = Http::new();
http.http2_only(true);
let http =
hyper_util::server::conn::auto::Builder::new(hyper_util::rt::TokioExecutor::new())
.http2_only();
let http = Arc::new(http);

let tls_server_config =
Expand Down Expand Up @@ -875,7 +880,7 @@ impl<S: NetworkService> NetworkManager<S> for TonicManager {
.service(consensus_service.clone());

pin! {
let connection = http.serve_connection(tls_stream, svc);
let connection = http.serve_connection(TokioIo::new(tls_stream), TowerToHyperService::new(svc));
}
trace!("Connection ready. Starting to serve requests for {peer_addr:?}");

Expand Down
1 change: 1 addition & 0 deletions consensus/core/src/network/tonic_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub(crate) fn create_rustls_client_config(
}

// Checks if the public key from a TLS certificate belongs to one of the validators.
#[derive(Debug)]
struct AllowedPublicKeys {
// TODO: refactor to use key bytes
keys: BTreeSet<Ed25519PublicKey>,
Expand Down
4 changes: 2 additions & 2 deletions crates/mysten-metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ pub fn start_prometheus_server(addr: SocketAddr) -> RegistryService {
.layer(Extension(registry_service.clone()));

tokio::spawn(async move {
axum::Server::bind(&addr)
.serve(app.into_make_service())
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
});
Expand Down
8 changes: 4 additions & 4 deletions crates/mysten-network/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use tonic::{
BoxFuture,
},
server::NamedService,
transport::{server::Router, Body},
transport::server::Router,
};
use tower::{
layer::util::{Identity, Stack},
Expand All @@ -41,7 +41,7 @@ pub struct ServerBuilder<M: MetricsCallbackProvider = DefaultMetricsCallbackProv
health_reporter: tonic_health::server::HealthReporter,
}

type AddPathToHeaderFunction = fn(&Request<Body>) -> Option<HeaderValue>;
type AddPathToHeaderFunction = fn(&Request<BoxBody>) -> Option<HeaderValue>;

type WrapperService<M> = Stack<
Stack<
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<M: MetricsCallbackProvider> ServerBuilder<M> {
.global_concurrency_limit
.map(tower::limit::GlobalConcurrencyLimitLayer::new);

fn add_path_to_request_header(request: &Request<Body>) -> Option<HeaderValue> {
fn add_path_to_request_header(request: &Request<BoxBody>) -> Option<HeaderValue> {
let path = request.uri().path();
Some(HeaderValue::from_str(path).unwrap())
}
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<M: MetricsCallbackProvider> ServerBuilder<M> {
/// Add a new service to this Server.
pub fn add_service<S>(mut self, svc: S) -> Self
where
S: Service<Request<Body>, Response = Response<BoxBody>, Error = Infallible>
S: Service<Request<BoxBody>, Response = Response<BoxBody>, Error = Infallible>
+ NamedService
+ Clone
+ Send
Expand Down
8 changes: 5 additions & 3 deletions crates/mysten-service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ where
pub async fn serve(app: Router) -> Result<()> {
// run it with hyper on localhost:3000
debug!("listening on http://localhost:{}", DEFAULT_PORT);
axum::Server::bind(&format!("0.0.0.0:{}", DEFAULT_PORT).parse()?)
.serve(app.into_make_service())
.await?;

let listener = tokio::net::TcpListener::bind(&format!("0.0.0.0:{}", DEFAULT_PORT))
.await
.unwrap();
axum::serve(listener, app).await?;
Ok(())
}
5 changes: 2 additions & 3 deletions crates/mysten-service/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

use axum::body::Body;
use axum::body::HttpBody;
use axum::http::Request;
use tower::ServiceExt;

Expand All @@ -21,8 +20,8 @@ async fn test_mysten_service() {
.unwrap();
assert_eq!(res.status(), 200);

let mut body = res.into_body();
let body_data = body.data().await.unwrap().unwrap();
let body = res.into_body();
let body_data = axum::body::to_bytes(body, usize::MAX).await.unwrap();
println!("{}", std::str::from_utf8(&body_data).unwrap());
assert_eq!(
&body_data[..],
Expand Down
14 changes: 8 additions & 6 deletions crates/sui-bridge/src/server/mock_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ pub fn run_mock_server(
mock_handler: BridgeRequestMockHandler,
) -> tokio::task::JoinHandle<()> {
tracing::info!("Starting mock server at {}", socket_address);
let server = axum::Server::bind(&socket_address).serve(
make_router(
let listener = std::net::TcpListener::bind(socket_address).unwrap();
listener.set_nonblocking(true).unwrap();
let listener = tokio::net::TcpListener::from_std(listener).unwrap();
tokio::spawn(async move {
let router = make_router(
Arc::new(mock_handler),
Arc::new(BridgeMetrics::new_for_testing()),
Arc::new(BridgeNodePublicMetadata::empty_for_testing()),
)
.into_make_service(),
);
tokio::spawn(async move { server.await.unwrap() })
);
axum::serve(listener, router).await.unwrap()
})
}
11 changes: 8 additions & 3 deletions crates/sui-bridge/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ pub fn run_server(
metrics: Arc<BridgeMetrics>,
metadata: Arc<BridgeNodePublicMetadata>,
) -> tokio::task::JoinHandle<()> {
let service = axum::Server::bind(socket_address)
.serve(make_router(Arc::new(handler), metrics, metadata).into_make_service());
let socket_address = *socket_address;
tokio::spawn(async move {
service.await.unwrap();
let listener = tokio::net::TcpListener::bind(socket_address).await.unwrap();
axum::serve(
listener,
make_router(Arc::new(handler), metrics, metadata).into_make_service(),
)
.await
.unwrap();
})
}

Expand Down
11 changes: 2 additions & 9 deletions crates/sui-core/src/traffic_controller/nodefw_test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,11 @@ impl NodeFwTestServer {
.route("/block_addresses", post(Self::block_addresses))
.with_state(app_state.clone());

let shutdown_signal = self.shutdown_signal.clone();
let addr = SocketAddr::from(([127, 0, 0, 1], port));
let server = axum::Server::bind(&addr)
.serve(app.into_make_service())
.with_graceful_shutdown(async move {
shutdown_signal.notified().await;
});

let handle = tokio::spawn(async move {
if let Err(e) = server.await {
panic!("Server error: {}", e);
}
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
});

tokio::spawn(Self::periodically_remove_expired_addresses(
Expand Down
5 changes: 2 additions & 3 deletions crates/sui-faucet/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ pub async fn start_faucet(

let addr = SocketAddr::new(IpAddr::V4(host_ip), port);
info!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await?;
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await?;
Ok(())
}

Expand Down
4 changes: 1 addition & 3 deletions crates/sui-graphql-e2e-tests/tests/call/simple.exp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ Headers: {
"content-type": "application/json",
"content-length": "157",
"x-sui-rpc-version": "2024.7.0-testing-no-sha",
"vary": "origin, access-control-request-method, access-control-request-headers",
"access-control-allow-origin": "*",
"vary": "origin",
"vary": "access-control-request-method",
"vary": "access-control-request-headers",
}
Service version: 2024.7.0-testing-no-sha
Response: {
Expand Down
1 change: 1 addition & 0 deletions crates/sui-graphql-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async-graphql-axum.workspace = true
async-graphql-value.workspace = true
async-trait.workspace = true
axum.workspace = true
axum-extra.workspace = true
bin-version.workspace = true
chrono.workspace = true
clap.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-graphql-rpc/schema/current_progress_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4402,6 +4402,8 @@ type ZkLoginVerifyResult {
errors: [String!]!
}

directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
schema {
query: Query
mutation: Mutation
Expand Down
Loading

0 comments on commit da6dd18

Please sign in to comment.