Skip to content

Commit

Permalink
Add option to enable native execution in NativeElseWasmExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
ark0f committed Jul 11, 2024
1 parent 652e809 commit b96a699
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

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

25 changes: 21 additions & 4 deletions substrate/client/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ pub struct NativeElseWasmExecutor<D: NativeExecutionDispatch> {
/// Fallback wasm executor.
wasm:
WasmExecutor<ExtendedHostFunctions<sp_io::SubstrateHostFunctions, D::ExtendHostFunctions>>,
gear_force_native: bool,
}

impl<D: NativeExecutionDispatch> NativeElseWasmExecutor<D> {
Expand Down Expand Up @@ -601,7 +602,11 @@ impl<D: NativeExecutionDispatch> NativeElseWasmExecutor<D> {
.with_runtime_cache_size(runtime_cache_size)
.build();

NativeElseWasmExecutor { native_version: D::native_version(), wasm }
NativeElseWasmExecutor {
native_version: D::native_version(),
wasm,
gear_force_native: false,
}
}

/// Create a new instance using the given [`WasmExecutor`].
Expand All @@ -610,14 +615,18 @@ impl<D: NativeExecutionDispatch> NativeElseWasmExecutor<D> {
ExtendedHostFunctions<sp_io::SubstrateHostFunctions, D::ExtendHostFunctions>,
>,
) -> Self {
Self { native_version: D::native_version(), wasm: executor }
Self { native_version: D::native_version(), wasm: executor, gear_force_native: false }
}

/// Ignore missing function imports if set true.
#[deprecated(note = "use `Self::new_with_wasm_executor` method instead of it")]
pub fn allow_missing_host_functions(&mut self, allow_missing_host_functions: bool) {
self.wasm.allow_missing_host_functions = allow_missing_host_functions
}

pub fn gear_force_native(&mut self) {
self.gear_force_native = true;
}
}

impl<D: NativeExecutionDispatch> RuntimeVersionOf for NativeElseWasmExecutor<D> {
Expand Down Expand Up @@ -645,7 +654,7 @@ impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeElseWasmExecut
runtime_code: &RuntimeCode,
method: &str,
data: &[u8],
use_native: bool,
mut use_native: bool,
context: CallContext,
) -> (Result<Vec<u8>>, bool) {
tracing::trace!(
Expand All @@ -654,6 +663,10 @@ impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeElseWasmExecut
"Executing function",
);

if self.gear_force_native {
use_native = true;
}

let on_chain_heap_alloc_strategy = if self.wasm.ignore_onchain_heap_pages {
self.wasm.default_onchain_heap_alloc_strategy
} else {
Expand Down Expand Up @@ -711,7 +724,11 @@ impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeElseWasmExecut

impl<D: NativeExecutionDispatch> Clone for NativeElseWasmExecutor<D> {
fn clone(&self) -> Self {
NativeElseWasmExecutor { native_version: D::native_version(), wasm: self.wasm.clone() }
NativeElseWasmExecutor {
native_version: D::native_version(),
wasm: self.wasm.clone(),
gear_force_native: self.gear_force_native,
}
}
}

Expand Down

0 comments on commit b96a699

Please sign in to comment.