Skip to content

Commit

Permalink
refactor: migrate to axum
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara committed Jun 20, 2024
1 parent 230e0bb commit c953ef1
Show file tree
Hide file tree
Showing 17 changed files with 476 additions and 667 deletions.
271 changes: 164 additions & 107 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ iroha_core = { version = "=2.0.0-pre-rc.21 ", path = "core" }

irohad = { version = "=2.0.0-pre-rc.21", path = "cli" }
iroha_torii = { version = "=2.0.0-pre-rc.21", path = "torii" }
iroha_torii_derive = { version = "=2.0.0-pre-rc.21", path = "torii/derive" }
iroha_torii_const = { version = "=2.0.0-pre-rc.21", path = "torii/const" }

iroha = { version = "=2.0.0-pre-rc.21", path = "client" }
Expand Down Expand Up @@ -117,10 +116,10 @@ getset = "0.1.2"
hex-literal = "0.4.1"

rand = { version = "0.8.5", default-features = false, features = ["getrandom", "alloc"] }
warp = { version = "0.3.7", default-features = false }
axum = { version = "0.7.5", default-features = false }
wasmtime = "15.0.1"

tracing = "0.1.40"
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = { version = "0.3.18", default-features = false }

dashmap = "5.5.3"
Expand Down Expand Up @@ -245,7 +244,6 @@ members = [
"tools/wasm_builder_cli",
"tools/wasm_test_runner",
"torii",
"torii/derive",
"torii/const",
"version",
"version/derive",
Expand Down
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ iroha_primitives = { workspace = true }
iroha_logger = { workspace = true }
iroha_telemetry = { workspace = true }
iroha_torii_const = { workspace = true }
iroha_version = { workspace = true, features = ["http"] }
iroha_version = { workspace = true }
test_samples = { workspace = true }

attohttpc = { version = "0.28.0", default-features = false }
Expand Down
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
3 changes: 1 addition & 2 deletions data_model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ default = ["std"]
# Please refer to https://docs.rust-embedded.org/book/intro/no-std.html
std = ["iroha_macro/std", "iroha_version/std", "iroha_crypto/std", "iroha_primitives/std", "thiserror", "displaydoc/std", "strum/std", "once_cell"]
# Enable API for HTTP requests. Should be activated for HTTP clients
http = ["std", "warp", "iroha_version/http"]
http = ["std"]
# Replace structures and methods with FFI equivalents to facilitate dynamic linkage (mainly used in smartcontracts)
#ffi_import = ["iroha_ffi", "iroha_primitives/ffi_import", "iroha_crypto/ffi_import"]

Expand All @@ -46,7 +46,6 @@ derive_more = { workspace = true, features = ["as_ref", "display", "constructor"
serde = { workspace = true, features = ["derive"] }
serde_with = { workspace = true, features = ["macros"] }
serde_json = { workspace = true }
warp = { workspace = true, optional = true }
thiserror = { workspace = true, optional = true }
displaydoc = { workspace = true }
getset = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ iroha_data_model = { workspace = true, features = ["http"] }

derive_more = { workspace = true, features = ["deref"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serde_json = { workspace = true, features = ["std"] }
once_cell = { workspace = true }
tracing = { workspace = true }
eyre = { workspace = true }
Expand Down
9 changes: 5 additions & 4 deletions torii/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,27 @@ telemetry = ["iroha_telemetry", "iroha_core/telemetry", "serde_json"]
# Enables profiling endpoint
profiling = ["pprof"]
# Enables Data Model Schema endpoint
schema = ["iroha_schema_gen"]
schema = ["iroha_schema", "iroha_schema_gen"]

[dependencies]
iroha_core = { workspace = true }
iroha_config = { workspace = true }
iroha_primitives = { workspace = true }
iroha_logger = { workspace = true }
iroha_data_model = { workspace = true, features = ["http"] }
iroha_version = { workspace = true, features = ["http"] }
iroha_torii_derive = { workspace = true }
iroha_version = { workspace = true }
iroha_torii_const = { workspace = true }
iroha_futures = { workspace = true }
iroha_macro = { workspace = true }
iroha_schema = { workspace = true, optional = true }
iroha_schema_gen = { workspace = true, optional = true }
iroha_telemetry = { workspace = true, optional = true }

thiserror = { workspace = true }
displaydoc = { workspace = true }
futures = { workspace = true, features = ["std", "async-await"] }
warp = { workspace = true, features = ["multipart", "websocket"] }
axum = { workspace = true, features = ["multipart", "ws", "query", "json", "tokio", "http1"] }
tower-http = { version = "0.5.0", features = ["trace", "timeout"] }
tokio = { workspace = true, features = ["sync", "time", "macros"] }
eyre = { workspace = true }
serde = { workspace = true, features = ["derive"] }
Expand Down
26 changes: 13 additions & 13 deletions torii/const/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ pub mod uri {
pub const DEFAULT_API_ADDR: iroha_primitives::addr::SocketAddr =
iroha_primitives::addr::socket_addr!(127.0.0.1:8080);
/// Query URI is used to handle incoming Query requests.
pub const QUERY: &str = "query";
pub const QUERY: &str = "/query";
/// Transaction URI is used to handle incoming ISI requests.
pub const TRANSACTION: &str = "transaction";
pub const TRANSACTION: &str = "/transaction";
/// Block URI is used to handle incoming Block requests.
pub const CONSENSUS: &str = "consensus";
pub const CONSENSUS: &str = "/consensus";
/// Health URI is used to handle incoming Healthcheck requests.
pub const HEALTH: &str = "health";
pub const HEALTH: &str = "/health";
/// The URI used for block synchronization.
pub const BLOCK_SYNC: &str = "block/sync";
pub const BLOCK_SYNC: &str = "/block/sync";
/// The web socket uri used to subscribe to block and transactions statuses.
pub const SUBSCRIPTION: &str = "events";
pub const SUBSCRIPTION: &str = "/events";
/// The web socket uri used to subscribe to blocks stream.
pub const BLOCKS_STREAM: &str = "block/stream";
pub const BLOCKS_STREAM: &str = "/block/stream";
/// The URI for local config changing inspecting
pub const CONFIGURATION: &str = "configuration";
pub const CONFIGURATION: &str = "/configuration";
/// URI to report status for administration
pub const STATUS: &str = "status";
pub const STATUS: &str = "/status";
/// Metrics URI is used to export metrics according to [Prometheus
/// Guidance](https://prometheus.io/docs/instrumenting/writing_exporters/).
pub const METRICS: &str = "metrics";
pub const METRICS: &str = "/metrics";
/// URI for retrieving the schema with which Iroha was built.
pub const SCHEMA: &str = "schema";
pub const SCHEMA: &str = "/schema";
/// URI for getting the API version currently used
pub const API_VERSION: &str = "api_version";
pub const API_VERSION: &str = "/api_version";
/// URI for getting cpu profile
pub const PROFILE: &str = "debug/pprof/profile";
pub const PROFILE: &str = "/debug/pprof/profile";
}
23 changes: 0 additions & 23 deletions torii/derive/Cargo.toml

This file was deleted.

161 changes: 0 additions & 161 deletions torii/derive/src/lib.rs

This file was deleted.

12 changes: 6 additions & 6 deletions torii/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Iroha is a quite dynamic system so many events can happen.
//! This module contains descriptions of such an events and
//! utility Iroha Special Instructions to work with them.
use axum::extract::ws::WebSocket;
use futures::TryStreamExt;
use iroha_data_model::events::prelude::*;
use iroha_macro::error::ErrorTryFromEnum;
use warp::ws::WebSocket;

use crate::stream::{self, Sink, Stream};
use crate::stream::{self, Sink, Stream, StreamMessage as _};

/// Type of Stream error
pub type StreamError = stream::Error<<WebSocket as Stream<EventSubscriptionRequest>>::Err>;
Expand All @@ -24,7 +24,7 @@ pub enum Error {
),
/// Error from provided websocket
#[error("WebSocket error: {0}")]
WebSocket(#[from] warp::Error),
WebSocket(#[from] axum::Error),
/// Error that occurs than `WebSocket::next()` call returns `None`
#[error("Can't receive message from stream")]
CantReceiveMessage,
Expand Down Expand Up @@ -54,7 +54,8 @@ impl Consumer {
/// Can fail due to timeout or without message at websocket or during decoding request
#[iroha_futures::telemetry_future]
pub async fn new(mut stream: WebSocket) -> Result<Self> {
let EventSubscriptionRequest(filters) = stream.recv().await?;
let EventSubscriptionRequest(filters) =
Stream::<EventSubscriptionRequest>::recv(&mut stream).await?;
Ok(Consumer { stream, filters })
}

Expand All @@ -68,8 +69,7 @@ impl Consumer {
return Ok(());
}

self.stream
.send(EventMessage(event))
Sink::<_>::send(&mut self.stream, EventMessage(event))
.await
.map_err(Into::into)
}
Expand Down
Loading

0 comments on commit c953ef1

Please sign in to comment.