Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Jul 11, 2023
1 parent 961b45d commit 62e70e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 50 deletions.
60 changes: 16 additions & 44 deletions node/src/service/executors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@
// substrate
use sc_executor::{NativeExecutionDispatch, NativeVersion};

#[cfg(all(feature = "runtime-benchmarks", feature = "evm-tracing"))]
pub type HostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
moonbeam_primitives_ext::moonbeam_ext::HostFunctions,
);
#[cfg(all(feature = "runtime-benchmarks", not(feature = "evm-tracing")))]
pub type HostFunctions = frame_benchmarking::benchmarking::HostFunctions;
#[cfg(all(not(feature = "runtime-benchmarks"), feature = "evm-tracing"))]
pub type HostFunctions = moonbeam_primitives_ext::moonbeam_ext::HostFunctions;
#[cfg(not(any(feature = "evm-tracing", feature = "runtime-benchmarks")))]
pub type HostFunctions = ();

/// Darwinia native executor instance.
#[cfg(feature = "darwinia-native")]
pub struct DarwiniaRuntimeExecutor;
#[cfg(feature = "darwinia-native")]
impl NativeExecutionDispatch for DarwiniaRuntimeExecutor {
#[cfg(all(feature = "runtime-benchmarks", feature = "evm-tracing"))]
type ExtendHostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
moonbeam_primitives_ext::moonbeam_ext::HostFunctions,
);
#[cfg(all(feature = "runtime-benchmarks", not(feature = "evm-tracing")))]
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
#[cfg(all(not(feature = "runtime-benchmarks"), feature = "evm-tracing"))]
type ExtendHostFunctions = moonbeam_primitives_ext::moonbeam_ext::HostFunctions;
#[cfg(not(any(feature = "evm-tracing", feature = "runtime-benchmarks")))]
type ExtendHostFunctions = ();
type ExtendHostFunctions = HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
darwinia_runtime::api::dispatch(method, data)
Expand All @@ -50,17 +52,7 @@ impl NativeExecutionDispatch for DarwiniaRuntimeExecutor {
pub struct CrabRuntimeExecutor;
#[cfg(feature = "crab-native")]
impl NativeExecutionDispatch for CrabRuntimeExecutor {
#[cfg(all(feature = "runtime-benchmarks", feature = "evm-tracing"))]
type ExtendHostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
moonbeam_primitives_ext::moonbeam_ext::HostFunctions,
);
#[cfg(all(feature = "runtime-benchmarks", not(feature = "evm-tracing")))]
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
#[cfg(all(not(feature = "runtime-benchmarks"), feature = "evm-tracing"))]
type ExtendHostFunctions = moonbeam_primitives_ext::moonbeam_ext::HostFunctions;
#[cfg(not(any(feature = "evm-tracing", feature = "runtime-benchmarks")))]
type ExtendHostFunctions = ();
type ExtendHostFunctions = HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
crab_runtime::api::dispatch(method, data)
Expand All @@ -76,17 +68,7 @@ impl NativeExecutionDispatch for CrabRuntimeExecutor {
pub struct PangolinRuntimeExecutor;
#[cfg(feature = "pangolin-native")]
impl NativeExecutionDispatch for PangolinRuntimeExecutor {
#[cfg(all(feature = "runtime-benchmarks", feature = "evm-tracing"))]
type ExtendHostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
moonbeam_primitives_ext::moonbeam_ext::HostFunctions,
);
#[cfg(all(feature = "runtime-benchmarks", not(feature = "evm-tracing")))]
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
#[cfg(all(not(feature = "runtime-benchmarks"), feature = "evm-tracing"))]
type ExtendHostFunctions = moonbeam_primitives_ext::moonbeam_ext::HostFunctions;
#[cfg(not(any(feature = "evm-tracing", feature = "runtime-benchmarks")))]
type ExtendHostFunctions = ();
type ExtendHostFunctions = HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
pangolin_runtime::api::dispatch(method, data)
Expand All @@ -102,17 +84,7 @@ impl NativeExecutionDispatch for PangolinRuntimeExecutor {
pub struct PangoroRuntimeExecutor;
#[cfg(feature = "pangoro-native")]
impl NativeExecutionDispatch for PangoroRuntimeExecutor {
#[cfg(all(feature = "runtime-benchmarks", feature = "evm-tracing"))]
type ExtendHostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
moonbeam_primitives_ext::moonbeam_ext::HostFunctions,
);
#[cfg(all(feature = "runtime-benchmarks", not(feature = "evm-tracing")))]
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
#[cfg(all(not(feature = "runtime-benchmarks"), feature = "evm-tracing"))]
type ExtendHostFunctions = moonbeam_primitives_ext::moonbeam_ext::HostFunctions;
#[cfg(not(any(feature = "evm-tracing", feature = "runtime-benchmarks")))]
type ExtendHostFunctions = ();
type ExtendHostFunctions = HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
pangoro_runtime::api::dispatch(method, data)
Expand Down
17 changes: 11 additions & 6 deletions node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,17 @@ where
Ok((worker, telemetry))
})
.transpose()?;
let executor = sc_executor::NativeElseWasmExecutor::<Executor>::new(
config.wasm_method,
config.default_heap_pages,
config.max_runtime_instances,
config.runtime_cache_size,
);
let heap_pages =
config.default_heap_pages.map_or(sc_executor::DEFAULT_HEAP_ALLOC_STRATEGY, |h| {
sc_executor::HeapAllocStrategy::Static { extra_pages: h as _ }
});
let executor = sc_executor::WasmExecutor::<crate::service::HostFunctions>::builder()
.with_execution_method(config.wasm_method)
.with_max_runtime_instances(config.max_runtime_instances)
.with_runtime_cache_size(config.runtime_cache_size)
.with_onchain_heap_alloc_strategy(heap_pages)
.with_offchain_heap_alloc_strategy(heap_pages)
.build();
let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
config,
Expand Down

0 comments on commit 62e70e1

Please sign in to comment.