Skip to content

Commit 70be93d

Browse files
RomarQKrayt78
authored andcommitted
Expose types from sc-service (paritytech#5855)
# Description At moonbeam we have worked on a `lazy-loading` feature which is a client mode that forks a live parachain and fetches its state on-demand, we have been able to do this by duplicating some code from `sc_service::client`. The objective of this PR is to simplify the implementation by making public some types in polkadot-sdk. - Modules: - `sc_service::client` **I do not see a point to only expose this type when `test-helpers` feature is enabled** ## Integration Not applicable, the PR just makes some types public. ## Review Notes The changes included in this PR give more flexibility for client developers by exposing important types.
1 parent 0c4265a commit 70be93d

File tree

14 files changed

+34
-63
lines changed

14 files changed

+34
-63
lines changed

prdoc/pr_5855.prdoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Remove feature `test-helpers` from sc-service
5+
6+
doc:
7+
- audience: Node Dev
8+
description: |
9+
Removes feature `test-helpers` from sc-service.
10+
11+
crates:
12+
- name: sc-service
13+
bump: major
14+
- name: sc-rpc-spec-v2
15+
bump: major

substrate/bin/node/testing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ sc-client-api = { workspace = true, default-features = true }
3737
sc-client-db = { features = ["rocksdb"], workspace = true, default-features = true }
3838
sc-consensus = { workspace = true, default-features = true }
3939
sc-executor = { workspace = true, default-features = true }
40-
sc-service = { features = ["rocksdb", "test-helpers"], workspace = true, default-features = true }
40+
sc-service = { features = ["rocksdb"], workspace = true, default-features = true }
4141
sp-api = { workspace = true, default-features = true }
4242
sp-block-builder = { workspace = true, default-features = true }
4343
sp-blockchain = { workspace = true, default-features = true }

substrate/client/network/test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sc-network-types = { workspace = true, default-features = true }
3333
sc-utils = { workspace = true, default-features = true }
3434
sc-network-light = { workspace = true, default-features = true }
3535
sc-network-sync = { workspace = true, default-features = true }
36-
sc-service = { features = ["test-helpers"], workspace = true }
36+
sc-service = { workspace = true }
3737
sp-blockchain = { workspace = true, default-features = true }
3838
sp-consensus = { workspace = true, default-features = true }
3939
sp-core = { workspace = true, default-features = true }

substrate/client/rpc-spec-v2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ sp-consensus = { workspace = true, default-features = true }
5656
sp-externalities = { workspace = true, default-features = true }
5757
sp-maybe-compressed-blob = { workspace = true, default-features = true }
5858
sc-block-builder = { workspace = true, default-features = true }
59-
sc-service = { features = ["test-helpers"], workspace = true, default-features = true }
59+
sc-service = { workspace = true, default-features = true }
6060
sc-rpc = { workspace = true, default-features = true, features = ["test-helpers"] }
6161
assert_matches = { workspace = true }
6262
pretty_assertions = { workspace = true }

substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ mod tests {
784784
use super::*;
785785
use jsonrpsee::ConnectionId;
786786
use sc_block_builder::BlockBuilderBuilder;
787-
use sc_service::client::new_in_mem;
787+
use sc_service::client::new_with_backend;
788788
use sp_consensus::BlockOrigin;
789789
use sp_core::{testing::TaskExecutor, H256};
790790
use substrate_test_runtime_client::{
@@ -811,13 +811,13 @@ mod tests {
811811
)
812812
.unwrap();
813813
let client = Arc::new(
814-
new_in_mem::<_, Block, _, RuntimeApi>(
814+
new_with_backend::<_, _, Block, _, RuntimeApi>(
815815
backend.clone(),
816816
executor,
817817
genesis_block_builder,
818+
Box::new(TaskExecutor::new()),
818819
None,
819820
None,
820-
Box::new(TaskExecutor::new()),
821821
client_config,
822822
)
823823
.unwrap(),

substrate/client/rpc-spec-v2/src/chain_head/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use jsonrpsee::{
3434
use sc_block_builder::BlockBuilderBuilder;
3535
use sc_client_api::ChildInfo;
3636
use sc_rpc::testing::TokioTestExecutor;
37-
use sc_service::client::new_in_mem;
37+
use sc_service::client::new_with_backend;
3838
use sp_blockchain::HeaderBackend;
3939
use sp_consensus::BlockOrigin;
4040
use sp_core::{
@@ -2547,13 +2547,13 @@ async fn pin_block_references() {
25472547
.unwrap();
25482548

25492549
let client = Arc::new(
2550-
new_in_mem::<_, Block, _, RuntimeApi>(
2550+
new_with_backend::<_, _, Block, _, RuntimeApi>(
25512551
backend.clone(),
25522552
executor,
25532553
genesis_block_builder,
2554+
Box::new(TokioTestExecutor::default()),
25542555
None,
25552556
None,
2556-
Box::new(TokioTestExecutor::default()),
25572557
client_config,
25582558
)
25592559
.unwrap(),

substrate/client/service/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ default = ["rocksdb"]
2020
# The RocksDB feature activates the RocksDB database backend. If it is not activated, and you pass
2121
# a path to a database, an error will be produced at runtime.
2222
rocksdb = ["sc-client-db/rocksdb"]
23-
# exposes the client type
24-
test-helpers = []
2523
runtime-benchmarks = [
2624
"sc-client-db/runtime-benchmarks",
2725
"sp-runtime/runtime-benchmarks",

substrate/client/service/src/client/client.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ use std::{
8585
sync::Arc,
8686
};
8787

88-
#[cfg(feature = "test-helpers")]
89-
use {
90-
super::call_executor::LocalCallExecutor, sc_client_api::in_mem, sp_core::traits::CodeExecutor,
91-
};
88+
use super::call_executor::LocalCallExecutor;
89+
use sp_core::traits::CodeExecutor;
9290

9391
type NotificationSinks<T> = Mutex<Vec<TracingUnboundedSender<T>>>;
9492

@@ -152,39 +150,6 @@ enum PrepareStorageChangesResult<Block: BlockT> {
152150
Discard(ImportResult),
153151
Import(Option<sc_consensus::StorageChanges<Block>>),
154152
}
155-
156-
/// Create an instance of in-memory client.
157-
#[cfg(feature = "test-helpers")]
158-
pub fn new_in_mem<E, Block, G, RA>(
159-
backend: Arc<in_mem::Backend<Block>>,
160-
executor: E,
161-
genesis_block_builder: G,
162-
prometheus_registry: Option<Registry>,
163-
telemetry: Option<TelemetryHandle>,
164-
spawn_handle: Box<dyn SpawnNamed>,
165-
config: ClientConfig<Block>,
166-
) -> sp_blockchain::Result<
167-
Client<in_mem::Backend<Block>, LocalCallExecutor<Block, in_mem::Backend<Block>, E>, Block, RA>,
168-
>
169-
where
170-
E: CodeExecutor + sc_executor::RuntimeVersionOf,
171-
Block: BlockT,
172-
G: BuildGenesisBlock<
173-
Block,
174-
BlockImportOperation = <in_mem::Backend<Block> as backend::Backend<Block>>::BlockImportOperation,
175-
>,
176-
{
177-
new_with_backend(
178-
backend,
179-
executor,
180-
genesis_block_builder,
181-
spawn_handle,
182-
prometheus_registry,
183-
telemetry,
184-
config,
185-
)
186-
}
187-
188153
/// Client configuration items.
189154
#[derive(Debug, Clone)]
190155
pub struct ClientConfig<Block: BlockT> {
@@ -218,7 +183,6 @@ impl<Block: BlockT> Default for ClientConfig<Block> {
218183

219184
/// Create a client with the explicitly provided backend.
220185
/// This is useful for testing backend implementations.
221-
#[cfg(feature = "test-helpers")]
222186
pub fn new_with_backend<B, E, Block, G, RA>(
223187
backend: Arc<B>,
224188
executor: E,

substrate/client/service/src/client/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ pub use call_executor::LocalCallExecutor;
5656
pub use client::{Client, ClientConfig};
5757
pub(crate) use code_provider::CodeProvider;
5858

59-
#[cfg(feature = "test-helpers")]
60-
pub use self::client::{new_in_mem, new_with_backend};
59+
pub use self::client::new_with_backend;

substrate/client/service/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@
2323
#![recursion_limit = "1024"]
2424

2525
pub mod chain_ops;
26+
pub mod client;
2627
pub mod config;
2728
pub mod error;
2829

2930
mod builder;
30-
#[cfg(feature = "test-helpers")]
31-
pub mod client;
32-
#[cfg(not(feature = "test-helpers"))]
33-
mod client;
3431
mod metrics;
3532
mod task_manager;
3633

0 commit comments

Comments
 (0)