Skip to content

Commit

Permalink
remove NativeElseWasmExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci committed Aug 8, 2024
1 parent bbfaff4 commit b3e589a
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 242 deletions.
112 changes: 52 additions & 60 deletions bin/collator/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::{
cli::{Cli, RelayChainCli, Subcommand},
local::{self, development_config},
parachain::{
self, astar, chain_spec, service::AdditionalConfig, shibuya, shiden, start_astar_node,
start_shibuya_node, start_shiden_node,
self, chain_spec, service::AdditionalConfig, start_astar_node, start_shibuya_node,
start_shiden_node,
},
};
use cumulus_primitives_core::ParaId;
Expand Down Expand Up @@ -205,7 +205,7 @@ pub fn run() -> Result<()> {
task_manager,
import_queue,
..
} = parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
} = parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -218,7 +218,7 @@ pub fn run() -> Result<()> {
task_manager,
import_queue,
..
} = parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
} = parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;
Expand All @@ -231,7 +231,7 @@ pub fn run() -> Result<()> {
task_manager,
import_queue,
..
} = parachain::new_partial::<shibuya::RuntimeApi, shibuya::Executor, _>(
} = parachain::new_partial::<shibuya_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -247,7 +247,7 @@ pub fn run() -> Result<()> {
client,
task_manager,
..
} = parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
} = parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -259,7 +259,7 @@ pub fn run() -> Result<()> {
client,
task_manager,
..
} = parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
} = parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;
Expand All @@ -271,7 +271,7 @@ pub fn run() -> Result<()> {
client,
task_manager,
..
} = parachain::new_partial::<shibuya::RuntimeApi, shibuya::Executor, _>(
} = parachain::new_partial::<shibuya_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -287,7 +287,7 @@ pub fn run() -> Result<()> {
client,
task_manager,
..
} = parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
} = parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -299,7 +299,7 @@ pub fn run() -> Result<()> {
client,
task_manager,
..
} = parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
} = parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;
Expand All @@ -311,7 +311,7 @@ pub fn run() -> Result<()> {
client,
task_manager,
..
} = parachain::new_partial::<shibuya::RuntimeApi, shibuya::Executor, _>(
} = parachain::new_partial::<shibuya_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -328,7 +328,7 @@ pub fn run() -> Result<()> {
task_manager,
import_queue,
..
} = parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
} = parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -341,7 +341,7 @@ pub fn run() -> Result<()> {
task_manager,
import_queue,
..
} = parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
} = parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;
Expand All @@ -354,7 +354,7 @@ pub fn run() -> Result<()> {
task_manager,
import_queue,
..
} = parachain::new_partial::<shibuya::RuntimeApi, shibuya::Executor, _>(
} = parachain::new_partial::<shibuya_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand Down Expand Up @@ -390,7 +390,7 @@ pub fn run() -> Result<()> {
task_manager,
backend,
..
} = parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
} = parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -407,7 +407,7 @@ pub fn run() -> Result<()> {
task_manager,
backend,
..
} = parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
} = parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;
Expand All @@ -424,7 +424,7 @@ pub fn run() -> Result<()> {
task_manager,
backend,
..
} = parachain::new_partial::<shibuya::RuntimeApi, shibuya::Executor, _>(
} = parachain::new_partial::<shibuya_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -441,7 +441,7 @@ pub fn run() -> Result<()> {
if runner.config().chain_spec.is_astar() {
runner.sync_run(|config| {
let PartialComponents { client, .. } =
parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand All @@ -450,7 +450,7 @@ pub fn run() -> Result<()> {
} else if runner.config().chain_spec.is_shiden() {
runner.sync_run(|config| {
let PartialComponents { client, .. } =
parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;
Expand All @@ -459,7 +459,7 @@ pub fn run() -> Result<()> {
} else {
runner.sync_run(|config| {
let PartialComponents { client, .. } =
parachain::new_partial::<shibuya::RuntimeApi, shibuya::Executor, _>(
parachain::new_partial::<shibuya_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
Expand Down Expand Up @@ -519,20 +519,18 @@ pub fn run() -> Result<()> {
BenchmarkCmd::Block(cmd) => {
if chain_spec.is_astar() {
runner.sync_run(|config| {
let params =
parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
&config,
parachain::build_import_queue,
)?;
let params = parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
cmd.run(params.client)
})
} else if chain_spec.is_shiden() {
runner.sync_run(|config| {
let params =
parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
&config,
parachain::build_import_queue_fallback,
)?;
let params = parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;
cmd.run(params.client)
})
} else if chain_spec.is_shibuya() {
Expand All @@ -556,23 +554,21 @@ pub fn run() -> Result<()> {
BenchmarkCmd::Storage(cmd) => {
if chain_spec.is_astar() {
runner.sync_run(|config| {
let params =
parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
&config,
parachain::build_import_queue,
)?;
let params = parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
let db = params.backend.expose_db();
let storage = params.backend.expose_storage();

cmd.run(config, params.client, db, storage)
})
} else if chain_spec.is_shiden() {
runner.sync_run(|config| {
let params =
parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
&config,
parachain::build_import_queue_fallback,
)?;
let params = parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;
let db = params.backend.expose_db();
let storage = params.backend.expose_storage();

Expand Down Expand Up @@ -605,11 +601,10 @@ pub fn run() -> Result<()> {
BenchmarkCmd::Overhead(cmd) => {
if chain_spec.is_astar() {
runner.sync_run(|config| {
let params =
parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
&config,
parachain::build_import_queue,
)?;
let params = parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
let ext_builder = RemarkBuilder::new(params.client.clone());
let inherent_data = para_benchmark_inherent_data()
.map_err(|e| format!("generating inherent data: {:?}", e))?;
Expand All @@ -624,11 +619,10 @@ pub fn run() -> Result<()> {
})
} else if chain_spec.is_shiden() {
runner.sync_run(|config| {
let params =
parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
&config,
parachain::build_import_queue_fallback,
)?;
let params = parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;

let ext_builder = RemarkBuilder::new(params.client.clone());
let inherent_data = para_benchmark_inherent_data()
Expand Down Expand Up @@ -684,11 +678,10 @@ pub fn run() -> Result<()> {
BenchmarkCmd::Extrinsic(cmd) => {
if chain_spec.is_astar() {
runner.sync_run(|config| {
let params =
parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
&config,
parachain::build_import_queue,
)?;
let params = parachain::new_partial::<astar_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue,
)?;
let remark_builder = RemarkBuilder::new(params.client.clone());
let tka_builder = TransferKeepAliveBuilder::new(
params.client.clone(),
Expand All @@ -706,11 +699,10 @@ pub fn run() -> Result<()> {
})
} else if chain_spec.is_shiden() {
runner.sync_run(|config| {
let params =
parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
&config,
parachain::build_import_queue_fallback,
)?;
let params = parachain::new_partial::<shiden_runtime::RuntimeApi, _>(
&config,
parachain::build_import_queue_fallback,
)?;
let remark_builder = RemarkBuilder::new(params.client.clone());
let tka_builder = TransferKeepAliveBuilder::new(
params.client.clone(),
Expand Down
2 changes: 1 addition & 1 deletion bin/collator/src/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ mod service;
mod chain_spec;

pub use chain_spec::*;
pub use service::{new_partial, start_node, Executor, HostFunctions, RuntimeApi};
pub use service::{new_partial, start_node, HostFunctions, RuntimeApi};
49 changes: 22 additions & 27 deletions bin/collator/src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use fc_storage::StorageOverrideHandler;
use futures::{FutureExt, StreamExt};
use sc_client_api::{Backend, BlockBackend, BlockchainEvents};
use sc_consensus_grandpa::SharedVoterState;
use sc_executor::NativeElseWasmExecutor;
use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY};
use sc_network::NetworkBackend;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
use sc_telemetry::{Telemetry, TelemetryWorker};
Expand All @@ -46,37 +46,20 @@ use astar_primitives::*;
/// imported and generated.
const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512;

/// Extra host functions
#[cfg(feature = "runtime-benchmarks")]
pub type HostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
// evm tracing host functions
moonbeam_primitives_ext::moonbeam_ext::HostFunctions,
);

/// Extra host functions
#[cfg(not(feature = "runtime-benchmarks"))]
/// Parachain host functions
#[cfg(feature = "evm-tracing")]
pub type HostFunctions = (
// evm tracing host functions
cumulus_client_service::ParachainHostFunctions,
moonbeam_primitives_ext::moonbeam_ext::HostFunctions,
);

/// Local runtime native executor.
pub struct Executor;
/// Parachain host functions
#[cfg(not(feature = "evm-tracing"))]
pub type HostFunctions = (cumulus_client_service::ParachainHostFunctions,);

impl sc_executor::NativeExecutionDispatch for Executor {
type ExtendHostFunctions = HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
local_runtime::api::dispatch(method, data)
}

fn native_version() -> sc_executor::NativeVersion {
local_runtime::native_version()
}
}
type ParachainExecutor = WasmExecutor<HostFunctions>;

type FullClient = sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>;
type FullClient = sc_service::TFullClient<Block, RuntimeApi, ParachainExecutor>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

Expand Down Expand Up @@ -119,7 +102,19 @@ pub fn new_partial(
})
.transpose()?;

let executor = sc_service::new_native_or_wasm_executor(&config);
let heap_pages = config
.default_heap_pages
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static {
extra_pages: h as _,
});

let executor = ParachainExecutor::builder()
.with_execution_method(config.wasm_method)
.with_onchain_heap_alloc_strategy(heap_pages)
.with_offchain_heap_alloc_strategy(heap_pages)
.with_max_runtime_instances(config.max_runtime_instances)
.with_runtime_cache_size(config.runtime_cache_size)
.build();

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts_record_import::<Block, RuntimeApi, _>(
Expand Down
4 changes: 2 additions & 2 deletions bin/collator/src/parachain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub mod service;
pub mod chain_spec;

pub use service::{
astar, build_import_queue, build_import_queue_fallback, new_partial, shibuya, shiden,
start_astar_node, start_shibuya_node, start_shiden_node, HostFunctions,
build_import_queue, build_import_queue_fallback, new_partial, start_astar_node,
start_shibuya_node, start_shiden_node, HostFunctions,
};

pub(crate) use shell_upgrade::{
Expand Down
Loading

0 comments on commit b3e589a

Please sign in to comment.