Skip to content

Commit

Permalink
Add option to enable native execution in LocalCallExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
ark0f committed Jun 17, 2024
1 parent a318557 commit c03b0d6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 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.

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
15 changes: 14 additions & 1 deletion 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 Down Expand Up @@ -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 Down

0 comments on commit c03b0d6

Please sign in to comment.