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 Jan 10, 2024
1 parent 4beb873 commit c09ebae
Show file tree
Hide file tree
Showing 7 changed files with 373 additions and 136 deletions.
Binary file modified configs/peer/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 @@ -16,17 +16,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, Engine, Linker, Module, Store, StoreLimits, StoreLimitsBuilder, TypedFunc,
};
Expand Down Expand Up @@ -76,7 +74,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 @@ -245,6 +243,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 @@ -1754,12 +1757,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
7 changes: 5 additions & 2 deletions data_model/src/isi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub mod model {
/// Note that [`InstructionBox`] is not a self-sufficient instruction,
/// but just a wrapper to pass instructions back and forth.
/// If you are a client SDK user then you likely don't need to use this type directly.
///
/// The order of [`Self`] variants is guaranteed to correspond to the order of [`InstructionType`] variants
#[derive(
DebugCustom,
Display,
Expand Down Expand Up @@ -1690,15 +1692,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 @@ -1964,6 +1966,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 c09ebae

Please sign in to comment.