Skip to content

fix(core): Update async-graphql, axum and tonic (#6901) #6969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
321 changes: 231 additions & 90 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ anemo-build = { git = "https://github.com/mystenlabs/anemo.git", rev = "c4e7e4cb
anemo-tower = { git = "https://github.com/mystenlabs/anemo.git", rev = "c4e7e4cb4b624d7738c2016d7b7885c6774ff9c2" }
anyhow = "1.0.71"
arc-swap = { version = "1.5.1", features = ["serde"] }
async-graphql = "=7.0.11"
async-graphql = "7.0.17"
async-recursion = "1.0.4"
async-trait = "0.1.61"
aws-config = "1.5.6"
aws-sdk-dynamodb = "1.42"
axum = { version = "0.7", default-features = false, features = ["tokio", "http1", "http2", "json", "matched-path", "original-uri", "form", "query", "ws"] }
axum-extra = { version = "0.9", features = ["typed-header"] }
axum = { version = "0.8", default-features = false, features = ["tokio", "http1", "http2", "json", "matched-path", "original-uri", "form", "query", "ws", "macros"] }
axum-extra = { version = "0.10", 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 = ["futures", "futures-core", "pin-project-lite", "tokio", "tokio_1"] }
base64 = "0.21.2"
Expand Down Expand Up @@ -346,9 +346,9 @@ tokio-rustls = { version = "0.26", default-features = false, features = ["tls12"
tokio-stream = { version = "0.1.14", features = ["sync", "net"] }
tokio-util = "0.7.10"
toml = { version = "0.7.4", features = ["preserve_order"] }
tonic = { version = "0.12", features = ["zstd", "transport"] }
tonic-build = { version = "0.12", features = ["prost", "transport"] }
tonic-health = "0.12"
tonic = { version = "0.13", features = ["zstd", "transport"] }
tonic-build = { version = "0.13", features = ["prost", "transport"] }
tonic-health = "0.13"
tower = { version = "0.4.12", features = ["full", "util", "timeout", "load-shed", "limit"] }
tower-http = { version = "0.5", features = ["cors", "full", "trace", "set-header", "propagate-header"] }
tracing = "0.1.37"
Expand Down
2 changes: 1 addition & 1 deletion consensus/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tokio-rustls.workspace = true
tokio-stream.workspace = true
tokio-util.workspace = true
tonic.workspace = true
tonic-rustls = "0.1.0"
tonic-rustls = "0.2.0"
tower.workspace = true
tower-http.workspace = true
tracing.workspace = true
Expand Down
21 changes: 10 additions & 11 deletions crates/iota-bridge/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,21 @@ pub const PING_PATH: &str = "/ping";

// Important: for BridgeActions, the paths need to match the ones in
// bridge_client.rs
pub const ETH_TO_IOTA_TX_PATH: &str = "/sign/bridge_tx/eth/iota/:tx_hash/:event_index";
pub const IOTA_TO_ETH_TX_PATH: &str = "/sign/bridge_tx/iota/eth/:tx_digest/:event_index";
pub const ETH_TO_IOTA_TX_PATH: &str = "/sign/bridge_tx/eth/iota/{tx_hash}/{event_index}";
pub const IOTA_TO_ETH_TX_PATH: &str = "/sign/bridge_tx/iota/eth/{tx_digest}/{event_index}";
pub const COMMITTEE_BLOCKLIST_UPDATE_PATH: &str =
"/sign/update_committee_blocklist/:chain_id/:nonce/:type/:keys";
pub const EMERGENCY_BUTTON_PATH: &str = "/sign/emergency_button/:chain_id/:nonce/:type";
"/sign/update_committee_blocklist/{chain_id}/{nonce}/{type}/{keys}";
pub const EMERGENCY_BUTTON_PATH: &str = "/sign/emergency_button/{chain_id}/{nonce}/{type}";
pub const LIMIT_UPDATE_PATH: &str =
"/sign/update_limit/:chain_id/:nonce/:sending_chain_id/:new_usd_limit";
"/sign/update_limit/{chain_id}/{nonce}/{sending_chain_id}/{new_usd_limit}";
pub const ASSET_PRICE_UPDATE_PATH: &str =
"/sign/update_asset_price/:chain_id/:nonce/:token_id/:new_usd_price";
"/sign/update_asset_price/{chain_id}/{nonce}/{token_id}/{new_usd_price}";
pub const EVM_CONTRACT_UPGRADE_PATH_WITH_CALLDATA: &str =
"/sign/upgrade_evm_contract/:chain_id/:nonce/:proxy_address/:new_impl_address/:calldata";
"/sign/upgrade_evm_contract/{chain_id}/{nonce}/{proxy_address}/{new_impl_address}/{calldata}";
pub const EVM_CONTRACT_UPGRADE_PATH: &str =
"/sign/upgrade_evm_contract/:chain_id/:nonce/:proxy_address/:new_impl_address";
pub const ADD_TOKENS_ON_IOTA_PATH: &str =
"/sign/add_tokens_on_iota/:chain_id/:nonce/:native/:token_ids/:token_type_names/:token_prices";
pub const ADD_TOKENS_ON_EVM_PATH: &str = "/sign/add_tokens_on_evm/:chain_id/:nonce/:native/:token_ids/:token_addresses/:token_iota_decimals/:token_prices";
"/sign/upgrade_evm_contract/{chain_id}/{nonce}/{proxy_address}/{new_impl_address}";
pub const ADD_TOKENS_ON_IOTA_PATH: &str = "/sign/add_tokens_on_iota/{chain_id}/{nonce}/{native}/{token_ids}/{token_type_names}/{token_prices}";
pub const ADD_TOKENS_ON_EVM_PATH: &str = "/sign/add_tokens_on_evm/{chain_id}/{nonce}/{native}/{token_ids}/{token_addresses}/{token_iota_decimals}/{token_prices}";

/// BridgeNode's public metadata that is acceesible via the `/ping` endpoint.
// Be careful with what to put here, as it is public.
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-faucet/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub async fn start_faucet(
.route("/", get(health))
.route("/gas", post(request_gas))
.route("/v1/gas", post(batch_request_gas))
.route("/v1/status/:task_id", get(request_status))
.route("/v1/status/{task_id}", get(request_status))
.layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(handle_error))
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-graphql-e2e-tests/tests/call/simple.snap
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ Response: {
task 15, lines 64-69:
//# run-graphql --show-usage --show-headers --show-service-version
Headers: {
"content-type": "application/json",
"content-length": "157",
"content-type": "application/graphql-response+json",
"x-iota-rpc-version": "1.2.0-testing-no-sha",
"vary": "origin, access-control-request-method, access-control-request-headers",
"access-control-allow-origin": "*",
"content-length": "157",
}
Service version: 1.2.0-testing-no-sha
Response: {
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-graphql-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ publish = false
# external dependencies
anyhow.workspace = true
async-graphql = { workspace = true, features = ["dataloader", "apollo_tracing", "tracing", "opentelemetry"] }
async-graphql-axum = "=7.0.11"
async-graphql-value = "=7.0.11"
async-graphql-axum = "7.0.17"
async-graphql-value = "7.0.17"
async-trait.workspace = true
axum.workspace = true
axum-extra.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions crates/iota-graphql-rpc/src/server/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ impl ServerBuilder {
if self.router.is_none() {
let router: Router = Router::new()
.route("/", post(graphql_handler))
.route("/:version", post(graphql_handler))
.route("/{version}", post(graphql_handler))
.route("/graphql", post(graphql_handler))
.route("/graphql/:version", post(graphql_handler))
.route("/graphql/{version}", post(graphql_handler))
.route("/health", get(health_check))
.route("/graphql/health", get(health_check))
.route("/graphql/:version/health", get(health_check))
.route("/graphql/{version}/health", get(health_check))
.with_state(self.state.clone())
.route_layer(CallbackLayer::new(MetricsMakeCallbackHandler {
metrics: self.state.metrics.clone(),
Expand All @@ -294,8 +294,8 @@ impl ServerBuilder {

pub fn layer<L>(mut self, layer: L) -> Self
where
L: Layer<Route> + Clone + Send + 'static,
L::Service: Service<Request<Body>> + Clone + Send + 'static,
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request<Body>> + Clone + Send + Sync + 'static,
<L::Service as Service<Request<Body>>>::Response: IntoResponse + 'static,
<L::Service as Service<Request<Body>>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-graphql-rpc/src/server/graphiql_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ async fn start_graphiql_server_impl(
// Add GraphiQL IDE handler on GET request to `/`` endpoint
let server = server_builder
.route("/", axum::routing::get(graphiql))
.route("/:version", axum::routing::get(graphiql))
.route("/{version}", axum::routing::get(graphiql))
.route("/graphql", axum::routing::get(graphiql))
.route("/graphql/:version", axum::routing::get(graphiql))
.route("/graphql/{version}", axum::routing::get(graphiql))
.layer(axum::extract::Extension(Some(ide_title)))
.build()?;

Expand Down
4 changes: 2 additions & 2 deletions crates/iota-graphql-rpc/src/server/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ mod tests {

Router::new()
.route("/", get(|| async { "Hello, Versioning!" }))
.route("/:version", get(|| async { "Hello, Versioning!" }))
.route("/{version}", get(|| async { "Hello, Versioning!" }))
.route("/graphql", get(|| async { "Hello, Versioning!" }))
.route("/graphql/:version", get(|| async { "Hello, Versioning!" }))
.route("/graphql/{version}", get(|| async { "Hello, Versioning!" }))
.layer(middleware::from_fn_with_state(
state.version,
check_version_middleware,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ String representation of an arbitrary width, possibly signed integer.
"""
scalar BigInt


type BridgeCommitteeInitTransaction {
bridgeObjInitialSharedVersion: UInt53!
}
Expand Down Expand Up @@ -1454,7 +1453,6 @@ enum Feature {
SYSTEM_STATE
}


"""
Access to the gas inputs, after they have been smashed into one coin. The
gas coin can only be used by reference, except for with
Expand Down Expand Up @@ -1546,7 +1544,6 @@ type GenesisTransaction {
events(first: Int, after: String, last: Int, before: String): EventConnection!
}


"""
Interface implemented by all GraphQL types that represent a Move datatype
(either structs or enums). This interface is used to provide a way to access
Expand Down Expand Up @@ -1702,7 +1699,6 @@ type Input {
ix: Int!
}


"""
String containing 32B hex-encoded address, with a leading "0x". Leading zeroes can be omitted on input but will always appear in outputs (IotaAddress in output is guaranteed to be 66 characters long).
"""
Expand Down Expand Up @@ -4290,7 +4286,6 @@ type StorageFund {
nonRefundableBalance: BigInt
}


"""
Details of the system that are decided during genesis.
"""
Expand Down Expand Up @@ -4954,8 +4949,17 @@ type ZkLoginVerifyResult {
errors: [String!]!
}

"""
Marks an element of a GraphQL schema as no longer supported.
"""
directive @deprecated(reason: String = "No longer supported") on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE
"""
Directs the executor to include this field or fragment only when the `if` argument is true.
"""
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
"""
Directs the executor to skip this field or fragment when the `if` argument is true.
"""
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
schema {
query: Query
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-json-rpc/src/axum_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pub mod ws {
}
},
Some(response) = rx.recv() => {
if socket.send(Message::Text(response)).await.is_err() {
if socket.send(Message::Text(response.into())).await.is_err() {
break;
}
},
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-network-stack/src/grpc_timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
use http::{HeaderMap, HeaderValue, Request, Response};
use pin_project_lite::pin_project;
use tokio::time::Sleep;
use tonic::Status;
use tonic::{Status, body::Body};
use tower::Service;

const GRPC_TIMEOUT_HEADER: &str = "grpc-timeout";
Expand Down Expand Up @@ -97,7 +97,7 @@ where
ready!(sleep.poll(cx));
let response = Status::deadline_exceeded("Timeout expired")
.into_http()
.map(|_| MaybeEmptyBody::empty());
.map(|_: Body| MaybeEmptyBody::empty());
return Poll::Ready(Ok(response));
}

Expand Down
9 changes: 5 additions & 4 deletions crates/iota-network-stack/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use futures::FutureExt;
use tokio::net::{TcpListener, ToSocketAddrs};
use tokio_stream::wrappers::TcpListenerStream;
use tonic::{
body::BoxBody,
body::Body,
codegen::{
BoxFuture,
http::{HeaderValue, Request, Response},
Expand Down Expand Up @@ -49,7 +49,7 @@ pub struct ServerBuilder<M: MetricsCallbackProvider = DefaultMetricsCallbackProv
health_reporter: tonic_health::server::HealthReporter,
}

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

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

fn add_path_to_request_header(request: &Request<BoxBody>) -> Option<HeaderValue> {
fn add_path_to_request_header(request: &Request<Body>) -> Option<HeaderValue> {
let path = request.uri().path();
Some(HeaderValue::from_str(path).unwrap())
}
Expand Down Expand Up @@ -152,10 +152,11 @@ 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<BoxBody>, Response = Response<BoxBody>, Error = Infallible>
S: Service<Request<Body>, Response = Response<Body>, Error = Infallible>
+ NamedService
+ Clone
+ Send
+ Sync
+ 'static,
S::Future: Send + 'static,
{
Expand Down
2 changes: 0 additions & 2 deletions crates/iota-proxy/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use std::sync::Arc;

use axum::{
async_trait,
body::{Body, Bytes},
extract::{Extension, FromRequest},
http::{Request, StatusCode},
Expand Down Expand Up @@ -104,7 +103,6 @@ pub async fn expect_valid_public_key(
#[derive(Debug)]
pub struct LenDelimProtobuf(pub Vec<MetricFamily>);

#[async_trait]
impl<S> FromRequest<S> for LenDelimProtobuf
where
S: Send + Sync,
Expand Down
2 changes: 0 additions & 2 deletions crates/iota-rest-api/src/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ fn parse_accept(headers: &HeaderMap) -> Vec<Mime> {
items.into_iter().map(|(mime, _)| mime).collect()
}

#[axum::async_trait]
impl<S> axum::extract::FromRequestParts<S> for Accept
where
S: Send + Sync,
Expand All @@ -54,7 +53,6 @@ pub enum AcceptFormat {
Bcs,
}

#[axum::async_trait]
impl<S> axum::extract::FromRequestParts<S> for AcceptFormat
where
S: Send + Sync,
Expand Down
1 change: 0 additions & 1 deletion crates/iota-rest-api/src/content_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ fn parse_content_type(headers: &HeaderMap) -> Result<Option<Mime>, mime::FromStr
Ok(Some(mime))
}

#[axum::async_trait]
impl<S> axum::extract::FromRequestParts<S> for ContentType
where
S: Send + Sync,
Expand Down
6 changes: 1 addition & 5 deletions crates/iota-rest-api/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ impl<'a, S> Api<'a, S> {
let handler = endpoint.handler();
assert_eq!(handler.method(), endpoint.method());

// we need to replace any path parameters wrapped in braces to be prefaced by a
// colon until axum updates matchit: https://github.com/tokio-rs/axum/pull/2645
let path = endpoint.path().replace('{', ":").replace('}', "");

router = router.route(&path, handler.handler);
router = router.route(endpoint.path(), handler.handler);
}

router
Expand Down
1 change: 0 additions & 1 deletion crates/iota-rest-api/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ where
}
}

#[axum::async_trait]
impl<T, S> axum::extract::FromRequest<S> for Bcs<T>
where
T: serde::de::DeserializeOwned,
Expand Down
6 changes: 3 additions & 3 deletions crates/iota-rest-api/src/transactions/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::{net::SocketAddr, sync::Arc};

use axum::extract::{Query, State};
use axum::extract::{Query, State, rejection::ExtensionRejection};
use iota_sdk2::types::{
Address, BalanceChange, CheckpointSequenceNumber, Object, Owner, SignedTransaction,
TransactionEffects, TransactionEvents, ValidatorAggregatedSignature, framework::Coin,
Expand Down Expand Up @@ -68,7 +68,7 @@ impl ApiEndpoint<RestService> for ExecuteTransaction {
async fn execute_transaction(
State(state): State<Option<Arc<dyn TransactionExecutor>>>,
Query(parameters): Query<ExecuteTransactionQueryParameters>,
client_address: Option<axum::extract::ConnectInfo<SocketAddr>>,
client_address: Result<axum::extract::ConnectInfo<SocketAddr>, ExtensionRejection>,
accept: AcceptFormat,
Bcs(transaction): Bcs<SignedTransaction>,
) -> Result<ResponseContent<TransactionExecutionResponse>> {
Expand All @@ -88,7 +88,7 @@ async fn execute_transaction(
output_objects,
auxiliary_data: _,
} = executor
.execute_transaction(request, client_address.map(|a| a.0))
.execute_transaction(request, client_address.ok().map(|a| a.0))
.await?;

let (effects, finality) = {
Expand Down
2 changes: 0 additions & 2 deletions crates/iota-rest-kv/src/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use core::str;

use axum::{
async_trait,
extract::{FromRequestParts, Path},
http::request::Parts,
};
Expand All @@ -33,7 +32,6 @@ struct RequestParams {
/// internally into [`RequestParams`] and constructs a [`Key`].
pub struct ExtractPath(pub Key);

#[async_trait]
impl<S> FromRequestParts<S> for ExtractPath
where
S: Send + Sync,
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-rest-kv/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Server {

let router = Router::new()
.route("/health", get(health::health))
.route("/:item_type/:key", get(kv_store::data_as_bytes))
.route("/{item_type}/{key}", get(kv_store::data_as_bytes))
.with_state(shared_state)
.fallback(fallback);

Expand Down
Loading
Loading