Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit 551d923

Browse files
authored
Merge pull request paritytech#262 from subspace/extract-subspace-service-tweaks
Extract subspace service (tweaks)
2 parents 7b6d0a4 + 02a3da3 commit 551d923

File tree

15 files changed

+147
-250
lines changed

15 files changed

+147
-250
lines changed

Cargo.lock

+7-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cirrus-node-primitives/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ pub type CollatorSignature = collator_app::Signature;
152152

153153
/// Configuration for the collation generator
154154
pub struct CollationGenerationConfig {
155-
/// Collator's authentication key, so it can sign things.
156-
pub key: CollatorPair,
157155
/// Transaction bundle function. See [`BundlerFn`] for more details.
158156
pub bundler: BundlerFn,
159157
/// State processor function. See [`ProcessorFn`] for more details.

crates/subspace-node/Cargo.toml

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,28 @@ targets = ["x86_64-unknown-linux-gnu"]
2121
[dependencies]
2222
clap = { version = "3.0.13", features = ["derive"] }
2323
frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
24+
frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
2425
futures = "0.3.19"
2526
sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927", features = ["wasmtime"] }
27+
sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927", features = ["wasmtime"] }
2628
sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927", features = ["wasmtime"] }
29+
sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
2730
sp-core = { version = "5.0.0", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
31+
sp-runtime = { version = "5.0.0", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
32+
subspace-runtime = { version = "0.1.0", path = "../subspace-runtime" }
33+
subspace-runtime-primitives = { version = "0.1.0", path = "../subspace-runtime-primitives" }
2834
subspace-service = { version = "0.1.0", path = "../subspace-service" }
2935
thiserror = "1.0.30"
3036

3137
[build-dependencies]
3238
substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
3339

3440
[features]
35-
default = []
41+
default = ["do-not-enforce-cost-of-storage"]
42+
do-not-enforce-cost-of-storage = [
43+
"subspace-runtime/do-not-enforce-cost-of-storage"
44+
]
3645
runtime-benchmarks = [
37-
"subspace-service/runtime-benchmarks",
46+
"subspace-runtime/runtime-benchmarks",
3847
]
3948
json-chain-spec = ["subspace-service/json-chain-spec"]

crates/subspace-node/src/command.rs

+59-16
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17+
use crate::chain_spec;
1718
use crate::cli::{Cli, Subcommand};
1819
use futures::future::TryFutureExt;
1920
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
21+
use sc_executor::NativeExecutionDispatch;
2022
use sp_core::crypto::Ss58AddressFormat;
21-
use subspace_service::{chain_spec, subspace_runtime, SubspaceExecutorDispatch};
23+
use subspace_runtime::RuntimeApi;
2224

2325
/// Subspace node error.
2426
#[derive(thiserror::Error, Debug)]
@@ -46,6 +48,25 @@ impl From<String> for Error {
4648
}
4749
}
4850

51+
struct ExecutorDispatch;
52+
53+
impl NativeExecutionDispatch for ExecutorDispatch {
54+
/// Only enable the benchmarking host functions when we actually want to benchmark.
55+
#[cfg(feature = "runtime-benchmarks")]
56+
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
57+
/// Otherwise we only use the default Substrate host functions.
58+
#[cfg(not(feature = "runtime-benchmarks"))]
59+
type ExtendHostFunctions = ();
60+
61+
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
62+
subspace_runtime::api::dispatch(method, data)
63+
}
64+
65+
fn native_version() -> sc_executor::NativeVersion {
66+
subspace_runtime::native_version()
67+
}
68+
}
69+
4970
impl SubstrateCli for Cli {
5071
fn impl_name() -> String {
5172
"Subspace".into()
@@ -120,9 +141,13 @@ pub fn run() -> std::result::Result<(), Error> {
120141
Some(Subcommand::CheckBlock(cmd)) => {
121142
let runner = cli.create_runner(cmd)?;
122143
set_default_ss58_version(&runner.config().chain_spec);
123-
runner.async_run(|mut config| {
124-
let (client, _, import_queue, task_manager) =
125-
subspace_service::new_chain_ops(&mut config)?;
144+
runner.async_run(|config| {
145+
let sc_service::PartialComponents {
146+
client,
147+
import_queue,
148+
task_manager,
149+
..
150+
} = subspace_service::new_partial::<RuntimeApi, ExecutorDispatch>(&config)?;
126151
Ok((
127152
cmd.run(client, import_queue).map_err(Error::SubstrateCli),
128153
task_manager,
@@ -132,8 +157,12 @@ pub fn run() -> std::result::Result<(), Error> {
132157
Some(Subcommand::ExportBlocks(cmd)) => {
133158
let runner = cli.create_runner(cmd)?;
134159
set_default_ss58_version(&runner.config().chain_spec);
135-
runner.async_run(|mut config| {
136-
let (client, _, _, task_manager) = subspace_service::new_chain_ops(&mut config)?;
160+
runner.async_run(|config| {
161+
let sc_service::PartialComponents {
162+
client,
163+
task_manager,
164+
..
165+
} = subspace_service::new_partial::<RuntimeApi, ExecutorDispatch>(&config)?;
137166
Ok((
138167
cmd.run(client, config.database)
139168
.map_err(Error::SubstrateCli),
@@ -144,8 +173,12 @@ pub fn run() -> std::result::Result<(), Error> {
144173
Some(Subcommand::ExportState(cmd)) => {
145174
let runner = cli.create_runner(cmd)?;
146175
set_default_ss58_version(&runner.config().chain_spec);
147-
runner.async_run(|mut config| {
148-
let (client, _, _, task_manager) = subspace_service::new_chain_ops(&mut config)?;
176+
runner.async_run(|config| {
177+
let sc_service::PartialComponents {
178+
client,
179+
task_manager,
180+
..
181+
} = subspace_service::new_partial::<RuntimeApi, ExecutorDispatch>(&config)?;
149182
Ok((
150183
cmd.run(client, config.chain_spec)
151184
.map_err(Error::SubstrateCli),
@@ -156,9 +189,13 @@ pub fn run() -> std::result::Result<(), Error> {
156189
Some(Subcommand::ImportBlocks(cmd)) => {
157190
let runner = cli.create_runner(cmd)?;
158191
set_default_ss58_version(&runner.config().chain_spec);
159-
runner.async_run(|mut config| {
160-
let (client, _, import_queue, task_manager) =
161-
subspace_service::new_chain_ops(&mut config)?;
192+
runner.async_run(|config| {
193+
let sc_service::PartialComponents {
194+
client,
195+
import_queue,
196+
task_manager,
197+
..
198+
} = subspace_service::new_partial::<RuntimeApi, ExecutorDispatch>(&config)?;
162199
Ok((
163200
cmd.run(client, import_queue).map_err(Error::SubstrateCli),
164201
task_manager,
@@ -172,9 +209,13 @@ pub fn run() -> std::result::Result<(), Error> {
172209
Some(Subcommand::Revert(cmd)) => {
173210
let runner = cli.create_runner(cmd)?;
174211
set_default_ss58_version(&runner.config().chain_spec);
175-
runner.async_run(|mut config| {
176-
let (client, backend, _, task_manager) =
177-
subspace_service::new_chain_ops(&mut config)?;
212+
runner.async_run(|config| {
213+
let sc_service::PartialComponents {
214+
client,
215+
backend,
216+
task_manager,
217+
..
218+
} = subspace_service::new_partial::<RuntimeApi, ExecutorDispatch>(&config)?;
178219
Ok((
179220
cmd.run(client, backend).map_err(Error::SubstrateCli),
180221
task_manager,
@@ -186,7 +227,7 @@ pub fn run() -> std::result::Result<(), Error> {
186227
let runner = cli.create_runner(cmd)?;
187228
set_default_ss58_version(&runner.config().chain_spec);
188229
runner.sync_run(|config| {
189-
cmd.run::<subspace_runtime::Block, SubspaceExecutorDispatch>(config)
230+
cmd.run::<subspace_runtime::Block, ExecutorDispatch>(config)
190231
})?;
191232
} else {
192233
return Err(Error::Other(
@@ -200,7 +241,9 @@ pub fn run() -> std::result::Result<(), Error> {
200241
let runner = cli.create_runner(&cli.run.base)?;
201242
set_default_ss58_version(&runner.config().chain_spec);
202243
runner.run_node_until_exit(|config| async move {
203-
subspace_service::new_full::<subspace_runtime::RuntimeApi, SubspaceExecutorDispatch>(config, true)
244+
subspace_service::new_full::<subspace_runtime::RuntimeApi, ExecutorDispatch>(
245+
config, true,
246+
)
204247
.await
205248
.map(|full| full.task_manager)
206249
})?;

crates/subspace-node/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
1919
#![warn(missing_docs)]
2020

21+
mod chain_spec;
2122
pub mod cli;
2223
mod command;
2324

crates/subspace-runtime/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use sp_version::NativeVersion;
5656
use sp_version::RuntimeVersion;
5757
use subspace_core_primitives::objects::{BlockObject, BlockObjectMapping};
5858
use subspace_core_primitives::{Randomness, RootBlock, Sha256Hash, PIECE_SIZE};
59-
pub use subspace_runtime_primitives::{
59+
use subspace_runtime_primitives::{
6060
opaque, AccountId, Balance, BlockNumber, Hash, Index, Moment, Signature, CONFIRMATION_DEPTH_K,
6161
MIN_REPLICATION_FACTOR, RECORDED_HISTORY_SEGMENT_SIZE, RECORD_SIZE,
6262
STORAGE_FEES_ESCROW_BLOCK_REWARD, STORAGE_FEES_ESCROW_BLOCK_TAX,

crates/subspace-service/Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ sp-runtime = { version = "5.0.0", git = "https://github.com/paritytech/substrate
5555
sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
5656
sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
5757
sp-trie = { version = "5.0.0", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
58-
subspace-runtime = { version = "0.1.0", features = ["do-not-enforce-cost-of-storage"], path = "../subspace-runtime" }
5958
subspace-runtime-primitives = { version = "0.1.0", path = "../subspace-runtime-primitives" }
6059
substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
6160
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
@@ -67,9 +66,6 @@ pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", git = "htt
6766

6867
[features]
6968
default = []
70-
runtime-benchmarks = [
71-
"subspace-runtime/runtime-benchmarks",
72-
]
7369
# This feature makes `testnet` chain spec to use `chain-spec.json` file in the root of the repo instead of compiled
7470
# version
7571
json-chain-spec = []

crates/subspace-service/src/lib.rs

-51
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
1818
19-
pub mod chain_spec;
2019
pub mod rpc;
2120

2221
use lru::LruCache;
@@ -41,7 +40,6 @@ use sp_blockchain::HeaderBackend;
4140
use sp_consensus::SelectChain;
4241
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Header as HeaderT};
4342
use std::sync::Arc;
44-
pub use subspace_runtime;
4543
use subspace_runtime_primitives::{
4644
opaque::{Block, BlockId},
4745
AccountId, Balance, Index as Nonce,
@@ -116,33 +114,10 @@ pub enum Error {
116114
Prometheus(#[from] substrate_prometheus_endpoint::PrometheusError),
117115
}
118116

119-
/// Subspace native executor instance.
120-
pub struct SubspaceExecutorDispatch;
121-
122-
impl sc_executor::NativeExecutionDispatch for SubspaceExecutorDispatch {
123-
/// Only enable the benchmarking host functions when we actually want to benchmark.
124-
#[cfg(feature = "runtime-benchmarks")]
125-
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
126-
/// Otherwise we only use the default Substrate host functions.
127-
#[cfg(not(feature = "runtime-benchmarks"))]
128-
type ExtendHostFunctions = ();
129-
130-
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
131-
subspace_runtime::api::dispatch(method, data)
132-
}
133-
134-
fn native_version() -> sc_executor::NativeVersion {
135-
subspace_runtime::native_version()
136-
}
137-
}
138-
139117
/// Subspace-like full client.
140118
pub type FullClient<RuntimeApi, ExecutorDispatch> =
141119
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
142120

143-
/// Full client using subspace-runtime.
144-
pub type SubspaceClient = FullClient<subspace_runtime::RuntimeApi, SubspaceExecutorDispatch>;
145-
146121
type FullBackend = sc_service::TFullBackend<Block>;
147122
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
148123

@@ -605,29 +580,3 @@ where
605580
block_signing_notification_stream,
606581
})
607582
}
608-
609-
/// Builds a new object suitable for chain operations.
610-
#[allow(clippy::type_complexity)]
611-
pub fn new_chain_ops(
612-
mut config: &mut Configuration,
613-
) -> Result<
614-
(
615-
Arc<FullClient<subspace_runtime::RuntimeApi, SubspaceExecutorDispatch>>,
616-
Arc<FullBackend>,
617-
sc_consensus::BasicQueue<Block, sp_trie::PrefixedMemoryDB<BlakeTwo256>>,
618-
TaskManager,
619-
),
620-
Error,
621-
> {
622-
config.keystore = sc_service::config::KeystoreConfig::InMemory;
623-
624-
let sc_service::PartialComponents {
625-
client,
626-
backend,
627-
import_queue,
628-
task_manager,
629-
..
630-
} = new_partial::<subspace_runtime::RuntimeApi, SubspaceExecutorDispatch>(config)?;
631-
632-
Ok((client, backend, import_queue, task_manager))
633-
}

crates/subspace-service/src/rpc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ use sp_api::ProvideRuntimeApi;
3131
use sp_block_builder::BlockBuilder;
3232
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
3333
use std::sync::Arc;
34-
use subspace_runtime::{opaque::Block, AccountId, Balance, Index};
34+
use subspace_runtime_primitives::opaque::Block;
35+
use subspace_runtime_primitives::{AccountId, Balance, Index};
3536

3637
/// Full client dependencies.
3738
pub struct FullDeps<C, P> {

cumulus/client/cirrus-executor/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use polkadot_overseer::Handle as OverseerHandle;
4242

4343
use cirrus_client_executor_gossip::{Action, GossipMessageHandler};
4444
use cirrus_node_primitives::{
45-
BundleResult, CollationGenerationConfig, CollatorPair, ExecutorSlotInfo, ProcessorResult,
45+
BundleResult, CollationGenerationConfig, ExecutorSlotInfo, ProcessorResult,
4646
};
4747
use cirrus_primitives::{AccountId, Hash, SecondaryApi};
4848
use sp_executor::{
@@ -528,7 +528,6 @@ pub struct StartExecutorParams<Block: BlockT, Spawner, Client, TransactionPool,
528528
pub announce_block: Arc<dyn Fn(Block::Hash, Option<Vec<u8>>) + Send + Sync>,
529529
pub overseer_handle: OverseerHandle,
530530
pub spawner: Spawner,
531-
pub key: CollatorPair,
532531
pub parachain_consensus: Box<dyn ParachainConsensus<Block>>,
533532
pub transaction_pool: Arc<TransactionPool>,
534533
pub bundle_sender: TracingUnboundedSender<Bundle<Block::Extrinsic>>,
@@ -545,7 +544,6 @@ pub async fn start_executor<Block, Spawner, Client, TransactionPool, Backend, CI
545544
announce_block: _,
546545
mut overseer_handle,
547546
spawner,
548-
key,
549547
parachain_consensus,
550548
transaction_pool,
551549
bundle_sender,
@@ -596,7 +594,6 @@ where
596594

597595
let span = tracing::Span::current();
598596
let config = CollationGenerationConfig {
599-
key,
600597
bundler: {
601598
let executor = executor.clone();
602599
let span = span.clone();

0 commit comments

Comments
 (0)