Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use ConstVec for instructions in Executable #5096

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/iroha_core/src/smartcontracts/isi/triggers/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use iroha_data_model::{
query::error::FindError,
transaction::WasmSmartContract,
};
use iroha_primitives::const_vec::ConstVec;
use mv::{
cell::{Block as CellBlock, Cell, Transaction as CellTransaction, View as CellView},
storage::{
Expand Down Expand Up @@ -1012,7 +1013,7 @@ pub enum ExecutableRef {
/// Loaded WASM
Wasm(HashOf<WasmSmartContract>),
/// Vector of ISI
Instructions(Vec<InstructionBox>),
Instructions(ConstVec<InstructionBox>),
}

impl core::fmt::Debug for ExecutableRef {
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_data_model/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ mod candidate {
else {
return Err("Genesis transaction must contain instructions");
};
let [InstructionBox::Upgrade(_)] = instructions_executor.as_slice() else {
let [InstructionBox::Upgrade(_)] = instructions_executor.as_ref() else {
return Err(
"First transaction must contain single `Upgrade` instruction to set executor",
);
Expand Down
5 changes: 3 additions & 2 deletions crates/iroha_data_model/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::{
#[model]
mod model {
use getset::Getters;
use iroha_primitives::const_vec::ConstVec;

use super::*;
use crate::account::AccountId;
Expand All @@ -53,7 +54,7 @@ mod model {
pub enum Executable {
/// Ordered set of instructions.
#[debug(fmt = "{_0:?}")]
Instructions(Vec<InstructionBox>),
Instructions(ConstVec<InstructionBox>),
/// WebAssembly smartcontract
Wasm(WasmSmartContract),
}
Expand Down Expand Up @@ -182,7 +183,7 @@ mod model {

impl<A: Instruction> FromIterator<A> for Executable {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
Self::Instructions(iter.into_iter().map(Into::into).collect())
Self::Instructions(iter.into_iter().map(Into::into).collect::<Vec<_>>().into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_data_model/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn visit_transaction<V: Visit + ?Sized>(
match transaction.instructions() {
Executable::Wasm(wasm) => visitor.visit_wasm(authority, wasm),
Executable::Instructions(instructions) => {
for isi in instructions {
for isi in instructions.as_ref() {
visitor.visit_instruction(authority, isi);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_executor/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn visit_transaction<V: Validate + Visit + ?Sized>(
match transaction.instructions() {
Executable::Wasm(wasm) => executor.visit_wasm(authority, wasm),
Executable::Instructions(instructions) => {
for isi in instructions {
for isi in instructions.as_ref() {
if executor.verdict().is_ok() {
executor.visit_instruction(authority, isi);
}
Expand Down
1 change: 1 addition & 0 deletions crates/iroha_schema_gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ types!(
ConfigurationEventSet,
ConstString,
ConstVec<u8>,
ConstVec<InstructionBox>,
CustomInstruction,
CustomParameter,
CustomParameterId,
Expand Down
Loading