Skip to content

Commit

Permalink
Revert "substrate-node: NativeElseWasmExecutor is no longer used (p…
Browse files Browse the repository at this point in the history
…aritytech#2521)"

This reverts commit 39d6c95.
  • Loading branch information
RomarQ committed Mar 20, 2024
1 parent 54d0501 commit 89cbe04
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 131 deletions.
45 changes: 41 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ members = [
"substrate/bin/node-template/runtime",
"substrate/bin/node/bench",
"substrate/bin/node/cli",
"substrate/bin/node/executor",
"substrate/bin/node/inspect",
"substrate/bin/node/primitives",
"substrate/bin/node/rpc",
Expand Down
30 changes: 24 additions & 6 deletions substrate/bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,35 @@ use node_template_runtime::{self, opaque::Block, RuntimeApi};
use sc_client_api::{Backend, BlockBackend};
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
use sc_consensus_grandpa::SharedVoterState;
pub use sc_executor::NativeElseWasmExecutor;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use std::{sync::Arc, time::Duration};

pub(crate) type FullClient = sc_service::TFullClient<
Block,
RuntimeApi,
sc_executor::WasmExecutor<sp_io::SubstrateHostFunctions>,
>;
// Our native executor instance.
pub struct ExecutorDispatch;

impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
/// 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 FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

Expand Down Expand Up @@ -48,7 +66,7 @@ pub fn new_partial(config: &Configuration) -> Result<Service, ServiceError> {
})
.transpose()?;

let executor = sc_service::new_wasm_executor::<sp_io::SubstrateHostFunctions>(config);
let executor = sc_service::new_native_or_wasm_executor(config);
let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
config,
Expand Down
20 changes: 1 addition & 19 deletions substrate/bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ sc-storage-monitor = { path = "../../../client/storage-monitor" }
sc-offchain = { path = "../../../client/offchain" }

# frame dependencies
frame-benchmarking = { path = "../../../frame/benchmarking" }
frame-system = { path = "../../../frame/system" }
frame-system-rpc-runtime-api = { path = "../../../frame/system/rpc/runtime-api" }
pallet-assets = { path = "../../../frame/assets" }
Expand All @@ -110,6 +109,7 @@ pallet-skip-feeless-payment = { path = "../../../frame/transaction-payment/skip-
kitchensink-runtime = { path = "../runtime" }
node-rpc = { path = "../rpc" }
node-primitives = { path = "../primitives" }
node-executor = { package = "staging-node-executor", path = "../executor" }

# CLI-specific dependencies
sc-cli = { path = "../../../client/cli", optional = true }
Expand Down Expand Up @@ -191,44 +191,30 @@ cli = [
]
runtime-benchmarks = [
"frame-benchmarking-cli/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"kitchensink-runtime/runtime-benchmarks",
"node-inspect?/runtime-benchmarks",
"pallet-asset-tx-payment/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-glutton/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-skip-feeless-payment/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"sc-client-db/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
# Enable features that allow the runtime to be tried and debugged. Name might be subject to change
# in the near future.
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"kitchensink-runtime/try-runtime",
"pallet-asset-conversion-tx-payment/try-runtime",
"pallet-asset-tx-payment/try-runtime",
"pallet-assets/try-runtime",
"pallet-balances/try-runtime",
"pallet-contracts/try-runtime",
"pallet-glutton/try-runtime",
"pallet-im-online/try-runtime",
"pallet-root-testing/try-runtime",
"pallet-skip-feeless-payment/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"sp-runtime/try-runtime",
"substrate-cli-test-utils/try-runtime",
"try-runtime-cli/try-runtime",
Expand All @@ -241,7 +227,3 @@ harness = false
[[bench]]
name = "block_production"
harness = false

[[bench]]
name = "executor"
harness = false
3 changes: 2 additions & 1 deletion substrate/bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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 @@ -88,7 +89,7 @@ pub fn run() -> Result<()> {
Some(Subcommand::Inspect(cmd)) => {
let runner = cli.create_runner(cmd)?;

runner.sync_run(|config| cmd.run::<Block, RuntimeApi>(config))
runner.sync_run(|config| cmd.run::<Block, RuntimeApi, ExecutorDispatch>(config))
},
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd)?;
Expand Down
24 changes: 5 additions & 19 deletions substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ 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_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::{strategy::warp::WarpSyncParams, SyncingService};
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
Expand All @@ -40,25 +42,9 @@ use sp_core::crypto::Pair;
use sp_runtime::{generic, traits::Block as BlockT, SaturatedConversion};
use std::{path::Path, 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.
pub type FullClient = sc_service::TFullClient<Block, RuntimeApi, RuntimeExecutor>;
pub type FullClient =
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
type FullGrandpaBlockImport =
Expand Down Expand Up @@ -195,7 +181,7 @@ pub fn new_partial(
})
.transpose()?;

let executor = sc_service::new_wasm_executor(&config);
let executor = sc_service::new_native_or_wasm_executor(&config);

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
Expand Down
57 changes: 57 additions & 0 deletions substrate/bin/node/executor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[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
Loading

0 comments on commit 89cbe04

Please sign in to comment.