Skip to content

Commit

Permalink
[fix] #4082: Remove cloning for query execution in wasm
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic committed Feb 20, 2024
1 parent 6c5d379 commit fbf7c06
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 322 deletions.
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
29 changes: 17 additions & 12 deletions core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ use iroha_data_model::{
isi::InstructionBox,
permission::PermissionTokenSchema,
prelude::*,
query::{QueryBox, QueryId, QueryRequest, QueryWithParameters},
smart_contract::{
payloads::{self, Validate},
SmartContractQueryRequest,
},
query::{QueryBox, QueryRequest, QueryWithParameters},
smart_contract::payloads::{self, Validate},
BatchedResponse, Level as LogLevel, ValidationFail,
};
use iroha_logger::debug;
// NOTE: Using error_span so that span info is logged on every event
use iroha_logger::{error_span as wasm_log_span, prelude::tracing::Span};
use iroha_wasm_codec::{self as codec, WasmUsize};
use parity_scale_codec::Decode;
use wasmtime::{
Caller, Config as WasmtimeConfig, Engine, Linker, Module, Store, StoreLimits,
StoreLimitsBuilder, TypedFunc,
Expand Down Expand Up @@ -74,7 +72,7 @@ mod import {

use super::super::*;

pub trait ExecuteOperations<S> {
pub(crate) trait ExecuteOperations<S> {
/// Execute `query` on host
#[codec::wrap_trait_fn]
fn execute_query(
Expand Down Expand Up @@ -243,6 +241,11 @@ pub mod error {
/// [`Result`] type for this module
pub type Result<T, E = Error> = core::result::Result<T, E>;

#[cfg_attr(test, derive(parity_scale_codec::Encode))]
#[derive(Debug, derive_more::Display, Decode)]
#[repr(transparent)]
pub(crate) struct SmartContractQueryRequest(pub QueryRequest<QueryBox>);

/// Create [`Module`] from bytes.
///
/// # Errors
Expand Down Expand Up @@ -1748,12 +1751,14 @@ mod tests {
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::test().start();
let mut wsv = WorldStateView::new(world_with_test_account(&authority), kura, query_handle);
let query_hex = encode_hex(SmartContractQueryRequest::query(
QueryBox::from(FindAccountById::new(authority.clone())),
Sorting::default(),
Pagination::default(),
FetchSize::default(),
));
let query_hex = encode_hex(SmartContractQueryRequest(QueryRequest::Query(
QueryWithParameters::new(
FindAccountById::new(authority.clone()).into(),
Sorting::default(),
Pagination::default(),
FetchSize::default(),
),
)));

let wat = format!(
r#"
Expand Down
2 changes: 1 addition & 1 deletion data_model/derive/src/enum_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl ToTokens for EnumRef {

quote! {
#attrs
pub(super) enum #ident<'a> #impl_generics #where_clause {
pub(crate) enum #ident<'a> #impl_generics #where_clause {
#(#variants),*
}
}
Expand Down
18 changes: 9 additions & 9 deletions data_model/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ use proc_macro2::TokenStream;
///
/// # Example
///
/// ```rust
/// ```
/// use iroha_data_model_derive::EnumRef;
/// use parity_scale_codec::Encode;
///
/// #[derive(EnumRef)]
/// enum InnerEnum {
/// #[enum_ref(derive(Encode))]
/// pub enum InnerEnum {
/// A(u32),
/// B(i32)
/// }
///
/// #[derive(EnumRef)]
/// #[enum_ref(derive(Encode))]
/// enum OuterEnum {
/// pub enum OuterEnum {
/// A(String),
/// #[enum_ref(transparent)]
/// B(InnerEnum),
/// }
///
/// /* will produce:
///
/// enum InnerEnumRef<'a> {
/// pub(crate) enum InnerEnumRef<'a> {
/// A(&'a u32),
/// B(&'a i32),
/// }
///
/// enum OuterEnumRef<'a> {
/// pub(crate) enum OuterEnumRef<'a> {
/// A(&'a String),
/// B(InnerEnumRef<'a>),
/// }
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn enum_ref(input: TokenStream) -> Result<TokenStream> {
///
/// # Example
///
/// ```rust
/// ```
/// use iroha_data_model_derive::model;
///
/// #[model]
Expand Down Expand Up @@ -170,7 +170,7 @@ pub fn model_single(input: TokenStream) -> TokenStream {
///
/// The common use-case:
///
/// ```rust
/// ```
/// use iroha_data_model_derive::IdEqOrdHash;
/// use iroha_data_model::{Identifiable, IdBox};
///
Expand Down Expand Up @@ -230,7 +230,7 @@ pub fn model_single(input: TokenStream) -> TokenStream {
///
/// Manual selection of the identifier field:
///
/// ```rust
/// ```
/// use iroha_data_model_derive::IdEqOrdHash;
/// use iroha_data_model::{Identifiable, IdBox};
///
Expand Down
5 changes: 3 additions & 2 deletions data_model/src/isi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,15 +1359,15 @@ pub mod error {
asset::AssetValueType,
metadata,
query::error::{FindError, QueryExecutionFail},
IdBox, Value,
IdBox,
};

#[model]
pub mod model {
use serde::{Deserialize, Serialize};

use super::*;
use crate::asset::AssetDefinitionId;
use crate::{asset::AssetDefinitionId, Value};

/// Instruction execution error type
#[derive(
Expand Down Expand Up @@ -1633,6 +1633,7 @@ pub mod error {
Self::Evaluate(InstructionEvaluationError::Type(err))
}
}

impl From<FixedPointOperationError> for MathError {
fn from(err: FixedPointOperationError) -> Self {
match err {
Expand Down
Loading

0 comments on commit fbf7c06

Please sign in to comment.