mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
Make choosing an executor (native/wasm) an explicit part of service construction (#9525)
* Split native executor stuff from wasm executor stuff * Remove `native_runtime_version` in places * Fix warning * Fix test warning * Remove redundant NativeRuntimeInfo trait * Add a warning for use_native * Run cargo fmt * Revert "Add a warning for use_native" This reverts commit 9494f765a06037e991dd60524f2ed1b14649bfd6. * Make choosing an executor (native/wasm) an explicit part of service construction * Add Cargo.lock * Rename Executor to ExecutorDispatch * Update bin/node/executor/src/lib.rs Co-authored-by: Squirrel <gilescope@gmail.com> * Fix tests * Fix minor node-executor error * Fix node cli command thing Co-authored-by: Squirrel <gilescope@gmail.com>
This commit is contained in:
@@ -72,6 +72,7 @@ sc-rpc = { version = "4.0.0-dev", path = "../../../client/rpc" }
|
||||
sc-basic-authorship = { version = "0.10.0-dev", path = "../../../client/basic-authorship" }
|
||||
sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../client/service" }
|
||||
sc-telemetry = { version = "4.0.0-dev", path = "../../../client/telemetry" }
|
||||
sc-executor = { version = "0.10.0-dev", path = "../../../client/executor" }
|
||||
sc-authority-discovery = { version = "0.10.0-dev", path = "../../../client/authority-discovery" }
|
||||
sc-sync-state-rpc = { version = "0.10.0-dev", path = "../../../client/sync-state-rpc" }
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{chain_spec, service, service::new_partial, Cli, Subcommand};
|
||||
use node_executor::Executor;
|
||||
use node_executor::ExecutorDispatch;
|
||||
use node_runtime::{Block, RuntimeApi};
|
||||
use sc_cli::{ChainSpec, Result, Role, RuntimeVersion, SubstrateCli};
|
||||
use sc_service::PartialComponents;
|
||||
@@ -87,13 +87,13 @@ pub fn run() -> Result<()> {
|
||||
Some(Subcommand::Inspect(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
|
||||
runner.sync_run(|config| cmd.run::<Block, RuntimeApi, Executor>(config))
|
||||
runner.sync_run(|config| cmd.run::<Block, RuntimeApi, ExecutorDispatch>(config))
|
||||
},
|
||||
Some(Subcommand::Benchmark(cmd)) =>
|
||||
if cfg!(feature = "runtime-benchmarks") {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
|
||||
runner.sync_run(|config| cmd.run::<Block, Executor>(config))
|
||||
runner.sync_run(|config| cmd.run::<Block, ExecutorDispatch>(config))
|
||||
} else {
|
||||
Err("Benchmarking wasn't enabled when building the node. \
|
||||
You can enable it with `--features runtime-benchmarks`."
|
||||
@@ -159,7 +159,7 @@ pub fn run() -> Result<()> {
|
||||
sc_service::TaskManager::new(config.task_executor.clone(), registry)
|
||||
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;
|
||||
|
||||
Ok((cmd.run::<Block, Executor>(config), task_manager))
|
||||
Ok((cmd.run::<Block, ExecutorDispatch>(config), task_manager))
|
||||
})
|
||||
},
|
||||
#[cfg(not(feature = "try-runtime"))]
|
||||
|
||||
@@ -21,23 +21,26 @@
|
||||
//! Service implementation. Specialized wrapper over substrate service.
|
||||
|
||||
use futures::prelude::*;
|
||||
use node_executor::Executor;
|
||||
use node_executor::ExecutorDispatch;
|
||||
use node_primitives::Block;
|
||||
use node_runtime::RuntimeApi;
|
||||
use sc_client_api::{ExecutorProvider, RemoteBackend};
|
||||
use sc_consensus_babe::{self, SlotProportion};
|
||||
use sc_executor::NativeElseWasmExecutor;
|
||||
use sc_network::{Event, NetworkService};
|
||||
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
|
||||
use sc_telemetry::{Telemetry, TelemetryWorker};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use std::sync::Arc;
|
||||
|
||||
type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
|
||||
type FullClient =
|
||||
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
|
||||
type FullBackend = sc_service::TFullBackend<Block>;
|
||||
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
|
||||
type FullGrandpaBlockImport =
|
||||
grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, FullSelectChain>;
|
||||
type LightClient = sc_service::TLightClient<Block, RuntimeApi, Executor>;
|
||||
type LightClient =
|
||||
sc_service::TLightClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
|
||||
|
||||
pub fn new_partial(
|
||||
config: &Configuration,
|
||||
@@ -75,10 +78,17 @@ pub fn new_partial(
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(
|
||||
config.wasm_method,
|
||||
config.default_heap_pages,
|
||||
config.max_runtime_instances,
|
||||
);
|
||||
|
||||
let (client, backend, keystore_container, task_manager) =
|
||||
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(
|
||||
sc_service::new_full_parts::<Block, RuntimeApi, _>(
|
||||
&config,
|
||||
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
|
||||
executor,
|
||||
)?;
|
||||
let client = Arc::new(client);
|
||||
|
||||
@@ -447,10 +457,17 @@ pub fn new_light_base(
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(
|
||||
config.wasm_method,
|
||||
config.default_heap_pages,
|
||||
config.max_runtime_instances,
|
||||
);
|
||||
|
||||
let (client, backend, keystore_container, mut task_manager, on_demand) =
|
||||
sc_service::new_light_parts::<Block, RuntimeApi, Executor>(
|
||||
sc_service::new_light_parts::<Block, RuntimeApi, _>(
|
||||
&config,
|
||||
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
|
||||
executor,
|
||||
)?;
|
||||
|
||||
let mut telemetry = telemetry.map(|(worker, telemetry)| {
|
||||
|
||||
@@ -18,14 +18,14 @@
|
||||
use codec::{Decode, Encode};
|
||||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
|
||||
use frame_support::Hashable;
|
||||
use node_executor::Executor;
|
||||
use node_executor::ExecutorDispatch;
|
||||
use node_primitives::{BlockNumber, Hash};
|
||||
use node_runtime::{
|
||||
constants::currency::*, Block, BuildStorage, Call, CheckedExtrinsic, GenesisConfig, Header,
|
||||
UncheckedExtrinsic,
|
||||
};
|
||||
use node_testing::keyring::*;
|
||||
use sc_executor::{Externalities, NativeExecutor, RuntimeVersionOf, WasmExecutionMethod};
|
||||
use sc_executor::{Externalities, NativeElseWasmExecutor, RuntimeVersionOf, WasmExecutionMethod};
|
||||
use sp_core::{
|
||||
storage::well_known_keys,
|
||||
traits::{CodeExecutor, RuntimeCode},
|
||||
@@ -77,7 +77,7 @@ fn new_test_ext(genesis_config: &GenesisConfig) -> TestExternalities<BlakeTwo256
|
||||
}
|
||||
|
||||
fn construct_block<E: Externalities>(
|
||||
executor: &NativeExecutor<Executor>,
|
||||
executor: &NativeElseWasmExecutor<ExecutorDispatch>,
|
||||
ext: &mut E,
|
||||
number: BlockNumber,
|
||||
parent_hash: Hash,
|
||||
@@ -157,7 +157,7 @@ fn construct_block<E: Externalities>(
|
||||
|
||||
fn test_blocks(
|
||||
genesis_config: &GenesisConfig,
|
||||
executor: &NativeExecutor<Executor>,
|
||||
executor: &NativeElseWasmExecutor<ExecutorDispatch>,
|
||||
) -> Vec<(Vec<u8>, Hash)> {
|
||||
let mut test_ext = new_test_ext(genesis_config);
|
||||
let mut block1_extrinsics = vec![CheckedExtrinsic {
|
||||
@@ -191,7 +191,7 @@ fn bench_execute_block(c: &mut Criterion) {
|
||||
ExecutionMethod::Wasm(wasm_method) => (false, wasm_method),
|
||||
};
|
||||
|
||||
let executor = NativeExecutor::new(wasm_method, None, 8);
|
||||
let executor = NativeElseWasmExecutor::new(wasm_method, None, 8);
|
||||
let runtime_code = RuntimeCode {
|
||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()),
|
||||
hash: vec![1, 2, 3],
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
//! A `CodeExecutor` specialization which uses natively compiled runtime when the wasm to be
|
||||
//! executed is equivalent to the natively compiled code.
|
||||
|
||||
pub use sc_executor::NativeExecutor;
|
||||
pub use sc_executor::NativeElseWasmExecutor;
|
||||
|
||||
// Declare an instance of the native executor named `Executor`. Include the wasm binary as the
|
||||
// equivalent wasm code.
|
||||
pub struct Executor;
|
||||
// Declare an instance of the native executor named `ExecutorDispatch`. Include the wasm binary as
|
||||
// the equivalent wasm code.
|
||||
pub struct ExecutorDispatch;
|
||||
|
||||
impl sc_executor::NativeExecutionDispatch for Executor {
|
||||
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
|
||||
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
|
||||
|
||||
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::Hashable;
|
||||
use frame_system::offchain::AppCrypto;
|
||||
use sc_executor::{error::Result, NativeExecutor, WasmExecutionMethod};
|
||||
use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutionMethod};
|
||||
use sp_consensus_babe::{
|
||||
digests::{PreDigest, SecondaryPlainPreDigest},
|
||||
Slot, BABE_ENGINE_ID,
|
||||
@@ -35,7 +35,7 @@ use sp_runtime::{
|
||||
};
|
||||
use sp_state_machine::TestExternalities as CoreTestExternalities;
|
||||
|
||||
use node_executor::Executor;
|
||||
use node_executor::ExecutorDispatch;
|
||||
use node_primitives::{BlockNumber, Hash};
|
||||
use node_runtime::{
|
||||
constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, Runtime,
|
||||
@@ -95,8 +95,8 @@ pub fn from_block_number(n: u32) -> Header {
|
||||
Header::new(n, Default::default(), Default::default(), [69; 32].into(), Default::default())
|
||||
}
|
||||
|
||||
pub fn executor() -> NativeExecutor<Executor> {
|
||||
NativeExecutor::new(WasmExecutionMethod::Interpreted, None, 8)
|
||||
pub fn executor() -> NativeElseWasmExecutor<ExecutorDispatch> {
|
||||
NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8)
|
||||
}
|
||||
|
||||
pub fn executor_call<
|
||||
|
||||
@@ -15,6 +15,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0" }
|
||||
derive_more = "0.99"
|
||||
sc-cli = { version = "0.10.0-dev", path = "../../../client/cli" }
|
||||
sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" }
|
||||
sc-executor = { version = "0.10.0-dev", path = "../../../client/executor" }
|
||||
sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../client/service" }
|
||||
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
|
||||
sp-core = { version = "4.0.0-dev", path = "../../../primitives/core" }
|
||||
|
||||
@@ -23,6 +23,7 @@ use crate::{
|
||||
Inspector,
|
||||
};
|
||||
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
|
||||
use sc_executor::NativeElseWasmExecutor;
|
||||
use sc_service::{new_full_client, Configuration, NativeExecutionDispatch};
|
||||
use sp_runtime::traits::Block;
|
||||
use std::str::FromStr;
|
||||
@@ -36,7 +37,13 @@ impl InspectCmd {
|
||||
RA: Send + Sync + 'static,
|
||||
EX: NativeExecutionDispatch + 'static,
|
||||
{
|
||||
let client = new_full_client::<B, RA, EX>(&config, None)?;
|
||||
let executor = NativeElseWasmExecutor::<EX>::new(
|
||||
config.wasm_method,
|
||||
config.default_heap_pages,
|
||||
config.max_runtime_instances,
|
||||
);
|
||||
|
||||
let client = new_full_client::<B, RA, _>(&config, None, executor)?;
|
||||
let inspect = Inspector::<B>::new(client);
|
||||
|
||||
match &self.command {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
use grandpa::GrandpaBlockImport;
|
||||
use sc_consensus_babe::BabeBlockImport;
|
||||
use sc_consensus_manual_seal::consensus::babe::SlotTimestampProvider;
|
||||
use sc_executor::NativeElseWasmExecutor;
|
||||
use sc_service::{TFullBackend, TFullClient};
|
||||
use sp_runtime::generic::Era;
|
||||
use test_runner::{ChainInfo, SignatureVerificationOverride};
|
||||
@@ -30,9 +31,9 @@ type BlockImport<B, BE, C, SC> = BabeBlockImport<B, C, GrandpaBlockImport<BE, B,
|
||||
|
||||
/// A unit struct which implements `NativeExecutionDispatch` feeding in the
|
||||
/// hard-coded runtime.
|
||||
pub struct Executor;
|
||||
pub struct ExecutorDispatch;
|
||||
|
||||
impl sc_executor::NativeExecutionDispatch for Executor {
|
||||
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
|
||||
type ExtendHostFunctions =
|
||||
(frame_benchmarking::benchmarking::HostFunctions, SignatureVerificationOverride);
|
||||
|
||||
@@ -50,14 +51,14 @@ struct NodeTemplateChainInfo;
|
||||
|
||||
impl ChainInfo for NodeTemplateChainInfo {
|
||||
type Block = node_primitives::Block;
|
||||
type Executor = Executor;
|
||||
type ExecutorDispatch = ExecutorDispatch;
|
||||
type Runtime = node_runtime::Runtime;
|
||||
type RuntimeApi = node_runtime::RuntimeApi;
|
||||
type SelectChain = sc_consensus::LongestChain<TFullBackend<Self::Block>, Self::Block>;
|
||||
type BlockImport = BlockImport<
|
||||
Self::Block,
|
||||
TFullBackend<Self::Block>,
|
||||
TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>,
|
||||
TFullClient<Self::Block, Self::RuntimeApi, NativeElseWasmExecutor<Self::ExecutorDispatch>>,
|
||||
Self::SelectChain,
|
||||
>;
|
||||
type SignedExtras = node_runtime::SignedExtra;
|
||||
|
||||
@@ -46,7 +46,7 @@ use sc_client_api::{
|
||||
};
|
||||
use sc_client_db::PruningMode;
|
||||
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, ImportedAux};
|
||||
use sc_executor::{NativeExecutor, WasmExecutionMethod};
|
||||
use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_block_builder::BlockBuilder;
|
||||
use sp_consensus::BlockOrigin;
|
||||
@@ -390,7 +390,7 @@ impl BenchDb {
|
||||
let backend = sc_service::new_db_backend(db_config).expect("Should not fail");
|
||||
let client = sc_service::new_client(
|
||||
backend.clone(),
|
||||
NativeExecutor::new(WasmExecutionMethod::Compiled, None, 8),
|
||||
NativeElseWasmExecutor::new(WasmExecutionMethod::Compiled, None, 8),
|
||||
&keyring.generate_genesis(),
|
||||
None,
|
||||
None,
|
||||
|
||||
@@ -24,7 +24,7 @@ use sp_runtime::BuildStorage;
|
||||
pub use substrate_test_client::*;
|
||||
|
||||
/// Call executor for `node-runtime` `TestClient`.
|
||||
pub type Executor = sc_executor::NativeExecutor<node_executor::Executor>;
|
||||
pub type ExecutorDispatch = sc_executor::NativeElseWasmExecutor<node_executor::ExecutorDispatch>;
|
||||
|
||||
/// Default backend type.
|
||||
pub type Backend = sc_client_db::Backend<node_primitives::Block>;
|
||||
@@ -32,7 +32,7 @@ pub type Backend = sc_client_db::Backend<node_primitives::Block>;
|
||||
/// Test client type.
|
||||
pub type Client = client::Client<
|
||||
Backend,
|
||||
client::LocalCallExecutor<node_primitives::Block, Backend, Executor>,
|
||||
client::LocalCallExecutor<node_primitives::Block, Backend, ExecutorDispatch>,
|
||||
node_primitives::Block,
|
||||
node_runtime::RuntimeApi,
|
||||
>;
|
||||
@@ -64,7 +64,7 @@ pub trait TestClientBuilderExt: Sized {
|
||||
impl TestClientBuilderExt
|
||||
for substrate_test_client::TestClientBuilder<
|
||||
node_primitives::Block,
|
||||
client::LocalCallExecutor<node_primitives::Block, Backend, Executor>,
|
||||
client::LocalCallExecutor<node_primitives::Block, Backend, ExecutorDispatch>,
|
||||
Backend,
|
||||
GenesisParameters,
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user