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 committed Oct 6, 2023
1 parent b53a288 commit 2b5f63a
Show file tree
Hide file tree
Showing 16 changed files with 296 additions and 401 deletions.
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,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
8 changes: 3 additions & 5 deletions core/src/smartcontracts/isi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,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 @@ -115,8 +114,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 @@ -169,7 +167,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
2 changes: 1 addition & 1 deletion core/src/smartcontracts/isi/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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
84 changes: 20 additions & 64 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")]
#[allow(clippy::expect_used)]
fn execute(self, _authority: &AccountId, wsv: &mut WorldStateView) -> Result<(), Error> {
Expand Down Expand Up @@ -82,7 +82,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 @@ -101,7 +101,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 @@ -133,7 +133,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 @@ -203,7 +203,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 @@ -217,41 +217,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
#[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 @@ -286,44 +264,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 2b5f63a

Please sign in to comment.