Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches for gear-tasks #4

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 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
5 changes: 5 additions & 0 deletions substrate/primitives/externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ pub trait Externalities: ExtensionStore {
///
/// Get all the keys that have been read or written to during the benchmark.
fn get_read_and_written_keys(&self) -> Vec<(Vec<u8>, u32, u32, bool)>;

/// Access to `OverlayChanges<H>` for `gear-tasks`.
fn gear_overlayed_changes(&self) -> Option<Box<dyn Any + Send>> {
None
}
}

/// Extension for the [`Externalities`] trait.
Expand Down
6 changes: 5 additions & 1 deletion substrate/primitives/state-machine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ where

impl<'a, H, B> Externalities for Ext<'a, H, B>
where
H: Hasher,
H: Hasher + 'static,
H::Out: Ord + 'static + codec::Codec,
B: Backend<H>,
{
Expand Down Expand Up @@ -651,6 +651,10 @@ where
fn get_read_and_written_keys(&self) -> Vec<(Vec<u8>, u32, u32, bool)> {
self.backend.get_read_and_written_keys()
}

fn gear_overlayed_changes(&self) -> Option<Box<dyn Any + Send>> {
Some(Box::new(self.overlay.clone()))
}
}

impl<'a, H, B> Ext<'a, H, B>
Expand Down
8 changes: 4 additions & 4 deletions substrate/primitives/state-machine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod execution {

impl<'a, B, H, Exec> StateMachine<'a, B, H, Exec>
where
H: Hasher,
H: Hasher + 'static,
H::Out: Ord + 'static + codec::Codec,
Exec: CodeExecutor + Clone + 'static,
B: Backend<H>,
Expand Down Expand Up @@ -318,7 +318,7 @@ mod execution {
) -> Result<(Vec<u8>, StorageProof), Box<dyn Error>>
where
B: AsTrieBackend<H>,
H: Hasher,
H: Hasher + 'static,
H::Out: Ord + 'static + codec::Codec,
Exec: CodeExecutor + Clone + 'static,
{
Expand Down Expand Up @@ -354,7 +354,7 @@ mod execution {
) -> Result<(Vec<u8>, StorageProof), Box<dyn Error>>
where
S: trie_backend_essence::TrieBackendStorage<H>,
H: Hasher,
H: Hasher + 'static,
H::Out: Ord + 'static + codec::Codec,
Exec: CodeExecutor + 'static + Clone,
{
Expand Down Expand Up @@ -416,7 +416,7 @@ mod execution {
runtime_code: &RuntimeCode,
) -> Result<Vec<u8>, Box<dyn Error>>
where
H: Hasher,
H: Hasher + 'static,
H::Out: Ord + 'static + codec::Codec,
Exec: CodeExecutor + Clone + 'static,
{
Expand Down
Loading