|
1 | | -//! `CodeExecutor` specialization which uses natively compiled runtime when the WASM to be |
2 | | -//! executed is equivalent to the natively compiled code. |
| 1 | +//! This module declares an `AlephExecutor` which is either a |
| 2 | +//! * `WasmExecutor`, for production and test build (when no local debugging is required) |
| 3 | +//! * `NativeElseWasmExecutor` for `try-runtime`, `runtime-benchmarks` and local debugging builds |
3 | 4 |
|
4 | | -use sc_executor::NativeElseWasmExecutor; |
| 5 | +use sc_service::Configuration; |
5 | 6 |
|
6 | | -// Declare an instance of the native executor named `ExecutorDispatch`. Include the wasm binary as the equivalent wasm code. |
7 | | -pub struct ExecutorDispatch; |
| 7 | +#[cfg(not(any( |
| 8 | + feature = "runtime-benchmarks", |
| 9 | + feature = "local-debugging", |
| 10 | + feature = "try-runtime" |
| 11 | +)))] |
| 12 | +pub mod aleph_executor { |
| 13 | + use sc_executor::WasmExecutor; |
| 14 | + |
| 15 | + use super::Configuration; |
8 | 16 |
|
9 | | -impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { |
10 | | - #[cfg(feature = "runtime-benchmarks")] |
11 | 17 | type ExtendHostFunctions = ( |
| 18 | + sp_io::SubstrateHostFunctions, |
12 | 19 | aleph_runtime_interfaces::snark_verifier::HostFunctions, |
13 | | - frame_benchmarking::benchmarking::HostFunctions, |
14 | 20 | ); |
15 | | - #[cfg(not(feature = "runtime-benchmarks"))] |
16 | | - type ExtendHostFunctions = (aleph_runtime_interfaces::snark_verifier::HostFunctions,); |
| 21 | + pub type Executor = WasmExecutor<ExtendHostFunctions>; |
| 22 | + |
| 23 | + pub fn get_executor(config: &Configuration) -> Executor { |
| 24 | + sc_service::new_wasm_executor(config) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +#[cfg(any( |
| 29 | + feature = "runtime-benchmarks", |
| 30 | + feature = "local-debugging", |
| 31 | + feature = "try-runtime" |
| 32 | +))] |
| 33 | +pub mod aleph_executor { |
| 34 | + use sc_executor::NativeElseWasmExecutor; |
| 35 | + |
| 36 | + use super::Configuration; |
17 | 37 |
|
18 | | - fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> { |
19 | | - aleph_runtime::api::dispatch(method, data) |
| 38 | + pub struct ExecutorDispatch; |
| 39 | + |
| 40 | + impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { |
| 41 | + #[cfg(feature = "runtime-benchmarks")] |
| 42 | + type ExtendHostFunctions = ( |
| 43 | + aleph_runtime_interfaces::snark_verifier::HostFunctions, |
| 44 | + frame_benchmarking::benchmarking::HostFunctions, |
| 45 | + ); |
| 46 | + |
| 47 | + #[cfg(not(feature = "runtime-benchmarks"))] |
| 48 | + type ExtendHostFunctions = (aleph_runtime_interfaces::snark_verifier::HostFunctions,); |
| 49 | + |
| 50 | + fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> { |
| 51 | + aleph_runtime::api::dispatch(method, data) |
| 52 | + } |
| 53 | + |
| 54 | + fn native_version() -> sc_executor::NativeVersion { |
| 55 | + aleph_runtime::native_version() |
| 56 | + } |
20 | 57 | } |
21 | 58 |
|
22 | | - fn native_version() -> sc_executor::NativeVersion { |
23 | | - aleph_runtime::native_version() |
| 59 | + pub type Executor = NativeElseWasmExecutor<ExecutorDispatch>; |
| 60 | + |
| 61 | + pub fn get_executor(config: &Configuration) -> Executor { |
| 62 | + sc_service::new_native_or_wasm_executor(config) |
24 | 63 | } |
25 | 64 | } |
26 | | - |
27 | | -pub type AlephExecutor = NativeElseWasmExecutor<ExecutorDispatch>; |
|
0 commit comments