Skip to content

Commit

Permalink
[fix] #4082: Remove cloning for ISI and query execution in wasm (#4182)
Browse files Browse the repository at this point in the history
* [fix] #4082: Remove cloning for ISI execution in wasm
* [fix] #4082: Remove cloning for query execution in wasm

Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic committed Feb 28, 2024
1 parent fe2b301 commit fd09f10
Show file tree
Hide file tree
Showing 27 changed files with 838 additions and 539 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Executor {
})?;

if let Ok(can_unregister_domain_token) =
iroha_executor::default::tokens::domain::CanUnregisterDomain::try_from(token)
iroha_executor::default::tokens::domain::CanUnregisterDomain::try_from(&token)
{
found_accounts.push((account, can_unregister_domain_token.domain_id));
break;
Expand Down
6 changes: 3 additions & 3 deletions client_cli/pytests/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""

from .conftest import (
GIVEN_127_lenght_name,
GIVEN_128_lenght_name,
GIVEN_129_lenght_name,
GIVEN_127_length_name,
GIVEN_128_length_name,
GIVEN_129_length_name,
GIVEN_big_quantity_value_type,
GIVEN_currently_account_quantity_with_two_quantity_of_asset,
GIVEN_currently_authorized_account,
Expand Down
4 changes: 2 additions & 2 deletions client_cli/pytests/test/accounts/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from test import (
GIVEN_127_lenght_name,
GIVEN_129_lenght_name,
GIVEN_127_length_name,
GIVEN_129_length_name,
GIVEN_fake_name,
GIVEN_key_with_invalid_character_in_key,
GIVEN_not_existing_name,
Expand Down
12 changes: 6 additions & 6 deletions client_cli/pytests/test/accounts/test_register_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ def test_register_account_with_invalid_character_in_key(

@allure.label("sdk_test_id", "register_account_with_max_name")
def test_register_account_with_max_name(
GIVEN_127_lenght_name, GIVEN_registered_domain, GIVEN_public_key
GIVEN_127_length_name, GIVEN_registered_domain, GIVEN_public_key
):
with allure.step("WHEN client_cli register an account with the 127 lenght name"):
with allure.step("WHEN client_cli register an account with the 127 length name"):
client_cli.register().account(
account=GIVEN_127_lenght_name,
account=GIVEN_127_length_name,
domain=GIVEN_registered_domain.name,
key=GIVEN_public_key,
)
registered = GIVEN_127_lenght_name + "@" + GIVEN_registered_domain.name
registered = GIVEN_127_length_name + "@" + GIVEN_registered_domain.name
with allure.step(f'THEN Iroha should have the "{registered}" account'):
iroha.should(have.account(registered))

Expand All @@ -129,13 +129,13 @@ def test_register_account_with_special_characters(

@allure.label("sdk_test_id", "register_account_with_long_account_name")
def test_register_account_with_long_account_name(
GIVEN_registered_domain, GIVEN_129_lenght_name, GIVEN_public_key
GIVEN_registered_domain, GIVEN_129_length_name, GIVEN_public_key
):
with allure.step(
"WHEN client_cli tries to register an account with a name with 129 characters"
):
client_cli.register().account(
account=GIVEN_129_lenght_name,
account=GIVEN_129_length_name,
domain=GIVEN_registered_domain.name,
key=GIVEN_public_key,
)
Expand Down
2 changes: 1 addition & 1 deletion client_cli/pytests/test/assets/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from test import (
GIVEN_129_lenght_name,
GIVEN_129_length_name,
GIVEN_big_quantity_value_type,
GIVEN_currently_account_quantity_with_two_quantity_of_asset,
GIVEN_currently_authorized_account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ def test_register_asset_definition_with_quantity_value_type(

@allure.label("sdk_test_id", "register_asset_definition_with_too_long_name")
def test_register_asset_definition_with_too_long_name(
GIVEN_129_lenght_name, GIVEN_registered_domain, GIVEN_quantity_value_type
GIVEN_129_length_name, GIVEN_registered_domain, GIVEN_quantity_value_type
):
with allure.step(
f'WHEN client_cli registers the asset_definition "{GIVEN_129_lenght_name}" '
f'WHEN client_cli registers the asset_definition "{GIVEN_129_length_name}" '
f'with "{GIVEN_quantity_value_type}" value type'
f'in the "{GIVEN_registered_domain.name}" domain'
):
client_cli.register().asset().definition(
asset=GIVEN_129_lenght_name,
asset=GIVEN_129_length_name,
domain=GIVEN_registered_domain.name,
value_type=GIVEN_quantity_value_type,
)
with allure.step(f'THEN Iroha should have the asset "{GIVEN_129_lenght_name}"'):
with allure.step(f'THEN Iroha should have the asset "{GIVEN_129_length_name}"'):
client_cli.should(have.error(Stderr.TOO_LONG.value))


Expand Down
6 changes: 3 additions & 3 deletions client_cli/pytests/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,21 @@ def GIVEN_quantity_value():


@pytest.fixture()
def GIVEN_128_lenght_name():
def GIVEN_128_length_name():
ident = generate_random_string_without_reserved_chars(128)
with allure.step(f'GIVEN a name with 128 length "{ident}"'):
return ident


@pytest.fixture()
def GIVEN_129_lenght_name():
def GIVEN_129_length_name():
ident = generate_random_string_without_reserved_chars(129)
with allure.step(f'GIVEN a name with 129 length "{ident}"'):
return ident


@pytest.fixture()
def GIVEN_127_lenght_name():
def GIVEN_127_length_name():
ident = generate_random_string_without_reserved_chars(127)
with allure.step(f'GIVEN a name with 127 length "{ident}"'):
return ident
Expand Down
4 changes: 2 additions & 2 deletions client_cli/pytests/test/domains/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from test import (
GIVEN_128_lenght_name,
GIVEN_129_lenght_name,
GIVEN_128_length_name,
GIVEN_129_length_name,
GIVEN_currently_authorized_account,
GIVEN_fake_name,
GIVEN_public_key,
Expand Down
18 changes: 9 additions & 9 deletions client_cli/pytests/test/domains/test_register_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,24 @@ def test_register_one_letter_domain(GIVEN_random_character):
iroha.should(have.domain(GIVEN_random_character))


@allure.label("sdk_test_id", "register_max_lenght_domain")
def test_register_max_lenght_domain(GIVEN_128_lenght_name):
@allure.label("sdk_test_id", "register_max_length_domain")
def test_register_max_length_domain(GIVEN_128_length_name):
with allure.step(
f'WHEN client_cli registers the longest domain "{GIVEN_128_lenght_name}"'
f'WHEN client_cli registers the longest domain "{GIVEN_128_length_name}"'
):
client_cli.register().domain(GIVEN_128_lenght_name)
client_cli.register().domain(GIVEN_128_length_name)
with allure.step(
f'THEN Iroha should have the longest domain "{GIVEN_128_lenght_name}"'
f'THEN Iroha should have the longest domain "{GIVEN_128_length_name}"'
):
iroha.should(have.domain(GIVEN_128_lenght_name))
iroha.should(have.domain(GIVEN_128_length_name))


@allure.label("sdk_test_id", "register_domain_with_too_long_name")
def test_register_domain_with_too_long_name(GIVEN_129_lenght_name):
def test_register_domain_with_too_long_name(GIVEN_129_length_name):
with allure.step(
f'WHEN client_cli registers the domain "{GIVEN_129_lenght_name}" with too long name'
f'WHEN client_cli registers the domain "{GIVEN_129_length_name}" with too long name'
):
client_cli.register().domain(GIVEN_129_lenght_name)
client_cli.register().domain(GIVEN_129_length_name)
with allure.step(
f'THEN client_cli should have the too long domain error: "{Stderr.TOO_LONG}"'
):
Expand Down
16 changes: 8 additions & 8 deletions config/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,20 @@ fn minimal_config_snapshot() -> Result<()> {
max_wasm_size_bytes: 4194304,
},
asset_metadata_limits: Limits {
max_len: 1048576,
max_entry_byte_size: 4096,
capacity: 1048576,
max_entry_len: 4096,
},
asset_definition_metadata_limits: Limits {
max_len: 1048576,
max_entry_byte_size: 4096,
capacity: 1048576,
max_entry_len: 4096,
},
account_metadata_limits: Limits {
max_len: 1048576,
max_entry_byte_size: 4096,
capacity: 1048576,
max_entry_len: 4096,
},
domain_metadata_limits: Limits {
max_len: 1048576,
max_entry_byte_size: 4096,
capacity: 1048576,
max_entry_len: 4096,
},
ident_length_limits: LengthLimits {
min: 1,
Expand Down
8 changes: 4 additions & 4 deletions config/tests/fixtures/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ max_transactions_in_block = 512
block_time = 2_000
commit_time = 4_000
transaction_limits = {max_instruction_number = 4096, max_wasm_size_bytes = 4194304 }
asset_metadata_limits = { max_len = 1048576, max_entry_byte_size = 4096 }
asset_definition_metadata_limits = { max_len = 1048576, max_entry_byte_size = 4096 }
account_metadata_limits = { max_len = 1048576, max_entry_byte_size = 4096 }
domain_metadata_limits = { max_len = 1048576, max_entry_byte_size = 4096 }
asset_metadata_limits = { capacity = 1048576, max_entry_len = 4096 }
asset_definition_metadata_limits = { capacity = 1048576, max_entry_len = 4096 }
account_metadata_limits = { capacity = 1048576, max_entry_len = 4096 }
domain_metadata_limits = { capacity = 1048576, max_entry_len = 4096 }
ident_length_limits = { min = 1, max = 128 }
wasm_fuel_limit = 55000000
wasm_max_memory = 524288000
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 @@ -1751,12 +1754,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
Loading

0 comments on commit fd09f10

Please sign in to comment.