diff --git a/Cargo.lock b/Cargo.lock index f0a13684..ca004fa7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,7 +13,7 @@ dependencies = [ [[package]] name = "air" -version = "0.25.0" +version = "0.26.0" dependencies = [ "air-execution-info-collector", "air-interpreter-data", @@ -72,9 +72,10 @@ version = "0.1.0" [[package]] name = "air-interpreter" -version = "0.25.0" +version = "0.26.0" dependencies = [ "air", + "air-interpreter-interface", "air-log-targets", "log", "marine-rs-sdk", @@ -165,6 +166,7 @@ version = "0.3.0" dependencies = [ "air", "air-interpreter-interface", + "avm-interface", "avm-server", "fstrings", "marine-rs-sdk", @@ -175,13 +177,14 @@ dependencies = [ [[package]] name = "air-trace" -version = "0.1.0" +version = "0.2.0" dependencies = [ "air", "air-interpreter-interface", "air-test-utils", "anyhow", - "avm-server", + "avm-data-store", + "avm-interface", "clap 3.2.16", "itertools 0.10.3", "serde", @@ -269,12 +272,29 @@ dependencies = [ ] [[package]] -name = "avm-server" -version = "0.24.0" +name = "avm-interface" +version = "0.25.0" dependencies = [ "air-interpreter-interface", "air-utils", "avm-data-store", + "log", + "maplit", + "polyplets", + "serde", + "serde_json", + "thiserror", + "tracing", +] + +[[package]] +name = "avm-server" +version = "0.25.0" +dependencies = [ + "air-interpreter-interface", + "air-utils", + "avm-data-store", + "avm-interface", "eyre", "log", "maplit", diff --git a/Cargo.toml b/Cargo.toml index 9bb9ba0a..b54e380f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "air", "air-interpreter", + "avm/interface", "avm/server", "crates/air-lib/air-parser", "crates/air-lib/execution-info-collector", diff --git a/air-interpreter/Cargo.toml b/air-interpreter/Cargo.toml index 0442104a..9cb17f05 100644 --- a/air-interpreter/Cargo.toml +++ b/air-interpreter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "air-interpreter" -version = "0.25.0" +version = "0.26.0" description = "Crate-wrapper for air" authors = ["Fluence Labs"] edition = "2018" @@ -19,6 +19,7 @@ path = "src/marine.rs" [dependencies] air = { path = "../air" } +air-interpreter-interface = { path = "../crates/air-lib/interpreter-interface" } air-log-targets = { path = "../crates/air-lib/log-targets" } marine-rs-sdk = { version = "0.7.0", features = ["logger"] } diff --git a/air/Cargo.toml b/air/Cargo.toml index d7c2e97c..8623a63d 100644 --- a/air/Cargo.toml +++ b/air/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "air" -version = "0.25.0" +version = "0.26.0" description = "Interpreter of AIR scripts intended to coordinate request flow in the Fluence network" authors = ["Fluence Labs"] edition = "2018" @@ -18,14 +18,13 @@ doctest = false air-parser = { path = "../crates/air-lib/air-parser" } air-execution-info-collector = { path = "../crates/air-lib/execution-info-collector" } air-interpreter-data = { path = "../crates/air-lib/interpreter-data" } -air-interpreter-interface = { path = "../crates/air-lib/interpreter-interface" } +air-interpreter-interface = { path = "../crates/air-lib/interpreter-interface", default-features = false } air-log-targets = { path = "../crates/air-lib/log-targets" } air-lambda-ast = { path = "../crates/air-lib/lambda/ast" } air-lambda-parser = { path = "../crates/air-lib/lambda/parser" } air-trace-handler = { path = "../crates/air-lib/trace-handler" } air-utils = { version = "0.1.0", path = "../crates/air-lib/utils" } polyplets = { path = "../crates/air-lib/polyplets" } -marine-rs-sdk = { version = "0.7.0", features = ["logger"] } serde = { version = "1.0.118", features = [ "derive", "rc" ] } serde_json = "1.0.61" @@ -47,6 +46,7 @@ wasm-bindgen = "=0.2.65" [dev_dependencies] air-test-utils = { path = "../crates/air-lib/test-utils" } fluence-app-service = "0.18.0" +marine-rs-sdk = { version = "0.7.0", features = ["logger"] } # the feature just silence a warning in the criterion 0.3.x. criterion = { version = "0.3.3", features = ["html_reports"] } diff --git a/avm/interface/Cargo.toml b/avm/interface/Cargo.toml new file mode 100644 index 00000000..5f464eff --- /dev/null +++ b/avm/interface/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "avm-interface" +description = "Fluence AIR VM interfacing" +version = "0.25.0" +authors = ["Fluence Labs"] +edition = "2018" +license = "Apache-2.0" +documentation = "https://docs.rs/avm-interface" +repository = "https://github.com/fluencelabs/aquavm/tree/master/avm/interface" +publish = true # this crate is used by the node +keywords = ["fluence", "air", "webassembly", "programming-language"] +categories = ["wasm"] + +[lib] +name = "avm_interface" +path = "src/lib.rs" + +[dependencies] +air-interpreter-interface = { version = "0.11.0", path = "../../crates/air-lib/interpreter-interface", default-features = false } +air-utils = { version = "0.1.0", path = "../../crates/air-lib/utils" } +avm-data-store = { version = "0.4.0", path = "../../crates/data-store" } +polyplets = { version = "0.3.0", path = "../../crates/air-lib/polyplets" } + +thiserror = "1.0.29" +maplit = "1.0.2" +serde_json = "1.0.61" +serde = "1.0.118" +log = "0.4.14" +tracing = "0.1.35" diff --git a/avm/server/src/interface/call_request_parameters.rs b/avm/interface/src/call_request_parameters.rs similarity index 92% rename from avm/server/src/interface/call_request_parameters.rs rename to avm/interface/src/call_request_parameters.rs index e9eea481..1add26fd 100644 --- a/avm/server/src/interface/call_request_parameters.rs +++ b/avm/interface/src/call_request_parameters.rs @@ -15,10 +15,9 @@ */ use super::JValue; -use crate::errors::CallSeDeErrors; -use crate::RunnerResult; -use crate::SecurityTetraplet; +use crate::CallSeDeErrors; +use polyplets::SecurityTetraplet; use serde::Deserialize; use serde::Serialize; @@ -60,7 +59,7 @@ impl CallRequestParams { pub(crate) fn from_raw( call_params: air_interpreter_interface::CallRequestParams, - ) -> RunnerResult { + ) -> Result { let arguments: Vec = serde_json::from_str(&call_params.arguments).map_err(|de_error| { CallSeDeErrors::CallParamsArgsDeFailed { @@ -86,7 +85,9 @@ impl CallRequestParams { } } -pub(crate) fn from_raw_call_requests(raw_call_params: Vec) -> RunnerResult { +pub(crate) fn from_raw_call_requests( + raw_call_params: Vec, +) -> Result { let call_requests: air_interpreter_interface::CallRequests = match serde_json::from_slice(&raw_call_params) { Ok(requests) => requests, @@ -101,7 +102,7 @@ pub(crate) fn from_raw_call_requests(raw_call_params: Vec) -> RunnerResult RunnerResult<_> { + .map(|(call_id, call_params)| -> Result<_, _> { let call_params = CallRequestParams::from_raw(call_params)?; Ok((call_id, call_params)) }) diff --git a/avm/server/src/interface/call_service_result.rs b/avm/interface/src/call_service_result.rs similarity index 100% rename from avm/server/src/interface/call_service_result.rs rename to avm/interface/src/call_service_result.rs diff --git a/avm/interface/src/lib.rs b/avm/interface/src/lib.rs new file mode 100644 index 00000000..d69b0dea --- /dev/null +++ b/avm/interface/src/lib.rs @@ -0,0 +1,66 @@ +/* + * Copyright 2021 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +mod call_request_parameters; +mod call_service_result; +mod outcome; +mod particle_parameters; +pub mod raw_outcome; + +use serde_json::Error as SerdeError; +use thiserror::Error as ThisError; + +#[derive(Debug, ThisError)] +#[allow(clippy::enum_variant_names)] +pub enum CallSeDeErrors { + /// Errors encountered while trying to serialize call results. + #[error("error occurred while call results `{call_results:?}` deserialization: {se_error}")] + CallResultsSeFailed { + call_results: air_interpreter_interface::CallResults, + se_error: SerdeError, + }, + + /// This error is encountered when deserialization pof call requests failed for some reason. + #[error("'{raw_call_request:?}' can't been serialized with error '{error}'")] + CallRequestsDeError { + raw_call_request: Vec, + error: SerdeError, + }, + + /// Errors encountered while trying to deserialize arguments from call parameters returned + /// by the interpreter. In the corresponding struct such arguments are Vec serialized + /// to a string. + #[error("error occurred while deserialization of arguments from call params `{call_params:?}`: {de_error}")] + CallParamsArgsDeFailed { + call_params: air_interpreter_interface::CallRequestParams, + de_error: SerdeError, + }, + + /// Errors encountered while trying to deserialize tetraplets from call parameters returned + /// by the interpreter. In the corresponding struct such tetraplets are + /// Vec> serialized to a string. + #[error("error occurred while deserialization of tetraplets from call params `{call_params:?}`: {de_error}")] + CallParamsTetrapletsDeFailed { + call_params: air_interpreter_interface::CallRequestParams, + de_error: SerdeError, + }, +} +type JValue = serde_json::Value; + +pub use call_request_parameters::*; +pub use call_service_result::*; +pub use outcome::*; +pub use particle_parameters::*; diff --git a/avm/server/src/interface/outcome.rs b/avm/interface/src/outcome.rs similarity index 89% rename from avm/server/src/interface/outcome.rs rename to avm/interface/src/outcome.rs index 33fdcfd3..fda01e4b 100644 --- a/avm/server/src/interface/outcome.rs +++ b/avm/interface/src/outcome.rs @@ -15,9 +15,7 @@ */ use super::CallRequests; -use crate::avm_runner::RawAVMOutcome; -use crate::AVMError; -use crate::AVMResult; +use crate::raw_outcome::RawAVMOutcome; use serde::Deserialize; use serde::Serialize; @@ -68,11 +66,11 @@ impl AVMOutcome { } } - pub(crate) fn from_raw_outcome( + pub fn from_raw_outcome( raw_outcome: RawAVMOutcome, memory_delta: usize, execution_time: Duration, - ) -> AVMResult { + ) -> Result { use air_interpreter_interface::INTERPRETER_SUCCESS; let RawAVMOutcome { @@ -92,11 +90,10 @@ impl AVMOutcome { ); if ret_code == INTERPRETER_SUCCESS { - return Ok(avm_outcome); + Ok(avm_outcome) + } else { + Err(ErrorAVMOutcome::new(ret_code, error_message, avm_outcome)) } - - let error_outcome = ErrorAVMOutcome::new(ret_code, error_message, avm_outcome); - Err(AVMError::InterpreterFailed(error_outcome)) } } diff --git a/avm/server/src/interface/particle_parameters.rs b/avm/interface/src/particle_parameters.rs similarity index 100% rename from avm/server/src/interface/particle_parameters.rs rename to avm/interface/src/particle_parameters.rs diff --git a/avm/server/src/interface/raw_outcome.rs b/avm/interface/src/raw_outcome.rs similarity index 91% rename from avm/server/src/interface/raw_outcome.rs rename to avm/interface/src/raw_outcome.rs index 4c708732..2377dfc1 100644 --- a/avm/server/src/interface/raw_outcome.rs +++ b/avm/interface/src/raw_outcome.rs @@ -14,8 +14,9 @@ * limitations under the License. */ +use crate::CallSeDeErrors; + use super::CallRequests; -use crate::RunnerResult; use air_interpreter_interface::InterpreterOutcome; @@ -33,7 +34,7 @@ pub struct RawAVMOutcome { } impl RawAVMOutcome { - pub fn from_interpreter_outcome(outcome: InterpreterOutcome) -> RunnerResult { + pub fn from_interpreter_outcome(outcome: InterpreterOutcome) -> Result { let InterpreterOutcome { ret_code, error_message, @@ -42,7 +43,7 @@ impl RawAVMOutcome { next_peer_pks, } = outcome; - let call_requests = crate::interface::from_raw_call_requests(call_requests)?; + let call_requests = crate::from_raw_call_requests(call_requests)?; let raw_avm_outcome = Self { ret_code, diff --git a/avm/server/Cargo.toml b/avm/server/Cargo.toml index 40aa98ed..dd2e6511 100644 --- a/avm/server/Cargo.toml +++ b/avm/server/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "avm-server" description = "Fluence AIR VM" -version = "0.24.0" +version = "0.25.0" authors = ["Fluence Labs"] edition = "2018" license = "Apache-2.0" @@ -21,6 +21,7 @@ air-utils = { version = "0.1.0", path = "../../crates/air-lib/utils" } avm-data-store = { version = "0.4.0", path = "../../crates/data-store" } marine-runtime = "0.18.0" polyplets = { version = "0.3.0", path = "../../crates/air-lib/polyplets" } +avm-interface = { version = "0.25.0", path = "../../avm/interface" } eyre = "0.6.5" thiserror = "1.0.29" diff --git a/avm/server/src/avm.rs b/avm/server/src/avm.rs index 9524b5d8..32b9c70e 100644 --- a/avm/server/src/avm.rs +++ b/avm/server/src/avm.rs @@ -18,14 +18,15 @@ use super::avm_runner::AVMRunner; use super::AVMDataStore; use super::AVMError; use super::AVMMemoryStats; -use super::AVMOutcome; -use super::CallResults; use crate::config::AVMConfig; -use crate::interface::raw_outcome::RawAVMOutcome; -use crate::interface::ParticleParameters; use crate::AVMResult; use avm_data_store::AnomalyData; +use avm_interface::raw_outcome::RawAVMOutcome; +use avm_interface::AVMOutcome; +use avm_interface::CallResults; +use avm_interface::ParticleParameters; + use std::ops::Deref; use std::ops::DerefMut; use std::time::Duration; @@ -118,7 +119,8 @@ impl AVM { // persist resulted data self.data_store.store_data(&outcome.data, particle_id)?; - let outcome = AVMOutcome::from_raw_outcome(outcome, memory_delta, execution_time)?; + let outcome = AVMOutcome::from_raw_outcome(outcome, memory_delta, execution_time) + .map_err(AVMError::InterpreterFailed)?; Ok(outcome) } diff --git a/avm/server/src/errors.rs b/avm/server/src/errors.rs index cca4e352..cd2e211f 100644 --- a/avm/server/src/errors.rs +++ b/avm/server/src/errors.rs @@ -14,7 +14,8 @@ * limitations under the License. */ -use crate::interface::ErrorAVMOutcome; +pub use avm_interface::CallSeDeErrors; +use avm_interface::ErrorAVMOutcome; use marine::IValue; use marine::MarineError; @@ -72,39 +73,3 @@ pub enum RunnerError { #[error(transparent)] CallSeDeErrors(#[from] CallSeDeErrors), } - -#[derive(Debug, ThisError)] -#[allow(clippy::enum_variant_names)] -pub enum CallSeDeErrors { - /// Errors encountered while trying to serialize call results. - #[error("error occurred while call results `{call_results:?}` deserialization: {se_error}")] - CallResultsSeFailed { - call_results: air_interpreter_interface::CallResults, - se_error: SerdeError, - }, - - /// This error is encountered when deserialization pof call requests failed for some reason. - #[error("'{raw_call_request:?}' can't been serialized with error '{error}'")] - CallRequestsDeError { - raw_call_request: Vec, - error: SerdeError, - }, - - /// Errors encountered while trying to deserialize arguments from call parameters returned - /// by the interpreter. In the corresponding struct such arguments are Vec serialized - /// to a string. - #[error("error occurred while deserialization of arguments from call params `{call_params:?}`: {de_error}")] - CallParamsArgsDeFailed { - call_params: air_interpreter_interface::CallRequestParams, - de_error: SerdeError, - }, - - /// Errors encountered while trying to deserialize tetraplets from call parameters returned - /// by the interpreter. In the corresponding struct such tetraplets are - /// Vec> serialized to a string. - #[error("error occurred while deserialization of tetraplets from call params `{call_params:?}`: {de_error}")] - CallParamsTetrapletsDeFailed { - call_params: air_interpreter_interface::CallRequestParams, - de_error: SerdeError, - }, -} diff --git a/avm/server/src/interface/mod.rs b/avm/server/src/interface/mod.rs deleted file mode 100644 index d5bc4506..00000000 --- a/avm/server/src/interface/mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2021 Fluence Labs Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -mod call_request_parameters; -mod call_service_result; -mod outcome; -mod particle_parameters; -pub mod raw_outcome; - -type JValue = serde_json::Value; - -pub use call_request_parameters::*; -pub use call_service_result::*; -pub use outcome::*; -pub use particle_parameters::*; diff --git a/avm/server/src/lib.rs b/avm/server/src/lib.rs index 157f691a..4a0b3ce3 100644 --- a/avm/server/src/lib.rs +++ b/avm/server/src/lib.rs @@ -27,18 +27,18 @@ mod avm; mod config; mod errors; -mod interface; mod runner; pub use avm::AVM; pub use config::AVMConfig; pub use errors::AVMError; -pub use interface::*; pub use runner::AVMMemoryStats; +pub use avm_interface::*; + pub mod avm_runner { - pub use crate::interface::raw_outcome::RawAVMOutcome; pub use crate::runner::AVMRunner; + pub use avm_interface::raw_outcome::RawAVMOutcome; } // Re-exports diff --git a/avm/server/src/runner.rs b/avm/server/src/runner.rs index 384669f9..3f2d8e7b 100644 --- a/avm/server/src/runner.rs +++ b/avm/server/src/runner.rs @@ -14,13 +14,13 @@ * limitations under the License. */ -use super::CallResults; -use crate::raw_outcome::RawAVMOutcome; use crate::RunnerError; use crate::RunnerResult; use air_interpreter_interface::InterpreterOutcome; use air_utils::measure; +use avm_interface::raw_outcome::RawAVMOutcome; +use avm_interface::CallResults; use marine::IValue; use marine::Marine; use marine::MarineConfig; @@ -192,7 +192,7 @@ fn prepare_args( ) .into_ivalue(); - let call_results = crate::interface::into_raw_result(call_results); + let call_results = avm_interface::into_raw_result(call_results); let call_results = measure!( serde_json::to_vec(&call_results).expect("the default serializer shouldn't fail"), tracing::Level::INFO, diff --git a/crates/air-lib/interpreter-interface/Cargo.toml b/crates/air-lib/interpreter-interface/Cargo.toml index 5de3d903..a1316ce4 100644 --- a/crates/air-lib/interpreter-interface/Cargo.toml +++ b/crates/air-lib/interpreter-interface/Cargo.toml @@ -16,8 +16,12 @@ name = "air_interpreter_interface" path = "src/lib.rs" [dependencies] -marine-rs-sdk = "0.7.0" -fluence-it-types = "0.3.0" +marine-rs-sdk = { version = "0.7.0", optional = true } +fluence-it-types = { version = "0.3.0", optional = true } serde = "1.0.118" serde_json = "1.0.56" + +[features] +default = ["marine"] +marine = ["marine-rs-sdk", "fluence-it-types"] diff --git a/crates/air-lib/interpreter-interface/src/call_request_parameters.rs b/crates/air-lib/interpreter-interface/src/call_request_parameters.rs index 86a9f17b..1aee2f38 100644 --- a/crates/air-lib/interpreter-interface/src/call_request_parameters.rs +++ b/crates/air-lib/interpreter-interface/src/call_request_parameters.rs @@ -14,6 +14,7 @@ * limitations under the License. */ +#[cfg(feature = "marine")] use marine_rs_sdk::marine; use serde::Deserialize; use serde::Serialize; @@ -23,7 +24,7 @@ pub type CallRequests = HashMap; /// Contains arguments of a call instruction and all other necessary information /// required for calling a service. -#[marine] +#[cfg_attr(feature = "marine", marine)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CallRequestParams { /// Id of a service that should be called. diff --git a/crates/air-lib/interpreter-interface/src/interpreter_outcome.rs b/crates/air-lib/interpreter-interface/src/interpreter_outcome.rs index 2b755d2a..ab9e9746 100644 --- a/crates/air-lib/interpreter-interface/src/interpreter_outcome.rs +++ b/crates/air-lib/interpreter-interface/src/interpreter_outcome.rs @@ -14,8 +14,10 @@ * limitations under the License. */ +#[cfg(feature = "marine")] use marine_rs_sdk::marine; +#[cfg(feature = "marine")] use fluence_it_types::IValue; use serde::Deserialize; use serde::Serialize; @@ -23,7 +25,7 @@ use serde::Serialize; pub const INTERPRETER_SUCCESS: i64 = 0; /// Describes a result returned at the end of the interpreter execution_step. -#[marine] +#[cfg_attr(feature = "marine", marine)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct InterpreterOutcome { /// A return code, where INTERPRETER_SUCCESS means success. @@ -43,6 +45,7 @@ pub struct InterpreterOutcome { pub call_requests: Vec, } +#[cfg(feature = "marine")] impl InterpreterOutcome { pub fn from_ivalue(ivalue: IValue) -> Result { const OUTCOME_FIELDS_COUNT: usize = 5; @@ -73,8 +76,10 @@ impl InterpreterOutcome { } } +#[cfg(feature = "marine")] use fluence_it_types::ne_vec::NEVec; +#[cfg(feature = "marine")] fn try_as_record(ivalue: IValue) -> Result, String> { match ivalue { IValue::Record(record_values) => Ok(record_values), @@ -85,6 +90,7 @@ fn try_as_record(ivalue: IValue) -> Result, String> { } } +#[cfg(feature = "marine")] fn try_as_i64(ivalue: IValue, field_name: &str) -> Result { match ivalue { IValue::S64(value) => Ok(value), @@ -92,6 +98,7 @@ fn try_as_i64(ivalue: IValue, field_name: &str) -> Result { } } +#[cfg(feature = "marine")] fn try_as_string(ivalue: IValue, field_name: &str) -> Result { match ivalue { IValue::String(value) => Ok(value), @@ -99,6 +106,7 @@ fn try_as_string(ivalue: IValue, field_name: &str) -> Result { } } +#[cfg(feature = "marine")] fn try_as_byte_vec(ivalue: IValue, field_name: &str) -> Result, String> { let byte_vec = match ivalue { IValue::Array(array) => { @@ -123,6 +131,7 @@ fn try_as_byte_vec(ivalue: IValue, field_name: &str) -> Result, String> Ok(byte_vec) } +#[cfg(feature = "marine")] fn try_as_string_vec(ivalue: IValue, field_name: &str) -> Result, String> { match ivalue { IValue::Array(ar_values) => { diff --git a/crates/air-lib/interpreter-interface/src/run_parameters.rs b/crates/air-lib/interpreter-interface/src/run_parameters.rs index d49852e9..51ae9abf 100644 --- a/crates/air-lib/interpreter-interface/src/run_parameters.rs +++ b/crates/air-lib/interpreter-interface/src/run_parameters.rs @@ -14,14 +14,17 @@ * limitations under the License. */ +#[cfg(feature = "marine")] use fluence_it_types::ne_vec::NEVec; +#[cfg(feature = "marine")] use fluence_it_types::IValue; +#[cfg(feature = "marine")] use marine_rs_sdk::marine; use serde::Deserialize; use serde::Serialize; /// Parameters that a host side should pass to an interpreter and that necessary for execution. -#[marine] +#[cfg_attr(feature = "marine", marine)] #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] pub struct RunParameters { /// Peer id of a peer that start this particle. @@ -48,6 +51,7 @@ impl RunParameters { } } + #[cfg(feature = "marine")] pub fn into_ivalue(self) -> IValue { let run_parameters = vec![ IValue::String(self.init_peer_id), diff --git a/crates/air-lib/test-utils/Cargo.toml b/crates/air-lib/test-utils/Cargo.toml index 018396e8..f1b6be92 100644 --- a/crates/air-lib/test-utils/Cargo.toml +++ b/crates/air-lib/test-utils/Cargo.toml @@ -16,6 +16,7 @@ path = "src/lib.rs" [dependencies] air = { path = "../../../air" } air-interpreter-interface = { path = "../interpreter-interface" } +avm-interface = { path = "../../../avm/interface" } avm-server = { path = "../../../avm/server" } marine-rs-sdk = "0.7.0" diff --git a/crates/air-lib/test-utils/src/lib.rs b/crates/air-lib/test-utils/src/lib.rs index 99d0c7e7..db6a85ee 100644 --- a/crates/air-lib/test-utils/src/lib.rs +++ b/crates/air-lib/test-utils/src/lib.rs @@ -35,7 +35,7 @@ mod native_test_runner; mod wasm_test_runner; pub use air::interpreter_data::*; -pub use avm_server::raw_outcome::*; +pub use avm_interface::raw_outcome::*; pub use avm_server::*; pub mod prelude { diff --git a/tools/cli/air-trace/Cargo.toml b/tools/cli/air-trace/Cargo.toml index 2eeaafe3..ce777aca 100644 --- a/tools/cli/air-trace/Cargo.toml +++ b/tools/cli/air-trace/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "air-trace" -version = "0.1.0" +version = "0.2.0" edition = "2021" description = "AIR performance tracing tool" authors = ["Fluence Labs"] @@ -10,9 +10,10 @@ keywords = ["fluence", "air", "tracing"] [dependencies] air = { path = "../../../air" } -air-test-utils = { path = "../../../crates/air-lib/test-utils" } -air-interpreter-interface = { path = "../../../crates/air-lib/interpreter-interface" } -avm-server = { path = "../../../avm/server" } +air-test-utils = { path = "../../../crates/air-lib/test-utils", optional = true } +air-interpreter-interface = { path = "../../../crates/air-lib/interpreter-interface", default-features = false } +avm-data-store = { path = "../../../crates/data-store" } +avm-interface = { path = "../../../avm/interface" } anyhow = "1.0.56" clap = { version = "3.1.18", features = ["derive", "env"] } @@ -23,4 +24,4 @@ tracing-subscriber = { version = "0.3.11", default-features = false, features = [features] default = ["wasm"] -wasm = [] +wasm = ["air-test-utils"] diff --git a/tools/cli/air-trace/README.md b/tools/cli/air-trace/README.md index aa53ae59..31dcb862 100644 --- a/tools/cli/air-trace/README.md +++ b/tools/cli/air-trace/README.md @@ -47,7 +47,6 @@ Please, note that currently tracing outputs to stdout, and execution result is a ## Known limitations 1. At detailed tracing levels (debug etc), trace formatting time is comparable to traced code execution time and can give incorrect results. -2. Native builds of the utility still depend on Marine, and cannot be built for architectures unsupported by Marine, like Apple Silicon or WASM. It is yet to be resolved with some refactoring. ## Installation @@ -68,3 +67,14 @@ You need to have Rust toolchain and its `cargo` utility installed. Run this com ``` sh cargo install --path tools/cli/air-trace ``` + +## `air-trace` native build + +You can have fully native or WASM `air-trace` build with the following commands: + +``` sh +cargo build --no-default-features --release -p air-trace +cargo build --no-default-features --release -p air-trace --target wasm32-wasi +``` + +This build doesn't need the AIR interpreter server binary. diff --git a/tools/cli/air-trace/src/run.rs b/tools/cli/air-trace/src/run.rs index e5f8fdc6..d93fca77 100644 --- a/tools/cli/air-trace/src/run.rs +++ b/tools/cli/air-trace/src/run.rs @@ -21,7 +21,7 @@ mod runner; mod wasm; use self::runner::AirRunner; -use air_test_utils::CallResults; +use avm_interface::CallResults; use anyhow::Context as _; use clap::{Parser, Subcommand}; @@ -71,12 +71,15 @@ enum Source { pub(crate) fn run(args: Args) -> anyhow::Result<()> { let tracing_json = (!args.json) as u8; + #[cfg(feature = "wasm")] let global_tracing_params = if args.native { // for native, there is single tracing configuration, and no runner args.tracing_params.clone() } else { args.runner_tracing_params }; + #[cfg(not(feature = "wasm"))] + let global_tracing_params = args.tracing_params.clone(); init_tracing(global_tracing_params, tracing_json); let current_peer_id = args.current_peer_id.as_deref().unwrap_or("some_id"); diff --git a/tools/cli/air-trace/src/run/data/anomaly.rs b/tools/cli/air-trace/src/run/data/anomaly.rs index ef22d9d6..bb8a6597 100644 --- a/tools/cli/air-trace/src/run/data/anomaly.rs +++ b/tools/cli/air-trace/src/run/data/anomaly.rs @@ -16,8 +16,8 @@ use super::ExecutionData; use crate::run::load_data; -use air_test_utils::ParticleParameters; -use avm_server::AnomalyData; +use avm_data_store::AnomalyData; +use avm_interface::ParticleParameters; use anyhow::Context; use clap::Parser; diff --git a/tools/cli/air-trace/src/run/data/mod.rs b/tools/cli/air-trace/src/run/data/mod.rs index 589bd3eb..34e20094 100644 --- a/tools/cli/air-trace/src/run/data/mod.rs +++ b/tools/cli/air-trace/src/run/data/mod.rs @@ -17,7 +17,7 @@ pub(crate) mod anomaly; pub(crate) mod plain; -use avm_server::ParticleParameters; +use avm_interface::ParticleParameters; pub(crate) struct ExecutionData<'ctx> { pub(crate) air_script: String, diff --git a/tools/cli/air-trace/src/run/data/plain.rs b/tools/cli/air-trace/src/run/data/plain.rs index 27cb4b69..d50ebce6 100644 --- a/tools/cli/air-trace/src/run/data/plain.rs +++ b/tools/cli/air-trace/src/run/data/plain.rs @@ -16,7 +16,7 @@ use super::ExecutionData; use crate::utils::unix_timestamp_now; -use air_test_utils::ParticleParameters; +use avm_interface::ParticleParameters; use anyhow::Context; diff --git a/tools/cli/air-trace/src/run/native.rs b/tools/cli/air-trace/src/run/native.rs index 06dfcd3b..6b72e85f 100644 --- a/tools/cli/air-trace/src/run/native.rs +++ b/tools/cli/air-trace/src/run/native.rs @@ -16,6 +16,7 @@ use super::runner::AirRunner; use air_interpreter_interface::RunParameters; +use avm_interface::raw_outcome::RawAVMOutcome; struct NativeAvmRunner { current_peer_id: String, @@ -30,12 +31,12 @@ impl AirRunner for NativeAvmRunner { init_peer_id: String, timestamp: u64, ttl: u32, - call_results: air_test_utils::CallResults, + call_results: avm_interface::CallResults, // We use externally configured logger. _tracing_params: String, _tracing_output_mode: u8, - ) -> anyhow::Result { - use air_test_utils::into_raw_result; + ) -> anyhow::Result { + use avm_interface::into_raw_result; // some inner parts transformations let raw_call_results = into_raw_result(call_results); @@ -53,7 +54,7 @@ impl AirRunner for NativeAvmRunner { }, raw_call_results, ); - let outcome = air_test_utils::RawAVMOutcome::from_interpreter_outcome(outcome)?; + let outcome = RawAVMOutcome::from_interpreter_outcome(outcome)?; Ok(outcome) } diff --git a/tools/cli/air-trace/src/run/runner.rs b/tools/cli/air-trace/src/run/runner.rs index 30f72191..04e7ab66 100644 --- a/tools/cli/air-trace/src/run/runner.rs +++ b/tools/cli/air-trace/src/run/runner.rs @@ -14,8 +14,8 @@ * limitations under the License. */ -use avm_server::avm_runner::*; -use avm_server::CallResults; +use avm_interface::raw_outcome::RawAVMOutcome; +use avm_interface::CallResults; pub(crate) trait AirRunner { #[allow(clippy::too_many_arguments)] diff --git a/tools/cli/air-trace/src/run/wasm.rs b/tools/cli/air-trace/src/run/wasm.rs index a8c6647d..46d4148b 100644 --- a/tools/cli/air-trace/src/run/wasm.rs +++ b/tools/cli/air-trace/src/run/wasm.rs @@ -14,7 +14,7 @@ * limitations under the License. */ use super::runner::AirRunner; -use avm_server::avm_runner::AVMRunner; +use air_test_utils::avm_runner::AVMRunner; use std::path::Path; pub(crate) struct WasmAvmRunner(AVMRunner); @@ -28,10 +28,10 @@ impl AirRunner for WasmAvmRunner { init_peer_id: String, timestamp: u64, ttl: u32, - call_results: avm_server::CallResults, + call_results: avm_interface::CallResults, tracing_params: String, tracing_output_mode: u8, - ) -> anyhow::Result { + ) -> anyhow::Result { Ok(self.0.call_tracing( air, prev_data,