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 4, 2024
1 parent cf65d44 commit 328b46c
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 134 deletions.
Binary file modified configs/peer/executor.wasm
Binary file not shown.
34 changes: 22 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,10 @@ pub mod error {
/// [`Result`] type for this module
pub type Result<T, E = Error> = core::result::Result<T, E>;

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

/// Create [`Module`] from bytes.
///
/// # Errors
Expand Down Expand Up @@ -1652,6 +1654,14 @@ mod tests {
World,
};

#[derive(Encode)]
struct QueryRequest<'a, Q> {
query: &'a Q,
sorting: Sorting,
pagination: Pagination,
fetch_size: FetchSize,
}

fn world_with_test_account(authority: &AccountId) -> World {
let domain_id = authority.domain_id.clone();
let (public_key, _) = KeyPair::generate().unwrap().into();
Expand Down Expand Up @@ -1754,12 +1764,12 @@ 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(QueryRequest {
query: &FindAccountById::new(authority.clone()),
sorting: Sorting::default(),
pagination: Pagination::default(),
fetch_size: FetchSize::default(),
});

let wat = format!(
r#"
Expand Down
Loading

0 comments on commit 328b46c

Please sign in to comment.