Skip to content

Commit 563cef3

Browse files
committed
Reduce a bit of code duplication
1 parent 2995613 commit 563cef3

File tree

4 files changed

+27
-38
lines changed

4 files changed

+27
-38
lines changed

crates/subspace-node/src/bin/subspace-node.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
1919
use futures::future::TryFutureExt;
2020
use sc_cli::{ChainSpec, SubstrateCli};
21-
use sc_executor::NativeExecutionDispatch;
2221
use sp_core::crypto::Ss58AddressFormat;
23-
use subspace_node::{Cli, Subcommand};
22+
use subspace_node::{Cli, ExecutorDispatch, Subcommand};
2423
use subspace_runtime::RuntimeApi;
2524

2625
/// Subspace node error.
@@ -49,25 +48,6 @@ impl From<String> for Error {
4948
}
5049
}
5150

52-
struct ExecutorDispatch;
53-
54-
impl NativeExecutionDispatch for ExecutorDispatch {
55-
/// Only enable the benchmarking host functions when we actually want to benchmark.
56-
#[cfg(feature = "runtime-benchmarks")]
57-
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
58-
/// Otherwise we only use the default Substrate host functions.
59-
#[cfg(not(feature = "runtime-benchmarks"))]
60-
type ExtendHostFunctions = ();
61-
62-
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
63-
subspace_runtime::api::dispatch(method, data)
64-
}
65-
66-
fn native_version() -> sc_executor::NativeVersion {
67-
subspace_runtime::native_version()
68-
}
69-
}
70-
7151
fn set_default_ss58_version<C: AsRef<dyn ChainSpec>>(chain_spec: C) {
7252
let maybe_ss58_address_format = chain_spec
7353
.as_ref()

crates/subspace-node/src/lib.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,29 @@ mod chain_spec;
2020

2121
use clap::Parser;
2222
use sc_cli::SubstrateCli;
23-
use sc_executor::RuntimeVersion;
23+
use sc_executor::{NativeExecutionDispatch, RuntimeVersion};
2424
use sc_service::ChainSpec;
2525

26+
/// Executor dispatch for subspace runtime
27+
pub struct ExecutorDispatch;
28+
29+
impl NativeExecutionDispatch for ExecutorDispatch {
30+
/// Only enable the benchmarking host functions when we actually want to benchmark.
31+
#[cfg(feature = "runtime-benchmarks")]
32+
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
33+
/// Otherwise we only use the default Substrate host functions.
34+
#[cfg(not(feature = "runtime-benchmarks"))]
35+
type ExtendHostFunctions = ();
36+
37+
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
38+
subspace_runtime::api::dispatch(method, data)
39+
}
40+
41+
fn native_version() -> sc_executor::NativeVersion {
42+
subspace_runtime::native_version()
43+
}
44+
}
45+
2646
/// Utilities for working with a node.
2747
#[derive(Debug, clap::Subcommand)]
2848
pub enum Subcommand {

cumulus/parachain-template/node/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ name = "subspace-executor"
2020
path = "src/main.rs"
2121

2222
[features]
23-
runtime-benchmarks = ["parachain-template-runtime/runtime-benchmarks"]
23+
runtime-benchmarks = [
24+
"parachain-template-runtime/runtime-benchmarks",
25+
"subspace-node/runtime-benchmarks",
26+
]
2427

2528
[dependencies]
2629
codec = { package = "parity-scale-codec", version = "2.3.0" }

cumulus/parachain-template/node/src/service.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ impl NativeExecutionDispatch for TemplateRuntimeExecutor {
3434
}
3535
}
3636

37-
struct SubspaceExecutorDispatch;
38-
39-
impl NativeExecutionDispatch for SubspaceExecutorDispatch {
40-
type ExtendHostFunctions = ();
41-
42-
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
43-
subspace_runtime::api::dispatch(method, data)
44-
}
45-
46-
fn native_version() -> sc_executor::NativeVersion {
47-
subspace_runtime::native_version()
48-
}
49-
}
50-
5137
/// Starts a `ServiceBuilder` for a full service.
5238
///
5339
/// Use this macro if you don't actually need the full service, but just the builder in order to
@@ -231,7 +217,7 @@ where
231217
let span = tracing::info_span!(sc_tracing::logging::PREFIX_LOG_SPAN, name = "Primarychain");
232218
let _enter = span.enter();
233219

234-
subspace_service::new_full::<subspace_runtime::RuntimeApi, SubspaceExecutorDispatch>(
220+
subspace_service::new_full::<subspace_runtime::RuntimeApi, subspace_node::ExecutorDispatch>(
235221
polkadot_config,
236222
false,
237223
)

0 commit comments

Comments
 (0)