Refactor NativeExecutor to support multiple Wasm execution methods (#3677)

* executor: Move definitions of externals out of wasm_executor module.

* executor: Create WasmRuntime trait.

This will be used to decouple the runtime cache from wasmi execution.

* executor: Remove WasmExecutor and move methods to wasmi_execution.

These will now be crate-internal functions and there is no need
for the struct.

* executor: Set default default_heap_pages in NativeExecutor.

* cli: CLI configuration for Wasm execution method.

* executor: Remove wasmi-specific code from wasm_runtime.

* Respond to review comments.
This commit is contained in:
Jim Posen
2019-10-08 12:57:12 +02:00
committed by GitHub
parent 2c77262c8f
commit 6cebbbf8b2
22 changed files with 1359 additions and 1237 deletions
+42 -1
View File
@@ -18,7 +18,6 @@ use crate::traits::{AugmentClap, GetLogFilter};
use std::path::PathBuf;
use structopt::{StructOpt, clap::{arg_enum, App, AppSettings, _clap_count_exprs, SubCommand, Arg}};
use client;
pub use crate::execution_strategy::ExecutionStrategy;
@@ -44,6 +43,24 @@ impl Into<client::ExecutionStrategy> for ExecutionStrategy {
}
}
arg_enum! {
/// How to execute Wasm runtime code
#[allow(missing_docs)]
#[derive(Debug, Clone)]
pub enum WasmExecutionMethod {
// Uses an interpreter.
Interpreted,
}
}
impl Into<service::config::WasmExecutionMethod> for WasmExecutionMethod {
fn into(self) -> service::config::WasmExecutionMethod {
match self {
WasmExecutionMethod::Interpreted => service::config::WasmExecutionMethod::Interpreted,
}
}
}
arg_enum! {
/// Whether off-chain workers are enabled.
#[allow(missing_docs)]
@@ -404,6 +421,18 @@ pub struct RunCmd {
)]
pub offchain_worker: OffchainWorkerEnabled,
/// Method for executing Wasm runtime code.
#[structopt(
long = "wasm-execution",
value_name = "METHOD",
raw(
possible_values = "&WasmExecutionMethod::variants()",
case_insensitive = "true",
default_value = r#""Interpreted""#
)
)]
pub wasm_method: WasmExecutionMethod,
#[allow(missing_docs)]
#[structopt(flatten)]
pub execution_strategies: ExecutionStrategies,
@@ -651,6 +680,18 @@ pub struct ImportBlocksCmd {
#[structopt(flatten)]
pub shared_params: SharedParams,
/// Method for executing Wasm runtime code.
#[structopt(
long = "wasm-execution",
value_name = "METHOD",
raw(
possible_values = "&WasmExecutionMethod::variants()",
case_insensitive = "true",
default_value = r#""Interpreted""#
)
)]
pub wasm_method: WasmExecutionMethod,
/// The means of execution used when calling into the runtime while importing blocks.
#[structopt(
long = "execution",