Skip to content

Commit

Permalink
[refactor] #3918: Rename validator to executor
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Oct 9, 2023
1 parent e73c753 commit e4343cf
Show file tree
Hide file tree
Showing 70 changed files with 1,054 additions and 1,059 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ iroha_wasm_builder = { version = "=2.0.0-pre-rc.19", path = "wasm_builder" }
iroha_smart_contract = { version = "=2.0.0-pre-rc.19", path = "smart_contract" }
iroha_smart_contract_derive = { version = "=2.0.0-pre-rc.19", path = "smart_contract/derive" }
iroha_smart_contract_utils = { version = "=2.0.0-pre-rc.19", path = "smart_contract/utils" }
iroha_validator = { version = "=2.0.0-pre-rc.19", path = "smart_contract/validator" }
iroha_validator_derive = { version = "=2.0.0-pre-rc.19", path = "smart_contract/validator/derive" }
iroha_executor = { version = "=2.0.0-pre-rc.19", path = "smart_contract/executor" }
iroha_executor_derive = { version = "=2.0.0-pre-rc.19", path = "smart_contract/executor/derive" }
iroha_trigger = { version = "=2.0.0-pre-rc.19", path = "smart_contract/trigger" }
iroha_trigger_derive = { version = "=2.0.0-pre-rc.19", path = "smart_contract/trigger/derive" }

Expand Down Expand Up @@ -326,8 +326,8 @@ members = [
"smart_contract/trigger",
"smart_contract/trigger/derive",
"smart_contract/utils",
"smart_contract/validator",
"smart_contract/validator/derive",
"smart_contract/executor",
"smart_contract/executor/derive",
"substrate",
"telemetry",
"tools/kagami",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Iroha project mainly consists of the following crates:
* [`iroha_logger`](logger) uses `tracing` to provide logging facilities.
* [`iroha_macro`](macro) provides the convenience macros.
* [`iroha_p2p`](p2p) defines peer creation and handshake logic.
* [`iroha_default_validator`](default_validator) defines runtime validation logic.
* [`iroha_default_executor`](default_executor) defines runtime validation logic.
* [`iroha_substrate`](substrate) is the bridge substrate `XClaim` external module.
* [`iroha_telemetry`](telemetry) is used for monitoring and analysis of telemetry data.
* [`iroha_version`](version) provides message versioning for non-simultaneous system updates.
Expand Down
12 changes: 6 additions & 6 deletions cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//! Build script to extract git hash of iroha build and to check runtime validator
//! Build script to extract git hash of iroha build and to check runtime executor
use eyre::{eyre, Result, WrapErr};

const DEFAULT_VALIDATOR_PATH: &str = "../default_validator";
const DEFAULT_EXECUTOR_PATH: &str = "../default_executor";

fn main() -> Result<()> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed={DEFAULT_VALIDATOR_PATH}");
println!("cargo:rerun-if-changed={DEFAULT_EXECUTOR_PATH}");

extract_git_hash()?;

// HACK: used by Nix, since at the moment
// the checks are a process that's hard to accomodate
// in Nix environment
if std::option_env!("IROHA_SKIP_WASM_CHECKS").is_none() {
check_default_validator()?;
check_default_executor()?;
}

Ok(())
Expand All @@ -30,8 +30,8 @@ fn extract_git_hash() -> Result<()> {
}

/// Apply `cargo check` to the smartcontract.
fn check_default_validator() -> Result<()> {
iroha_wasm_builder::Builder::new(DEFAULT_VALIDATOR_PATH)
fn check_default_executor() -> Result<()> {
iroha_wasm_builder::Builder::new(DEFAULT_EXECUTOR_PATH)
.format()
.check()
}
12 changes: 6 additions & 6 deletions cli/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ pub fn get_config(trusted_peers: UniqueVec<PeerId>, key_pair: Option<KeyPair>) -
.expect("Iroha config should build as all required fields were provided")
}

/// Construct validator from path.
/// Construct executor from path.
///
/// `relative_path` should be relative to `CARGO_MANIFEST_DIR`.
///
/// # Errors
///
/// - Failed to create temp dir for validator output
/// - Failed to build validator
/// - Failed to optimize validator
pub fn construct_validator<P>(relative_path: &P) -> color_eyre::Result<Validator>
/// - Failed to create temp dir for executor output
/// - Failed to build executor
/// - Failed to optimize executor
pub fn construct_executor<P>(relative_path: &P) -> color_eyre::Result<Executor>
where
P: AsRef<Path> + ?Sized,
{
Expand All @@ -118,5 +118,5 @@ where
.optimize()?
.into_bytes()?;

Ok(Validator::new(WasmSmartContract::from_compiled(wasm_blob)))
Ok(Executor::new(WasmSmartContract::from_compiled(wasm_blob)))
}
2 changes: 1 addition & 1 deletion cli/src/torii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn query_status_code(validation_error: &iroha_data_model::ValidationFail) -> Sta
InstructionFailed(error) => {
iroha_logger::error!(
?error,
"Query validation failed with unexpected error. This means a bug inside Runtime Validator",
"Query validation failed with unexpected error. This means a bug inside Runtime Executor",
);
StatusCode::INTERNAL_SERVER_ERROR
}
Expand Down
10 changes: 5 additions & 5 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::thread;

use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use iroha::samples::{construct_validator, get_config};
use iroha::samples::{construct_executor, get_config};
use iroha_client::client::{asset, Client};
use iroha_config::base::runtime_upgrades::Reload;
use iroha_crypto::KeyPair;
Expand All @@ -29,8 +29,8 @@ fn query_requests(criterion: &mut Criterion) {
get_key_pair().public_key().clone(),
)
.finish_domain()
.validator(
construct_validator("../default_validator").expect("Failed to construct validator"),
.executor(
construct_executor("../default_executor").expect("Failed to construct executor"),
)
.build(),
Some(&configuration.genesis),
Expand Down Expand Up @@ -124,8 +124,8 @@ fn instruction_submits(criterion: &mut Criterion) {
configuration.public_key.clone(),
)
.finish_domain()
.validator(
construct_validator("../default_validator").expect("Failed to construct validator"),
.executor(
construct_executor("../default_executor").expect("Failed to construct executor"),
)
.build(),
Some(&configuration.genesis),
Expand Down
6 changes: 2 additions & 4 deletions client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{thread, time::Duration};

use iroha::samples::{construct_validator, get_config};
use iroha::samples::{construct_executor, get_config};
use iroha_data_model::prelude::*;
use iroha_genesis::{GenesisNetwork, RawGenesisBlock, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
Expand Down Expand Up @@ -30,9 +30,7 @@ fn generate_genesis(num_domains: u32) -> RawGenesisBlock {
}

builder
.validator(
construct_validator("../default_validator").expect("Failed to construct validator"),
)
.executor(construct_executor("../default_executor").expect("Failed to construct executor"))
.build()
}

Expand Down
8 changes: 4 additions & 4 deletions client/tests/integration/smartcontracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ resolver = "2"
members = [
"create_nft_for_every_user_trigger",
"mint_rose_trigger",
"validator_with_admin",
"validator_with_custom_token",
"validator_with_migration_fail",
"executor_with_admin",
"executor_with_custom_token",
"executor_with_migration_fail",
]

[profile.dev]
Expand All @@ -28,7 +28,7 @@ codegen-units = 1 # Further reduces binary size but increases compilation time

[workspace.dependencies]
iroha_trigger = { version = "=2.0.0-pre-rc.19", path = "../../../../smart_contract/trigger", features = ["debug"]}
iroha_validator = { version = "=2.0.0-pre-rc.19", path = "../../../../smart_contract/validator" }
iroha_executor = { version = "=2.0.0-pre-rc.19", path = "../../../../smart_contract/executor" }
iroha_schema = { version = "=2.0.0-pre-rc.19", path = "../../../../schema" }

parity-scale-codec = { version = "3.2.1", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "validator_with_admin"
name = "executor_with_admin"

edition.workspace = true
version.workspace = true
Expand All @@ -11,7 +11,7 @@ license.workspace = true
crate-type = ['cdylib']

[dependencies]
iroha_validator.workspace = true
iroha_executor.workspace = true
iroha_schema.workspace = true

panic-halt.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Runtime Validator which allows any instruction executed by `admin@admin` account.
//! Runtime Executor which allows any instruction executed by `admin@admin` account.
//! If authority is not `admin@admin` then default validation is used as a backup.
#![no_std]
Expand All @@ -7,7 +7,7 @@
#[cfg(not(test))]
extern crate panic_halt;

use iroha_validator::{
use iroha_executor::{
data_model::evaluate::{EvaluationError, ExpressionEvaluator},
parse,
prelude::*,
Expand All @@ -18,13 +18,13 @@ use lol_alloc::{FreeListAllocator, LockedAllocator};
#[global_allocator]
static ALLOC: LockedAllocator<FreeListAllocator> = LockedAllocator::new(FreeListAllocator::new());

struct Validator {
struct Executor {
verdict: Result,
block_height: u64,
host: smart_contract::Host,
}

impl Validator {
impl Executor {
/// Construct [`Self`]
pub fn new(block_height: u64) -> Self {
Self {
Expand All @@ -36,20 +36,20 @@ impl Validator {
}

macro_rules! defaults {
( $($validator:ident $(<$param:ident $(: $bound:path)?>)?($operation:ty)),+ $(,)? ) => { $(
fn $validator $(<$param $(: $bound)?>)?(&mut self, authority: &AccountId, operation: $operation) {
iroha_validator::default::$validator(self, authority, operation)
( $($executor:ident $(<$param:ident $(: $bound:path)?>)?($operation:ty)),+ $(,)? ) => { $(
fn $executor $(<$param $(: $bound)?>)?(&mut self, authority: &AccountId, operation: $operation) {
iroha_executor::default::$executor(self, authority, operation)
} )+
};
}

impl Visit for Validator {
impl Visit for Executor {
fn visit_instruction(&mut self, authority: &AccountId, isi: &InstructionExpr) {
if parse!("admin@admin" as AccountId) == *authority {
pass!(self);
}

iroha_validator::default::visit_instruction(self, authority, isi);
iroha_executor::default::visit_instruction(self, authority, isi);
}

defaults! {
Expand Down Expand Up @@ -114,11 +114,11 @@ impl Visit for Validator {
visit_new_parameter(NewParameter),

// Upgrade validation
visit_upgrade_validator(Upgrade<iroha_validator::data_model::validator::Validator>),
visit_upgrade_executor(Upgrade<iroha_executor::data_model::executor::Executor>),
}
}

impl Validate for Validator {
impl Validate for Executor {
fn verdict(&self) -> &Result {
&self.verdict
}
Expand All @@ -132,7 +132,7 @@ impl Validate for Validator {
}
}

impl ExpressionEvaluator for Validator {
impl ExpressionEvaluator for Executor {
fn evaluate<E: Evaluate>(&self, expression: &E) -> Result<E::Value, EvaluationError> {
self.host.evaluate(expression)
}
Expand All @@ -149,9 +149,9 @@ pub fn validate_transaction(
transaction: SignedTransaction,
block_height: u64,
) -> Result {
let mut validator = Validator::new(block_height);
validator.visit_transaction(&authority, &transaction);
validator.verdict
let mut executor = Executor::new(block_height);
executor.visit_transaction(&authority, &transaction);
executor.verdict
}

#[entrypoint]
Expand All @@ -160,14 +160,14 @@ pub fn validate_instruction(
instruction: InstructionExpr,
block_height: u64,
) -> Result {
let mut validator = Validator::new(block_height);
validator.visit_instruction(&authority, &instruction);
validator.verdict
let mut executor = Executor::new(block_height);
executor.visit_instruction(&authority, &instruction);
executor.verdict
}

#[entrypoint]
pub fn validate_query(authority: AccountId, query: QueryBox, block_height: u64) -> Result {
let mut validator = Validator::new(block_height);
validator.visit_query(&authority, &query);
validator.verdict
let mut executor = Executor::new(block_height);
executor.visit_query(&authority, &query);
executor.verdict
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "validator_with_custom_token"
name = "executor_with_custom_token"

edition.workspace = true
version.workspace = true
Expand All @@ -11,7 +11,7 @@ license.workspace = true
crate-type = ['cdylib']

[dependencies]
iroha_validator.workspace = true
iroha_executor.workspace = true
iroha_schema.workspace = true

parity-scale-codec.workspace = true
Expand Down
Loading

0 comments on commit e4343cf

Please sign in to comment.