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 3 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.

2 changes: 2 additions & 0 deletions substrate/client/api/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub trait CallExecutor<B: BlockT>: RuntimeVersionOf {
/// The backend used by the node.
type Backend: crate::backend::Backend<B>;

fn gear_use_native(&mut self) {}

/// Returns the [`ExecutionExtensions`].
fn execution_extensions(&self) -> &ExecutionExtensions<B>;

Expand Down
17 changes: 17 additions & 0 deletions substrate/client/service/src/client/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct LocalCallExecutor<Block: BlockT, B, E> {
wasm_override: Arc<Option<WasmOverride>>,
wasm_substitutes: WasmSubstitutes<Block, E, B>,
execution_extensions: Arc<ExecutionExtensions<Block>>,
gear_use_native: bool,
}

impl<Block: BlockT, B, E> LocalCallExecutor<Block, B, E>
Expand Down Expand Up @@ -71,6 +72,7 @@ where
wasm_override: Arc::new(wasm_override),
wasm_substitutes,
execution_extensions: Arc::new(execution_extensions),
gear_use_native: false,
})
}

Expand Down Expand Up @@ -141,6 +143,7 @@ where
wasm_override: self.wasm_override.clone(),
wasm_substitutes: self.wasm_substitutes.clone(),
execution_extensions: self.execution_extensions.clone(),
gear_use_native: self.gear_use_native,
}
}
}
Expand All @@ -155,6 +158,10 @@ where

type Backend = B;

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

fn execution_extensions(&self) -> &ExecutionExtensions<Block> {
&self.execution_extensions
}
Expand Down Expand Up @@ -237,6 +244,11 @@ where
call_context,
)
.set_parent_hash(at_hash);

if self.gear_use_native {
state_machine.gear_use_native();
}

state_machine.execute()
},
None => {
Expand All @@ -251,6 +263,11 @@ where
call_context,
)
.set_parent_hash(at_hash);

if self.gear_use_native {
state_machine.gear_use_native();
}

state_machine.execute()
},
}
Expand Down
4 changes: 4 additions & 0 deletions substrate/client/service/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ where
})
}

pub fn gear_use_native(&mut self) {
self.executor.gear_use_native();
}

/// returns a reference to the block import notification sinks
/// useful for test environments.
pub fn import_notification_sinks(&self) -> &NotificationSinks<BlockImportNotification<Block>> {
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
23 changes: 18 additions & 5 deletions substrate/primitives/state-machine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ mod execution {
/// Used for logging.
parent_hash: Option<H::Out>,
context: CallContext,
gear_use_native: bool,
}

impl<'a, B, H, Exec> Drop for StateMachine<'a, B, H, Exec>
Expand All @@ -223,7 +224,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 All @@ -250,6 +251,7 @@ mod execution {
stats: StateMachineStats::default(),
parent_hash: None,
context,
gear_use_native: false,
}
}

Expand Down Expand Up @@ -289,7 +291,14 @@ mod execution {

let result = self
.exec
.call(&mut ext, self.runtime_code, self.method, self.call_data, false, self.context)
.call(
&mut ext,
self.runtime_code,
self.method,
self.call_data,
self.gear_use_native,
self.context,
)
.0;

self.overlay
Expand All @@ -305,6 +314,10 @@ mod execution {

result.map_err(|e| Box::new(e) as Box<_>)
}

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

/// Prove execution using the given state backend, overlayed changes, and call executor.
Expand All @@ -318,7 +331,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 +367,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 +429,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