Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

substrate-node: NativeElseWasmExecutor is no longer used #2521

Merged
merged 13 commits into from
Nov 29, 2023
Merged
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions substrate/bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::{
};
use frame_benchmarking_cli::*;
use kitchensink_runtime::{ExistentialDeposit, RuntimeApi};
use node_executor::ExecutorDispatch;
use node_primitives::Block;
use sc_cli::{Result, SubstrateCli};
use sc_service::PartialComponents;
Expand Down Expand Up @@ -89,7 +88,7 @@ pub fn run() -> Result<()> {
Some(Subcommand::Inspect(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)) => {
let runner = cli.create_runner(cmd)?;
Expand Down
8 changes: 3 additions & 5 deletions substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
use frame_system_rpc_runtime_api::AccountNonceApi;
use futures::prelude::*;
use kitchensink_runtime::RuntimeApi;
use node_executor::ExecutorDispatch;
use node_executor::ClientWasmExecutor;
use node_primitives::Block;
use sc_client_api::{Backend, BlockBackend};
use sc_consensus_babe::{self, SlotProportion};
use sc_executor::NativeElseWasmExecutor;
use sc_network::{event::Event, NetworkEventStream, NetworkService};
use sc_network_sync::{warp::WarpSyncParams, SyncingService};
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
Expand All @@ -43,8 +42,7 @@ use sp_runtime::{generic, traits::Block as BlockT, SaturatedConversion};
use std::sync::Arc;

/// The full client type definition.
pub type FullClient =
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
pub type FullClient = sc_service::TFullClient<Block, RuntimeApi, ClientWasmExecutor>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
type FullGrandpaBlockImport =
Expand Down Expand Up @@ -174,7 +172,7 @@ pub fn new_partial(
})
.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) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ node-primitives = { path = "../primitives" }
kitchensink-runtime = { path = "../runtime" }
sc-executor = { path = "../../../client/executor" }
sp-core = { path = "../../../primitives/core", features=["serde"] }
sp-io = { path = "../../../primitives/io" }
sp-keystore = { path = "../../../primitives/keystore" }
sp-state-machine = { path = "../../../primitives/state-machine" }
sp-tracing = { path = "../../../primitives/tracing" }
Expand Down
12 changes: 5 additions & 7 deletions substrate/bin/node/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ use kitchensink_runtime::{
constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, RuntimeCall,
RuntimeGenesisConfig, UncheckedExtrinsic,
};
use node_executor::ExecutorDispatch;
use node_executor::ClientWasmExecutor;
use node_primitives::{BlockNumber, Hash};
use node_testing::keyring::*;
use sc_executor::{
Externalities, NativeElseWasmExecutor, RuntimeVersionOf, WasmExecutionMethod, WasmExecutor,
WasmtimeInstantiationStrategy,
Externalities, RuntimeVersionOf, WasmExecutionMethod, WasmtimeInstantiationStrategy,
};
use sp_core::{
storage::well_known_keys,
Expand Down Expand Up @@ -80,7 +79,7 @@ fn new_test_ext(genesis_config: &RuntimeGenesisConfig) -> TestExternalities<Blak
}

fn construct_block<E: Externalities>(
executor: &NativeElseWasmExecutor<ExecutorDispatch>,
executor: &ClientWasmExecutor,
ext: &mut E,
number: BlockNumber,
parent_hash: Hash,
Expand Down Expand Up @@ -159,7 +158,7 @@ fn construct_block<E: Externalities>(

fn test_blocks(
genesis_config: &RuntimeGenesisConfig,
executor: &NativeElseWasmExecutor<ExecutorDispatch>,
executor: &ClientWasmExecutor,
) -> Vec<(Vec<u8>, Hash)> {
let mut test_ext = new_test_ext(genesis_config);
let mut block1_extrinsics = vec![CheckedExtrinsic {
Expand Down Expand Up @@ -196,8 +195,7 @@ fn bench_execute_block(c: &mut Criterion) {
ExecutionMethod::Wasm(..) => false,
};

let executor =
NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build());
let executor = ClientWasmExecutor::builder().build();
let runtime_code = RuntimeCode {
code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()),
hash: vec![1, 2, 3],
Expand Down
28 changes: 7 additions & 21 deletions substrate/bin/node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,12 @@
// 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.
//! Provides executor related types intended to use accross substrate node.
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved

pub use sc_executor::NativeElseWasmExecutor;
/// Host functions required for kitchensink runtime and substrate node.
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
pub type HostFunctions =
davxy marked this conversation as resolved.
Show resolved Hide resolved
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
(sp_io::SubstrateHostFunctions, sp_statement_store::runtime_api::HostFunctions);

// 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()
}
}
/// A specialized `WasmExecutor` intended to use accross substrate node. It provides all required
/// HostFunctions.
pub type ClientWasmExecutor = sc_executor::WasmExecutor<HostFunctions>;
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 4 additions & 5 deletions substrate/bin/node/executor/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use codec::{Decode, Encode};
use frame_support::Hashable;
use frame_system::offchain::AppCrypto;
use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutor};
use sc_executor::error::Result;
use sp_consensus_babe::{
digests::{PreDigest, SecondaryPlainPreDigest},
Slot, BABE_ENGINE_ID,
Expand All @@ -38,11 +38,10 @@ use kitchensink_runtime::{
constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, Runtime,
UncheckedExtrinsic,
};
use node_executor::ExecutorDispatch;
use node_primitives::{BlockNumber, Hash};
use node_testing::keyring::*;
use sp_externalities::Externalities;
use staging_node_executor as node_executor;
use staging_node_executor::ClientWasmExecutor;

pub const TEST_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"test");

Expand Down Expand Up @@ -98,8 +97,8 @@ pub fn from_block_number(n: u32) -> Header {
Header::new(n, Default::default(), Default::default(), [69; 32].into(), Default::default())
}

pub fn executor() -> NativeElseWasmExecutor<ExecutorDispatch> {
NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build())
pub fn executor() -> ClientWasmExecutor {
ClientWasmExecutor::builder().build()
}

pub fn executor_call(
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/inspect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
clap = { version = "4.4.6", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.6.1" }
thiserror = "1.0"
node-executor = { package = "staging-node-executor", path = "../executor" }
sc-cli = { path = "../../../client/cli" }
sc-client-api = { path = "../../../client/api" }
sc-service = { path = "../../../client/service", default-features = false}
Expand Down
7 changes: 3 additions & 4 deletions substrate/bin/node/inspect/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ use crate::{
Inspector,
};
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
use sc_service::{Configuration, NativeExecutionDispatch};
use sc_service::Configuration;
use sp_runtime::traits::Block;

impl InspectCmd {
/// 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
B: Block,
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::<node_executor::HostFunctions>(&config);
let client = sc_service::new_full_client::<B, RA, _>(&config, None, executor)?;
let inspect = Inspector::<B>::new(client);

Expand Down
14 changes: 6 additions & 8 deletions substrate/bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use sc_block_builder::BlockBuilderBuilder;
use sc_client_api::{execution_extensions::ExecutionExtensions, UsageProvider};
use sc_client_db::PruningMode;
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_block_builder::BlockBuilder;
use sp_consensus::BlockOrigin;
Expand Down Expand Up @@ -388,13 +388,11 @@ impl BenchDb {
let task_executor = TaskExecutor::new();

let backend = sc_service::new_db_backend(db_config).expect("Should not fail");
let executor = NativeElseWasmExecutor::new_with_wasm_executor(
sc_executor::WasmExecutor::builder()
.with_execution_method(WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
})
.build(),
);
let executor = sc_executor::WasmExecutor::builder()
.with_execution_method(WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
})
.build();

let client_config = sc_service::ClientConfig::default();
let genesis_block_builder = sc_service::GenesisBlockBuilder::new(
Expand Down
19 changes: 14 additions & 5 deletions substrate/bin/node/testing/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ use sp_runtime::BuildStorage;
pub use substrate_test_client::*;

/// Call executor for `kitchensink-runtime` `TestClient`.
pub type ExecutorDispatch = sc_executor::NativeElseWasmExecutor<node_executor::ExecutorDispatch>;
use node_executor::ClientWasmExecutor;

/// Default backend type.
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, ExecutorDispatch>,
client::LocalCallExecutor<node_primitives::Block, Backend, ClientWasmExecutor>,
node_primitives::Block,
kitchensink_runtime::RuntimeApi,
>;
Expand Down Expand Up @@ -63,16 +63,25 @@ pub trait TestClientBuilderExt: Sized {
impl TestClientBuilderExt
for substrate_test_client::TestClientBuilder<
node_primitives::Block,
client::LocalCallExecutor<node_primitives::Block, Backend, ExecutorDispatch>,
client::LocalCallExecutor<node_primitives::Block, Backend, ClientWasmExecutor>,
Backend,
GenesisParameters,
>
{
fn new() -> Self {
Self::default()
}

fn build(self) -> Client {
self.build_with_native_executor(None).0
let executor = ClientWasmExecutor::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
}
}
Loading