Skip to content

Commit

Permalink
[refactor] remove optimized WASM from data_model
Browse files Browse the repository at this point in the history
Signed-off-by: Artemii Gerasimovich <[email protected]>
  • Loading branch information
Artemii Gerasimovich authored and 6r1d committed Oct 17, 2023
1 parent 745a0bc commit 5a1b310
Show file tree
Hide file tree
Showing 22 changed files with 318 additions and 504 deletions.
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl_query_result! {
iroha_data_model::query::MetadataValue,
iroha_data_model::query::TransactionQueryOutput,
iroha_data_model::permission::PermissionTokenSchema,
iroha_data_model::trigger::Trigger<iroha_data_model::events::TriggeringFilterBox, iroha_data_model::transaction::Executable>,
iroha_data_model::trigger::Trigger<iroha_data_model::events::TriggeringFilterBox>,
}

/// Iroha client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ impl Visit for Executor {
visit_revoke_account_role(Revoke<RoleId>),

// Trigger validation
visit_unregister_trigger(Unregister<Trigger<TriggeringFilterBox, Executable>>),
visit_mint_trigger_repetitions(Mint<u32, Trigger<TriggeringFilterBox, Executable>>),
visit_burn_trigger_repetitions(Burn<u32, Trigger<TriggeringFilterBox, Executable>>),
visit_unregister_trigger(Unregister<Trigger<TriggeringFilterBox>>),
visit_mint_trigger_repetitions(Mint<u32, Trigger<TriggeringFilterBox>>),
visit_burn_trigger_repetitions(Burn<u32, Trigger<TriggeringFilterBox>>),
visit_execute_trigger(ExecuteTrigger),

// Parameter validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ impl Visit for Executor {
visit_revoke_account_role(Revoke<RoleId>),

// Trigger validation
visit_unregister_trigger(Unregister<Trigger<TriggeringFilterBox, Executable>>),
visit_mint_trigger_repetitions(Mint<u32, Trigger<TriggeringFilterBox, Executable>>),
visit_burn_trigger_repetitions(Burn<u32, Trigger<TriggeringFilterBox, Executable>>),
visit_unregister_trigger(Unregister<Trigger<TriggeringFilterBox>>),
visit_mint_trigger_repetitions(Mint<u32, Trigger<TriggeringFilterBox>>),
visit_burn_trigger_repetitions(Burn<u32, Trigger<TriggeringFilterBox>>),
visit_execute_trigger(ExecuteTrigger),

// Parameter validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ impl Visit for Executor {
visit_revoke_account_role(Revoke<RoleId>),

// Trigger validation
visit_unregister_trigger(Unregister<Trigger<TriggeringFilterBox, Executable>>),
visit_mint_trigger_repetitions(Mint<u32, Trigger<TriggeringFilterBox, Executable>>),
visit_burn_trigger_repetitions(Burn<u32, Trigger<TriggeringFilterBox, Executable>>),
visit_unregister_trigger(Unregister<Trigger<TriggeringFilterBox>>),
visit_mint_trigger_repetitions(Mint<u32, Trigger<TriggeringFilterBox>>),
visit_burn_trigger_repetitions(Burn<u32, Trigger<TriggeringFilterBox>>),
visit_execute_trigger(ExecuteTrigger),

// Parameter validation
Expand Down
Binary file modified configs/peer/executor.wasm
Binary file not shown.
10 changes: 4 additions & 6 deletions core/src/smartcontracts/isi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ impl Execute for RegisterExpr {
}
RegistrableBox::Asset(object) => Register::<Asset> { object }.execute(authority, wsv),
RegistrableBox::Trigger(object) => {
Register::<Trigger<TriggeringFilterBox, Executable>> { object }
.execute(authority, wsv)
Register::<Trigger<TriggeringFilterBox>> { object }.execute(authority, wsv)
}
RegistrableBox::Role(object) => Register::<Role> { object }.execute(authority, wsv),
}
Expand All @@ -110,8 +109,7 @@ impl Execute for UnregisterExpr {
IdBox::PeerId(object_id) => Unregister::<Peer> { object_id }.execute(authority, wsv),
IdBox::RoleId(object_id) => Unregister::<Role> { object_id }.execute(authority, wsv),
IdBox::TriggerId(object_id) => {
Unregister::<Trigger<TriggeringFilterBox, Executable>> { object_id }
.execute(authority, wsv)
Unregister::<Trigger<TriggeringFilterBox>> { object_id }.execute(authority, wsv)
}
IdBox::PermissionTokenId(_) | IdBox::ParameterId(_) => {
Err(Error::Evaluate(InstructionType::Unregister.into()))
Expand Down Expand Up @@ -164,7 +162,7 @@ impl Execute for MintExpr {
.execute(authority, wsv)
}
(IdBox::TriggerId(destination_id), Value::Numeric(NumericValue::U32(object))) => {
Mint::<u32, Trigger<TriggeringFilterBox, Executable>> {
Mint::<u32, Trigger<TriggeringFilterBox>> {
object,
destination_id,
}
Expand Down Expand Up @@ -206,7 +204,7 @@ impl Execute for BurnExpr {
}
.execute(authority, wsv),
(IdBox::TriggerId(destination_id), Value::Numeric(NumericValue::U32(object))) => {
Burn::<u32, Trigger<TriggeringFilterBox, Executable>> {
Burn::<u32, Trigger<TriggeringFilterBox>> {
object,
destination_id,
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/smartcontracts/isi/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl_lazy! {
iroha_data_model::query::MetadataValue,
iroha_data_model::query::TransactionQueryOutput,
iroha_data_model::permission::PermissionTokenSchema,
iroha_data_model::trigger::Trigger<iroha_data_model::events::TriggeringFilterBox, iroha_data_model::transaction::Executable>,
iroha_data_model::trigger::Trigger<iroha_data_model::events::TriggeringFilterBox>,
}

/// Query Request statefully validated on the Iroha node side.
Expand Down
86 changes: 21 additions & 65 deletions core/src/smartcontracts/isi/triggers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod isi {

use super::{super::prelude::*, *};

impl Execute for Register<Trigger<TriggeringFilterBox, Executable>> {
impl Execute for Register<Trigger<TriggeringFilterBox>> {
#[metrics(+"register_trigger")]
fn execute(self, _authority: &AccountId, wsv: &mut WorldStateView) -> Result<(), Error> {
let new_trigger = self.object;
Expand Down Expand Up @@ -81,7 +81,7 @@ pub mod isi {
}
}

impl Execute for Unregister<Trigger<TriggeringFilterBox, Executable>> {
impl Execute for Unregister<Trigger<TriggeringFilterBox>> {
#[metrics(+"unregister_trigger")]
fn execute(self, _authority: &AccountId, wsv: &mut WorldStateView) -> Result<(), Error> {
let trigger_id = self.object_id.clone();
Expand All @@ -100,7 +100,7 @@ pub mod isi {
}
}

impl Execute for Mint<u32, Trigger<TriggeringFilterBox, Executable>> {
impl Execute for Mint<u32, Trigger<TriggeringFilterBox>> {
#[metrics(+"mint_trigger_repetitions")]
fn execute(self, _authority: &AccountId, wsv: &mut WorldStateView) -> Result<(), Error> {
let id = self.destination_id;
Expand Down Expand Up @@ -132,7 +132,7 @@ pub mod isi {
}
}

impl Execute for Burn<u32, Trigger<TriggeringFilterBox, Executable>> {
impl Execute for Burn<u32, Trigger<TriggeringFilterBox>> {
#[metrics(+"burn_trigger_repetitions")]
fn execute(self, _authority: &AccountId, wsv: &mut WorldStateView) -> Result<(), Error> {
let trigger = self.destination_id;
Expand Down Expand Up @@ -202,7 +202,7 @@ pub mod query {
};

use super::*;
use crate::{prelude::*, smartcontracts::triggers::set::LoadedExecutable};
use crate::prelude::*;

impl ValidQuery for FindAllActiveTriggerIds {
#[metrics(+"find_all_active_triggers")]
Expand All @@ -216,41 +216,19 @@ pub mod query {

impl ValidQuery for FindTriggerById {
#[metrics(+"find_trigger_by_id")]
fn execute(
&self,
wsv: &WorldStateView,
) -> Result<Trigger<TriggeringFilterBox, Executable>, Error> {
fn execute(&self, wsv: &WorldStateView) -> Result<Trigger<TriggeringFilterBox>, Error> {
let id = wsv
.evaluate(&self.id)
.map_err(|e| Error::Evaluate(format!("Failed to evaluate trigger id. {e}")))?;
iroha_logger::trace!(%id);
// Can't use just `ActionTrait::clone_and_box` cause this will trigger lifetime mismatch
// Can't use just `LoadedActionTrait::clone_and_box` cause this will trigger lifetime mismatch
#[allow(clippy::redundant_closure_for_method_calls)]
let Action {
executable: loaded_executable,
repeats,
authority,
filter,
metadata,
} = wsv
let loaded_action = wsv
.triggers()
.inspect_by_id(&id, |action| action.clone_and_box())
.ok_or_else(|| Error::Find(FindError::Trigger(id.clone())))?;

let original_executable = match loaded_executable {
LoadedExecutable::Wasm(_) => {
let original_wasm = wsv
.triggers()
.get_original_contract(&id)
.cloned()
.expect("No original smartcontract saved for trigger. This is a bug.");
Executable::Wasm(original_wasm)
}
LoadedExecutable::Instructions(isi) => Executable::Instructions(isi),
};

let action = Action::new(original_executable, repeats, authority, filter)
.with_metadata(metadata);
let action = wsv.triggers().get_original_action(loaded_action);

// TODO: Should we redact the metadata if the account is not the authority/owner?
Ok(Trigger::new(id, action))
Expand Down Expand Up @@ -285,44 +263,22 @@ pub mod query {
fn execute<'wsv>(
&self,
wsv: &'wsv WorldStateView,
) -> eyre::Result<
Box<dyn Iterator<Item = Trigger<TriggeringFilterBox, Executable>> + 'wsv>,
Error,
> {
) -> eyre::Result<Box<dyn Iterator<Item = Trigger<TriggeringFilterBox>> + 'wsv>, Error>
{
let domain_id = wsv
.evaluate(&self.domain_id)
.map_err(|e| Error::Evaluate(format!("Failed to evaluate domain id. {e}")))?;

Ok(Box::new(wsv.triggers().inspect_by_domain_id(
&domain_id,
|trigger_id, action| {
let Action {
executable: loaded_executable,
repeats,
authority,
filter,
metadata,
} = action.clone_and_box();

let original_executable =
match loaded_executable {
LoadedExecutable::Wasm(_) => {
let original_wasm =
wsv.triggers().get_original_contract(&trigger_id).cloned().expect(
"No original smartcontract saved for trigger. This is a bug.",
);
Executable::Wasm(original_wasm)
}
LoadedExecutable::Instructions(isi) => Executable::Instructions(isi),
};

Trigger::new(
trigger_id.clone(),
Action::new(original_executable, repeats, authority, filter)
.with_metadata(metadata),
)
},
)))
Ok(Box::new(
wsv.triggers()
.inspect_by_domain_id(&domain_id, |trigger_id, action| {
(trigger_id.clone(), action.clone_and_box())
})
.map(|(trigger_id, action)| {
let action = wsv.triggers().get_original_action(action);
Trigger::new(trigger_id, action)
}),
))
}
}
}
Loading

0 comments on commit 5a1b310

Please sign in to comment.