Skip to content

Commit

Permalink
[refactor]: update executor source code
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Nov 13, 2023
1 parent 50cb33b commit 787ff0a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 188 deletions.
Binary file modified modules/block/src/test/resources/executor.wasm
Binary file not shown.
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions modules/client/src/test/executor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//! Runtime Executor for client tests
#![no_std]

extern crate alloc;
#[cfg(not(test))]
extern crate panic_halt;

use alloc::borrow::ToOwned as _;

use iroha_executor::{default::default_permission_token_schema, prelude::*, smart_contract};
use lol_alloc::{FreeListAllocator, LockedAllocator};

#[global_allocator]
static ALLOC: LockedAllocator<FreeListAllocator> = LockedAllocator::new(FreeListAllocator::new());

/// Executor that replaces some of [`Validate`]'s methods with sensible defaults
///
/// # Warning
///
/// The defaults are not guaranteed to be stable.
#[derive(Clone, Constructor, Debug, ValidateEntrypoints, ExpressionEvaluator, Validate, Visit)]
pub struct Executor {
verdict: Result,
block_height: u64,
host: smart_contract::Host,
}

impl Executor {
fn ensure_genesis(block_height: u64) -> MigrationResult {
if block_height != 0 {
return Err("Default Executor is intended to be used only in genesis. \
Write your own executor if you need to upgrade executor on existing chain."
.to_owned());
}

Ok(())
}
}

/// Migrate previous executor to the current version.
/// Called by Iroha once just before upgrading executor.
///
/// # Errors
///
/// Concrete errors are specific to the implementation.
///
/// If `migrate()` entrypoint fails then the whole `Upgrade` instruction
/// will be denied and previous executor will stay unchanged.
#[entrypoint]
pub fn migrate(block_height: u64) -> MigrationResult {
Executor::ensure_genesis(block_height)?;

let schema = default_permission_token_schema();
let (token_ids, schema_str) = schema.serialize();
iroha_executor::set_permission_token_schema(
&iroha_executor::data_model::permission::PermissionTokenSchema::new(token_ids, schema_str),
);

Ok(())
}

Binary file modified modules/client/src/test/resources/executor.wasm
Binary file not shown.
188 changes: 0 additions & 188 deletions modules/client/src/test/validator/src/lib.rs

This file was deleted.

Binary file modified modules/test-tools/src/main/resources/executor.wasm
Binary file not shown.

0 comments on commit 787ff0a

Please sign in to comment.