substrate-node: NativeElseWasmExecutor is no longer used (#2521)

This PR removes `NativeElseWasmExecutor` usage from substrate node.
Instead [`WasmExecutor<(sp_io::SubstrateHostFunctions,
sp_statement_store::runtime_api::HostFunctions)>`](https://github.com/paritytech/polkadot-sdk/blob/49a41ab3bb3f630c20e5b24cec8d92382404631c/substrate/bin/node/executor/src/lib.rs#L26)
is used.

Related to #2358.

---------

Co-authored-by: Davide Galassi <davxy@datawok.net>
This commit is contained in:
Michal Kucharczyk
2023-11-29 10:30:09 +01:00
committed by GitHub
parent 1d5d4a4840
commit 39d6c95c0d
19 changed files with 159 additions and 254 deletions
Generated
+17 -40
View File
@@ -8928,7 +8928,7 @@ dependencies = [
"sp-keyring", "sp-keyring",
"sp-runtime", "sp-runtime",
"sp-timestamp", "sp-timestamp",
"staging-node-executor", "staging-node-cli",
"substrate-test-client", "substrate-test-client",
"tempfile", "tempfile",
] ]
@@ -18358,7 +18358,9 @@ dependencies = [
"clap 4.4.6", "clap 4.4.6",
"clap_complete", "clap_complete",
"criterion 0.4.0", "criterion 0.4.0",
"frame-benchmarking",
"frame-benchmarking-cli", "frame-benchmarking-cli",
"frame-support",
"frame-system", "frame-system",
"frame-system-rpc-runtime-api", "frame-system-rpc-runtime-api",
"futures", "futures",
@@ -18368,13 +18370,20 @@ dependencies = [
"nix 0.26.2", "nix 0.26.2",
"node-primitives", "node-primitives",
"node-rpc", "node-rpc",
"node-testing",
"pallet-asset-conversion-tx-payment", "pallet-asset-conversion-tx-payment",
"pallet-asset-tx-payment", "pallet-asset-tx-payment",
"pallet-assets", "pallet-assets",
"pallet-balances", "pallet-balances",
"pallet-contracts",
"pallet-glutton",
"pallet-im-online", "pallet-im-online",
"pallet-root-testing",
"pallet-skip-feeless-payment", "pallet-skip-feeless-payment",
"pallet-sudo",
"pallet-timestamp", "pallet-timestamp",
"pallet-transaction-payment",
"pallet-treasury",
"parity-scale-codec", "parity-scale-codec",
"platforms", "platforms",
"rand 0.8.5", "rand 0.8.5",
@@ -18409,27 +18418,31 @@ dependencies = [
"sc-telemetry", "sc-telemetry",
"sc-transaction-pool", "sc-transaction-pool",
"sc-transaction-pool-api", "sc-transaction-pool-api",
"scale-info",
"serde", "serde",
"serde_json", "serde_json",
"soketto", "soketto",
"sp-api", "sp-api",
"sp-application-crypto",
"sp-authority-discovery", "sp-authority-discovery",
"sp-blockchain", "sp-blockchain",
"sp-consensus", "sp-consensus",
"sp-consensus-babe", "sp-consensus-babe",
"sp-consensus-grandpa", "sp-consensus-grandpa",
"sp-core", "sp-core",
"sp-externalities 0.19.0",
"sp-inherents", "sp-inherents",
"sp-io", "sp-io",
"sp-keyring", "sp-keyring",
"sp-keystore", "sp-keystore",
"sp-mixnet", "sp-mixnet",
"sp-runtime", "sp-runtime",
"sp-state-machine",
"sp-statement-store", "sp-statement-store",
"sp-timestamp", "sp-timestamp",
"sp-tracing 10.0.0", "sp-tracing 10.0.0",
"sp-transaction-storage-proof", "sp-transaction-storage-proof",
"staging-node-executor", "sp-trie",
"staging-node-inspect", "staging-node-inspect",
"substrate-build-script-utils", "substrate-build-script-utils",
"substrate-cli-test-utils", "substrate-cli-test-utils",
@@ -18440,44 +18453,6 @@ dependencies = [
"tokio-util", "tokio-util",
"try-runtime-cli", "try-runtime-cli",
"wait-timeout", "wait-timeout",
]
[[package]]
name = "staging-node-executor"
version = "3.0.0-dev"
dependencies = [
"criterion 0.4.0",
"frame-benchmarking",
"frame-support",
"frame-system",
"futures",
"kitchensink-runtime",
"node-primitives",
"node-testing",
"pallet-balances",
"pallet-contracts",
"pallet-glutton",
"pallet-im-online",
"pallet-root-testing",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-treasury",
"parity-scale-codec",
"sc-executor",
"scale-info",
"serde_json",
"sp-application-crypto",
"sp-consensus-babe",
"sp-core",
"sp-externalities 0.19.0",
"sp-keyring",
"sp-keystore",
"sp-runtime",
"sp-state-machine",
"sp-statement-store",
"sp-tracing 10.0.0",
"sp-trie",
"wat", "wat",
] ]
@@ -18492,7 +18467,9 @@ dependencies = [
"sc-service", "sc-service",
"sp-blockchain", "sp-blockchain",
"sp-core", "sp-core",
"sp-io",
"sp-runtime", "sp-runtime",
"sp-statement-store",
"thiserror", "thiserror",
] ]
-1
View File
@@ -200,7 +200,6 @@ members = [
"substrate/bin/node-template/runtime", "substrate/bin/node-template/runtime",
"substrate/bin/node/bench", "substrate/bin/node/bench",
"substrate/bin/node/cli", "substrate/bin/node/cli",
"substrate/bin/node/executor",
"substrate/bin/node/inspect", "substrate/bin/node/inspect",
"substrate/bin/node/primitives", "substrate/bin/node/primitives",
"substrate/bin/node/rpc", "substrate/bin/node/rpc",
@@ -5,35 +5,17 @@ use node_template_runtime::{self, opaque::Block, RuntimeApi};
use sc_client_api::{Backend, BlockBackend}; use sc_client_api::{Backend, BlockBackend};
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
use sc_consensus_grandpa::SharedVoterState; use sc_consensus_grandpa::SharedVoterState;
pub use sc_executor::NativeElseWasmExecutor;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams}; use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams};
use sc_telemetry::{Telemetry, TelemetryWorker}; use sc_telemetry::{Telemetry, TelemetryWorker};
use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use std::{sync::Arc, time::Duration}; use std::{sync::Arc, time::Duration};
// Our native executor instance. pub(crate) type FullClient = sc_service::TFullClient<
pub struct ExecutorDispatch; Block,
RuntimeApi,
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { sc_executor::WasmExecutor<sp_io::SubstrateHostFunctions>,
/// Only enable the benchmarking host functions when we actually want to benchmark. >;
#[cfg(feature = "runtime-benchmarks")]
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
/// Otherwise we only use the default Substrate host functions.
#[cfg(not(feature = "runtime-benchmarks"))]
type ExtendHostFunctions = ();
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
node_template_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
node_template_runtime::native_version()
}
}
pub(crate) type FullClient =
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
type FullBackend = sc_service::TFullBackend<Block>; type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>; type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
@@ -75,7 +57,7 @@ pub fn new_partial(
}) })
.transpose()?; .transpose()?;
let executor = sc_service::new_native_or_wasm_executor(config); let executor = sc_service::new_wasm_executor::<sp_io::SubstrateHostFunctions>(config);
let (client, backend, keystore_container, task_manager) = let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>( sc_service::new_full_parts::<Block, RuntimeApi, _>(
config, config,
+39 -1
View File
@@ -90,6 +90,7 @@ sc-storage-monitor = { path = "../../../client/storage-monitor" }
sc-offchain = { path = "../../../client/offchain" } sc-offchain = { path = "../../../client/offchain" }
# frame dependencies # frame dependencies
frame-benchmarking = { path = "../../../frame/benchmarking" }
frame-system = { path = "../../../frame/system" } frame-system = { path = "../../../frame/system" }
frame-system-rpc-runtime-api = { path = "../../../frame/system/rpc/runtime-api" } frame-system-rpc-runtime-api = { path = "../../../frame/system/rpc/runtime-api" }
pallet-assets = { path = "../../../frame/assets" } pallet-assets = { path = "../../../frame/assets" }
@@ -102,7 +103,6 @@ pallet-skip-feeless-payment = { path = "../../../frame/transaction-payment/skip-
kitchensink-runtime = { path = "../runtime" } kitchensink-runtime = { path = "../runtime" }
node-rpc = { path = "../rpc" } node-rpc = { path = "../rpc" }
node-primitives = { path = "../primitives" } node-primitives = { path = "../primitives" }
node-executor = { package = "staging-node-executor", path = "../executor" }
# CLI-specific dependencies # CLI-specific dependencies
sc-cli = { path = "../../../client/cli", optional = true} sc-cli = { path = "../../../client/cli", optional = true}
@@ -136,6 +136,26 @@ substrate-rpc-client = { path = "../../../utils/frame/rpc/client" }
pallet-timestamp = { path = "../../../frame/timestamp" } pallet-timestamp = { path = "../../../frame/timestamp" }
substrate-cli-test-utils = { path = "../../../test-utils/cli" } substrate-cli-test-utils = { path = "../../../test-utils/cli" }
wat = "1.0"
frame-support = { path = "../../../frame/support" }
node-testing = { path = "../testing" }
pallet-balances = { path = "../../../frame/balances" }
pallet-contracts = { path = "../../../frame/contracts" }
pallet-glutton = { path = "../../../frame/glutton" }
pallet-sudo = { path = "../../../frame/sudo" }
pallet-treasury = { path = "../../../frame/treasury" }
pallet-transaction-payment = { path = "../../../frame/transaction-payment" }
sp-application-crypto = { path = "../../../primitives/application-crypto" }
pallet-root-testing = { path = "../../../frame/root-testing" }
sp-consensus-babe = { path = "../../../primitives/consensus/babe" }
sp-externalities = { path = "../../../primitives/externalities" }
sp-keyring = { path = "../../../primitives/keyring" }
sp-runtime = { path = "../../../primitives/runtime" }
serde_json = "1.0.108"
scale-info = { version = "2.10.0", features = ["derive", "serde"] }
sp-trie = { path = "../../../primitives/trie" }
sp-state-machine = { path = "../../../primitives/state-machine" }
[build-dependencies] [build-dependencies]
clap = { version = "4.4.6", optional = true } clap = { version = "4.4.6", optional = true }
clap_complete = { version = "4.0.2", optional = true } clap_complete = { version = "4.0.2", optional = true }
@@ -163,14 +183,21 @@ cli = [
] ]
runtime-benchmarks = [ runtime-benchmarks = [
"frame-benchmarking-cli/runtime-benchmarks", "frame-benchmarking-cli/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks", "frame-system/runtime-benchmarks",
"kitchensink-runtime/runtime-benchmarks", "kitchensink-runtime/runtime-benchmarks",
"node-inspect?/runtime-benchmarks",
"pallet-asset-tx-payment/runtime-benchmarks", "pallet-asset-tx-payment/runtime-benchmarks",
"pallet-assets/runtime-benchmarks", "pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks", "pallet-balances/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-glutton/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks", "pallet-im-online/runtime-benchmarks",
"pallet-skip-feeless-payment/runtime-benchmarks", "pallet-skip-feeless-payment/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"sc-client-db/runtime-benchmarks", "sc-client-db/runtime-benchmarks",
"sc-service/runtime-benchmarks", "sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks",
@@ -178,15 +205,22 @@ runtime-benchmarks = [
# Enable features that allow the runtime to be tried and debugged. Name might be subject to change # Enable features that allow the runtime to be tried and debugged. Name might be subject to change
# in the near future. # in the near future.
try-runtime = [ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime", "frame-system/try-runtime",
"kitchensink-runtime/try-runtime", "kitchensink-runtime/try-runtime",
"pallet-asset-conversion-tx-payment/try-runtime", "pallet-asset-conversion-tx-payment/try-runtime",
"pallet-asset-tx-payment/try-runtime", "pallet-asset-tx-payment/try-runtime",
"pallet-assets/try-runtime", "pallet-assets/try-runtime",
"pallet-balances/try-runtime", "pallet-balances/try-runtime",
"pallet-contracts/try-runtime",
"pallet-glutton/try-runtime",
"pallet-im-online/try-runtime", "pallet-im-online/try-runtime",
"pallet-root-testing/try-runtime",
"pallet-skip-feeless-payment/try-runtime", "pallet-skip-feeless-payment/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime", "pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"sp-runtime/try-runtime", "sp-runtime/try-runtime",
"substrate-cli-test-utils/try-runtime", "substrate-cli-test-utils/try-runtime",
"try-runtime-cli/try-runtime", "try-runtime-cli/try-runtime",
@@ -199,3 +233,7 @@ harness = false
[[bench]] [[bench]]
name = "block_production" name = "block_production"
harness = false harness = false
[[bench]]
name = "executor"
harness = false
@@ -22,20 +22,16 @@ use kitchensink_runtime::{
constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, RuntimeCall, constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, RuntimeCall,
RuntimeGenesisConfig, UncheckedExtrinsic, RuntimeGenesisConfig, UncheckedExtrinsic,
}; };
use node_executor::ExecutorDispatch;
use node_primitives::{BlockNumber, Hash}; use node_primitives::{BlockNumber, Hash};
use node_testing::keyring::*; use node_testing::keyring::*;
use sc_executor::{ use sc_executor::{Externalities, RuntimeVersionOf};
Externalities, NativeElseWasmExecutor, RuntimeVersionOf, WasmExecutionMethod, WasmExecutor,
WasmtimeInstantiationStrategy,
};
use sp_core::{ use sp_core::{
storage::well_known_keys, storage::well_known_keys,
traits::{CallContext, CodeExecutor, RuntimeCode}, traits::{CallContext, CodeExecutor, RuntimeCode},
}; };
use sp_runtime::traits::BlakeTwo256; use sp_runtime::traits::BlakeTwo256;
use sp_state_machine::TestExternalities as CoreTestExternalities; use sp_state_machine::TestExternalities as CoreTestExternalities;
use staging_node_executor as node_executor; use staging_node_cli::service::RuntimeExecutor;
criterion_group!(benches, bench_execute_block); criterion_group!(benches, bench_execute_block);
criterion_main!(benches); criterion_main!(benches);
@@ -58,12 +54,6 @@ const HEAP_PAGES: u64 = 20;
type TestExternalities<H> = CoreTestExternalities<H>; type TestExternalities<H> = CoreTestExternalities<H>;
#[derive(Debug)]
enum ExecutionMethod {
Native,
Wasm(WasmExecutionMethod),
}
fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic { fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH) node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH)
} }
@@ -80,7 +70,7 @@ fn new_test_ext(genesis_config: &RuntimeGenesisConfig) -> TestExternalities<Blak
} }
fn construct_block<E: Externalities>( fn construct_block<E: Externalities>(
executor: &NativeElseWasmExecutor<ExecutorDispatch>, executor: &RuntimeExecutor,
ext: &mut E, ext: &mut E,
number: BlockNumber, number: BlockNumber,
parent_hash: Hash, parent_hash: Hash,
@@ -159,7 +149,7 @@ fn construct_block<E: Externalities>(
fn test_blocks( fn test_blocks(
genesis_config: &RuntimeGenesisConfig, genesis_config: &RuntimeGenesisConfig,
executor: &NativeElseWasmExecutor<ExecutorDispatch>, executor: &RuntimeExecutor,
) -> Vec<(Vec<u8>, Hash)> { ) -> Vec<(Vec<u8>, Hash)> {
let mut test_ext = new_test_ext(genesis_config); let mut test_ext = new_test_ext(genesis_config);
let mut block1_extrinsics = vec![CheckedExtrinsic { let mut block1_extrinsics = vec![CheckedExtrinsic {
@@ -181,56 +171,43 @@ fn test_blocks(
fn bench_execute_block(c: &mut Criterion) { fn bench_execute_block(c: &mut Criterion) {
let mut group = c.benchmark_group("execute blocks"); let mut group = c.benchmark_group("execute blocks");
let execution_methods = vec![
ExecutionMethod::Native,
ExecutionMethod::Wasm(WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
}),
];
for strategy in execution_methods { group.bench_function("wasm", |b| {
group.bench_function(format!("{:?}", strategy), |b| { let genesis_config = node_testing::genesis::config();
let genesis_config = node_testing::genesis::config();
let use_native = match strategy {
ExecutionMethod::Native => true,
ExecutionMethod::Wasm(..) => false,
};
let executor = let executor = RuntimeExecutor::builder().build();
NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()); let runtime_code = RuntimeCode {
let runtime_code = RuntimeCode { code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()),
code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()), hash: vec![1, 2, 3],
hash: vec![1, 2, 3], heap_pages: None,
heap_pages: None, };
};
// Get the runtime version to initialize the runtimes cache. // Get the runtime version to initialize the runtimes cache.
{ {
let mut test_ext = new_test_ext(&genesis_config); let mut test_ext = new_test_ext(&genesis_config);
executor.runtime_version(&mut test_ext.ext(), &runtime_code).unwrap(); executor.runtime_version(&mut test_ext.ext(), &runtime_code).unwrap();
} }
let blocks = test_blocks(&genesis_config, &executor); let blocks = test_blocks(&genesis_config, &executor);
b.iter_batched_ref( b.iter_batched_ref(
|| new_test_ext(&genesis_config), || new_test_ext(&genesis_config),
|test_ext| { |test_ext| {
for block in blocks.iter() { for block in blocks.iter() {
executor executor
.call( .call(
&mut test_ext.ext(), &mut test_ext.ext(),
&runtime_code, &runtime_code,
"Core_execute_block", "Core_execute_block",
&block.0, &block.0,
use_native, false,
CallContext::Offchain, CallContext::Offchain,
) )
.0 .0
.unwrap(); .unwrap();
} }
}, },
BatchSize::LargeInput, BatchSize::LargeInput,
); );
}); });
}
} }
+1 -2
View File
@@ -24,7 +24,6 @@ use crate::{
}; };
use frame_benchmarking_cli::*; use frame_benchmarking_cli::*;
use kitchensink_runtime::{ExistentialDeposit, RuntimeApi}; use kitchensink_runtime::{ExistentialDeposit, RuntimeApi};
use node_executor::ExecutorDispatch;
use node_primitives::Block; use node_primitives::Block;
use sc_cli::{Result, SubstrateCli}; use sc_cli::{Result, SubstrateCli};
use sc_service::PartialComponents; use sc_service::PartialComponents;
@@ -89,7 +88,7 @@ pub fn run() -> Result<()> {
Some(Subcommand::Inspect(cmd)) => { Some(Subcommand::Inspect(cmd)) => {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run::<Block, RuntimeApi, ExecutorDispatch>(config)) runner.sync_run(|config| cmd.run::<Block, RuntimeApi>(config))
}, },
Some(Subcommand::Benchmark(cmd)) => { Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
+19 -5
View File
@@ -26,11 +26,9 @@ use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
use frame_system_rpc_runtime_api::AccountNonceApi; use frame_system_rpc_runtime_api::AccountNonceApi;
use futures::prelude::*; use futures::prelude::*;
use kitchensink_runtime::RuntimeApi; use kitchensink_runtime::RuntimeApi;
use node_executor::ExecutorDispatch;
use node_primitives::Block; use node_primitives::Block;
use sc_client_api::{Backend, BlockBackend}; use sc_client_api::{Backend, BlockBackend};
use sc_consensus_babe::{self, SlotProportion}; use sc_consensus_babe::{self, SlotProportion};
use sc_executor::NativeElseWasmExecutor;
use sc_network::{event::Event, NetworkEventStream, NetworkService}; use sc_network::{event::Event, NetworkEventStream, NetworkService};
use sc_network_sync::{warp::WarpSyncParams, SyncingService}; use sc_network_sync::{warp::WarpSyncParams, SyncingService};
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager}; use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
@@ -42,9 +40,25 @@ use sp_core::crypto::Pair;
use sp_runtime::{generic, traits::Block as BlockT, SaturatedConversion}; use sp_runtime::{generic, traits::Block as BlockT, SaturatedConversion};
use std::sync::Arc; use std::sync::Arc;
/// Host functions required for kitchensink runtime and Substrate node.
#[cfg(not(feature = "runtime-benchmarks"))]
pub type HostFunctions =
(sp_io::SubstrateHostFunctions, sp_statement_store::runtime_api::HostFunctions);
/// Host functions required for kitchensink runtime and Substrate node.
#[cfg(feature = "runtime-benchmarks")]
pub type HostFunctions = (
sp_io::SubstrateHostFunctions,
sp_statement_store::runtime_api::HostFunctions,
frame_benchmarking::benchmarking::HostFunctions,
);
/// A specialized `WasmExecutor` intended to use accross substrate node. It provides all required
/// HostFunctions.
pub type RuntimeExecutor = sc_executor::WasmExecutor<HostFunctions>;
/// The full client type definition. /// The full client type definition.
pub type FullClient = pub type FullClient = sc_service::TFullClient<Block, RuntimeApi, RuntimeExecutor>;
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
type FullBackend = sc_service::TFullBackend<Block>; type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>; type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
type FullGrandpaBlockImport = type FullGrandpaBlockImport =
@@ -174,7 +188,7 @@ pub fn new_partial(
}) })
.transpose()?; .transpose()?;
let executor = sc_service::new_native_or_wasm_executor(&config); let executor = sc_service::new_wasm_executor(&config);
let (client, backend, keystore_container, task_manager) = let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>( sc_service::new_full_parts::<Block, RuntimeApi, _>(
@@ -18,7 +18,7 @@
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use frame_support::Hashable; use frame_support::Hashable;
use frame_system::offchain::AppCrypto; use frame_system::offchain::AppCrypto;
use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutor}; use sc_executor::error::Result;
use sp_consensus_babe::{ use sp_consensus_babe::{
digests::{PreDigest, SecondaryPlainPreDigest}, digests::{PreDigest, SecondaryPlainPreDigest},
Slot, BABE_ENGINE_ID, Slot, BABE_ENGINE_ID,
@@ -38,11 +38,10 @@ use kitchensink_runtime::{
constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, Runtime, constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, Runtime,
UncheckedExtrinsic, UncheckedExtrinsic,
}; };
use node_executor::ExecutorDispatch;
use node_primitives::{BlockNumber, Hash}; use node_primitives::{BlockNumber, Hash};
use node_testing::keyring::*; use node_testing::keyring::*;
use sp_externalities::Externalities; use sp_externalities::Externalities;
use staging_node_executor as node_executor; use staging_node_cli::service::RuntimeExecutor;
pub const TEST_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"test"); pub const TEST_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"test");
@@ -98,8 +97,8 @@ pub fn from_block_number(n: u32) -> Header {
Header::new(n, Default::default(), Default::default(), [69; 32].into(), Default::default()) Header::new(n, Default::default(), Default::default(), [69; 32].into(), Default::default())
} }
pub fn executor() -> NativeElseWasmExecutor<ExecutorDispatch> { pub fn executor() -> RuntimeExecutor {
NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) RuntimeExecutor::builder().build()
} }
pub fn executor_call( pub fn executor_call(
-57
View File
@@ -1,57 +0,0 @@
[package]
name = "staging-node-executor"
version = "3.0.0-dev"
authors.workspace = true
description = "Substrate node implementation in Rust."
edition.workspace = true
license = "Apache-2.0"
homepage = "https://substrate.io"
repository.workspace = true
publish = false
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1" }
scale-info = { version = "2.10.0", features = ["derive", "serde"] }
frame-benchmarking = { path = "../../../frame/benchmarking" }
node-primitives = { path = "../primitives" }
kitchensink-runtime = { path = "../runtime" }
sc-executor = { path = "../../../client/executor" }
sp-core = { path = "../../../primitives/core", features=["serde"] }
sp-keystore = { path = "../../../primitives/keystore" }
sp-state-machine = { path = "../../../primitives/state-machine" }
sp-tracing = { path = "../../../primitives/tracing" }
sp-trie = { path = "../../../primitives/trie" }
sp-statement-store = { path = "../../../primitives/statement-store", features=["serde"] }
[dev-dependencies]
criterion = "0.4.0"
futures = "0.3.21"
wat = "1.0"
frame-support = { path = "../../../frame/support" }
frame-system = { path = "../../../frame/system" }
node-testing = { path = "../testing" }
pallet-balances = { path = "../../../frame/balances" }
pallet-contracts = { path = "../../../frame/contracts" }
pallet-im-online = { path = "../../../frame/im-online" }
pallet-glutton = { path = "../../../frame/glutton" }
pallet-sudo = { path = "../../../frame/sudo" }
pallet-timestamp = { path = "../../../frame/timestamp" }
pallet-treasury = { path = "../../../frame/treasury" }
pallet-transaction-payment = { path = "../../../frame/transaction-payment" }
sp-application-crypto = { path = "../../../primitives/application-crypto" }
pallet-root-testing = { path = "../../../frame/root-testing" }
sp-consensus-babe = { path = "../../../primitives/consensus/babe" }
sp-externalities = { path = "../../../primitives/externalities" }
sp-keyring = { path = "../../../primitives/keyring" }
sp-runtime = { path = "../../../primitives/runtime" }
serde_json = "1.0.108"
[features]
stress-test = []
[[bench]]
name = "bench"
harness = false
-40
View File
@@ -1,40 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! 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::NativeElseWasmExecutor;
// 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 ExecutorDispatch {
type ExtendHostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
sp_statement_store::runtime_api::HostFunctions,
);
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
kitchensink_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
kitchensink_runtime::native_version()
}
}
+8
View File
@@ -20,4 +20,12 @@ sc-client-api = { path = "../../../client/api" }
sc-service = { path = "../../../client/service", default-features = false} sc-service = { path = "../../../client/service", default-features = false}
sp-blockchain = { path = "../../../primitives/blockchain" } sp-blockchain = { path = "../../../primitives/blockchain" }
sp-core = { path = "../../../primitives/core" } sp-core = { path = "../../../primitives/core" }
sp-io = { path = "../../../primitives/io" }
sp-runtime = { path = "../../../primitives/runtime" } sp-runtime = { path = "../../../primitives/runtime" }
sp-statement-store = { path = "../../../primitives/statement-store" }
[features]
runtime-benchmarks = [
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
+6 -4
View File
@@ -23,18 +23,20 @@ use crate::{
Inspector, Inspector,
}; };
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams}; use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
use sc_service::{Configuration, NativeExecutionDispatch}; use sc_service::Configuration;
use sp_runtime::traits::Block; use sp_runtime::traits::Block;
type HostFunctions =
(sp_io::SubstrateHostFunctions, sp_statement_store::runtime_api::HostFunctions);
impl InspectCmd { impl InspectCmd {
/// Run the inspect command, passing the inspector. /// Run the inspect command, passing the inspector.
pub fn run<B, RA, D>(&self, config: Configuration) -> Result<()> pub fn run<B, RA>(&self, config: Configuration) -> Result<()>
where where
B: Block, B: Block,
RA: Send + Sync + 'static, RA: Send + Sync + 'static,
D: NativeExecutionDispatch + 'static,
{ {
let executor = sc_service::new_native_or_wasm_executor::<D>(&config); let executor = sc_service::new_wasm_executor::<HostFunctions>(&config);
let client = sc_service::new_full_client::<B, RA, _>(&config, None, executor)?; let client = sc_service::new_full_client::<B, RA, _>(&config, None, executor)?;
let inspect = Inspector::<B>::new(client); let inspect = Inspector::<B>::new(client);
+1 -1
View File
@@ -19,7 +19,7 @@ futures = "0.3.21"
log = "0.4.17" log = "0.4.17"
tempfile = "3.1.0" tempfile = "3.1.0"
frame-system = { path = "../../../frame/system" } frame-system = { path = "../../../frame/system" }
node-executor = { package = "staging-node-executor", path = "../executor" } node-cli = { package = "staging-node-cli", path = "../cli" }
node-primitives = { path = "../primitives" } node-primitives = { path = "../primitives" }
kitchensink-runtime = { path = "../runtime" } kitchensink-runtime = { path = "../runtime" }
pallet-asset-conversion = { path = "../../../frame/asset-conversion" } pallet-asset-conversion = { path = "../../../frame/asset-conversion" }
+6 -8
View File
@@ -43,7 +43,7 @@ use sc_block_builder::BlockBuilderBuilder;
use sc_client_api::{execution_extensions::ExecutionExtensions, UsageProvider}; use sc_client_api::{execution_extensions::ExecutionExtensions, UsageProvider};
use sc_client_db::PruningMode; use sc_client_db::PruningMode;
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, ImportedAux}; use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, ImportedAux};
use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmtimeInstantiationStrategy}; use sc_executor::{WasmExecutionMethod, WasmtimeInstantiationStrategy};
use sp_api::ProvideRuntimeApi; use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder; use sp_block_builder::BlockBuilder;
use sp_consensus::BlockOrigin; use sp_consensus::BlockOrigin;
@@ -388,13 +388,11 @@ impl BenchDb {
let task_executor = TaskExecutor::new(); let task_executor = TaskExecutor::new();
let backend = sc_service::new_db_backend(db_config).expect("Should not fail"); let backend = sc_service::new_db_backend(db_config).expect("Should not fail");
let executor = NativeElseWasmExecutor::new_with_wasm_executor( let executor = sc_executor::WasmExecutor::builder()
sc_executor::WasmExecutor::builder() .with_execution_method(WasmExecutionMethod::Compiled {
.with_execution_method(WasmExecutionMethod::Compiled { instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite, })
}) .build();
.build(),
);
let client_config = sc_service::ClientConfig::default(); let client_config = sc_service::ClientConfig::default();
let genesis_block_builder = sc_service::GenesisBlockBuilder::new( let genesis_block_builder = sc_service::GenesisBlockBuilder::new(
+14 -5
View File
@@ -23,7 +23,7 @@ use sp_runtime::BuildStorage;
pub use substrate_test_client::*; pub use substrate_test_client::*;
/// Call executor for `kitchensink-runtime` `TestClient`. /// Call executor for `kitchensink-runtime` `TestClient`.
pub type ExecutorDispatch = sc_executor::NativeElseWasmExecutor<node_executor::ExecutorDispatch>; use node_cli::service::RuntimeExecutor;
/// Default backend type. /// Default backend type.
pub type Backend = sc_client_db::Backend<node_primitives::Block>; pub type Backend = sc_client_db::Backend<node_primitives::Block>;
@@ -31,7 +31,7 @@ pub type Backend = sc_client_db::Backend<node_primitives::Block>;
/// Test client type. /// Test client type.
pub type Client = client::Client< pub type Client = client::Client<
Backend, Backend,
client::LocalCallExecutor<node_primitives::Block, Backend, ExecutorDispatch>, client::LocalCallExecutor<node_primitives::Block, Backend, RuntimeExecutor>,
node_primitives::Block, node_primitives::Block,
kitchensink_runtime::RuntimeApi, kitchensink_runtime::RuntimeApi,
>; >;
@@ -63,7 +63,7 @@ pub trait TestClientBuilderExt: Sized {
impl TestClientBuilderExt impl TestClientBuilderExt
for substrate_test_client::TestClientBuilder< for substrate_test_client::TestClientBuilder<
node_primitives::Block, node_primitives::Block,
client::LocalCallExecutor<node_primitives::Block, Backend, ExecutorDispatch>, client::LocalCallExecutor<node_primitives::Block, Backend, RuntimeExecutor>,
Backend, Backend,
GenesisParameters, GenesisParameters,
> >
@@ -71,8 +71,17 @@ impl TestClientBuilderExt
fn new() -> Self { fn new() -> Self {
Self::default() Self::default()
} }
fn build(self) -> Client { fn build(self) -> Client {
self.build_with_native_executor(None).0 let executor = RuntimeExecutor::builder().build();
use sc_service::client::LocalCallExecutor;
use std::sync::Arc;
let executor = LocalCallExecutor::new(
self.backend().clone(),
executor.clone(),
Default::default(),
ExecutionExtensions::new(None, Arc::new(executor)),
)
.expect("Creates LocalCallExecutor");
self.build_with_executor(executor).0
} }
} }