Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Remove the service, replacing it with a struct of individual chain components #6352

Merged
merged 32 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5178a3f
WIP
expenses Jun 12, 2020
9bb0129
Making progress
expenses Jun 15, 2020
91767ac
Almost ready
expenses Jun 15, 2020
3de5fce
Get service tests compiling
expenses Jun 16, 2020
937ad16
Fix node screenshot
expenses Jun 16, 2020
8d84167
Merge remote-tracking branch 'parity/master' into ashley-service-mult…
expenses Jun 16, 2020
30b8c65
Line widths
expenses Jun 18, 2020
a09301e
Merge remote-tracking branch 'parity/master' into ashley-service-mult…
expenses Jun 18, 2020
5bcf9f6
Fix node cli tests
expenses Jun 18, 2020
01e3ea0
Fix node cli warning
expenses Jun 18, 2020
1290452
ChainComponents -> ServiceComponents, fix tests
expenses Jun 18, 2020
11e3203
make spawn_handle public
expenses Jun 19, 2020
04d82e1
Merge remote-tracking branch 'parity/master' into ashley-service-mult…
expenses Jun 22, 2020
55df8af
Remove spawnnamed impl for taskmanager
expenses Jun 22, 2020
4e11e59
Move the keep alive stuff to the task manager
expenses Jun 23, 2020
22048cf
Move the telemetry, base path, rpc keep_alive to the service builder
expenses Jun 23, 2020
b5b335a
Merge remote-tracking branch 'parity/master' into ashley-service-mult…
expenses Jun 23, 2020
8ae7a04
Make the task manager keep alive an internal detail
expenses Jun 24, 2020
3319c11
Merge remote-tracking branch 'parity/master' into ashley-service-mult…
expenses Jun 24, 2020
f0a8f35
Rewrite the browser start_client future
expenses Jun 24, 2020
4546435
Remove run_node etc
expenses Jun 24, 2020
f42df6c
Revert my personal changes to browser-demo/build.sh
expenses Jun 24, 2020
0ad4e40
use |config|
expenses Jun 24, 2020
d066c02
Add a runtime_version function to SubstrateCli
expenses Jun 24, 2020
1305100
Reexport role and runtime version from sc cli
expenses Jun 24, 2020
1326a02
Update Cargo.lock
expenses Jun 24, 2020
772b757
runtime_version -> native_runtime_version
expenses Jun 25, 2020
efae0da
Merge remote-tracking branch 'parity/master' into ashley-service-mult…
expenses Jun 25, 2020
fe9d37a
Pass chain spec to native_runtime_version for polkadot
expenses Jun 25, 2020
97112f2
Merge remote-tracking branch 'parity/master' into ashley-service-mult…
expenses Jun 29, 2020
9c2e782
Fix line widths
expenses Jun 29, 2020
1f71076
Traitify ServiceComponents Client
expenses Jun 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ members = [
"client/rpc",
"client/rpc-api",
"client/service",
"client/service/test",
#"client/service/test",
"client/state-db",
"client/telemetry",
"client/transaction-pool",
Expand Down
57 changes: 36 additions & 21 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ use std::time::Duration;
use sc_client_api::ExecutorProvider;
use sc_consensus::LongestChain;
use node_template_runtime::{self, opaque::Block, RuntimeApi};
use sc_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder};
use sc_service::{
error::{Error as ServiceError},
Configuration, ServiceBuilder, ChainComponents,
};
use sp_inherents::InherentDataProviders;
use sc_executor::native_executor_instance;
pub use sc_executor::NativeExecutor;
use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};
use sc_finality_grandpa::{
FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider, SharedVoterState,
};
use sc_cli::KeepAliveChainComponents;

// Our native executor instance.
native_executor_instance!(
Expand Down Expand Up @@ -93,7 +97,9 @@ macro_rules! new_full_start {
}

/// Builds a new service for a full client.
pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceError> {
pub fn new_full(config: Configuration)
-> Result<KeepAliveChainComponents, ServiceError>
{
let role = config.role.clone();
let force_authoring = config.force_authoring;
let name = config.network.node_name.clone();
Expand All @@ -105,7 +111,10 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr
import_setup.take()
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");

let service = builder
let ChainComponents {
client, transaction_pool, task_manager, keystore, network, telemetry, base_path,
select_chain, prometheus_registry, telemetry_on_connect_sinks, rpc, ..
} = builder
.with_finality_proof_provider(|client, backend| {
// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
Expand All @@ -115,40 +124,39 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr

if role.is_authority() {
let proposer = sc_basic_authorship::ProposerFactory::new(
service.client(),
service.transaction_pool(),
service.prometheus_registry().as_ref(),
client.clone(),
transaction_pool,
prometheus_registry.as_ref(),
);

let client = service.client();
let select_chain = service.select_chain()
let select_chain = select_chain
.ok_or(ServiceError::SelectChainRequired)?;

let can_author_with =
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());

let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _>(
sc_consensus_aura::slot_duration(&*client)?,
client,
client.clone(),
select_chain,
block_import,
proposer,
service.network(),
network.clone(),
inherent_data_providers.clone(),
force_authoring,
service.keystore(),
keystore.clone(),
can_author_with,
)?;

// the AURA authoring task is considered essential, i.e. if it
// fails we take down the service with it.
service.spawn_essential_task("aura", aura);
task_manager.spawn_essential("aura", aura);
}

// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if role.is_authority() {
Some(service.keystore() as sp_core::traits::BareCryptoStorePtr)
Some(keystore.clone() as sp_core::traits::BareCryptoStorePtr)
} else {
None
};
Expand All @@ -174,33 +182,35 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr
let grandpa_config = sc_finality_grandpa::GrandpaParams {
config: grandpa_config,
link: grandpa_link,
network: service.network(),
network: network.clone(),
inherent_data_providers: inherent_data_providers.clone(),
telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
telemetry_on_connect: Some(telemetry_on_connect_sinks.on_connect_stream()),
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
prometheus_registry: service.prometheus_registry(),
prometheus_registry: prometheus_registry.clone(),
shared_voter_state: SharedVoterState::empty(),
};

// the GRANDPA voter task is considered infallible, i.e.
// if it fails we take down the service with it.
service.spawn_essential_task(
task_manager.spawn_essential(
"grandpa-voter",
sc_finality_grandpa::run_grandpa_voter(grandpa_config)?
);
} else {
sc_finality_grandpa::setup_disabled_grandpa(
service.client(),
client,
&inherent_data_providers,
service.network(),
network.clone(),
)?;
}

Ok(service)
Ok(KeepAliveChainComponents {
task_manager, telemetry, base_path, rpc,
})
}

/// Builds a new service for a light client.
pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceError> {
pub fn new_light(config: Configuration) -> Result<KeepAliveChainComponents, ServiceError> {
let inherent_data_providers = InherentDataProviders::new();

ServiceBuilder::new_light::<Block, RuntimeApi, Executor>(config)?
Expand Down Expand Up @@ -265,4 +275,9 @@ pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceE
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
})?
.build_light()
.map(|ChainComponents { task_manager, telemetry, base_path, rpc, .. }| {
KeepAliveChainComponents {
task_manager, telemetry, base_path, rpc,
}
})
}
2 changes: 1 addition & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ sc-keystore = { version = "2.0.0-rc3", path = "../../../client/keystore" }
sc-consensus = { version = "0.8.0-rc3", path = "../../../client/consensus/common" }
sc-consensus-babe = { version = "0.8.0-rc3", features = ["test-helpers"], path = "../../../client/consensus/babe" }
sc-consensus-epochs = { version = "0.8.0-rc3", path = "../../../client/consensus/epochs" }
sc-service-test = { version = "2.0.0-rc3", path = "../../../client/service/test" }
#sc-service-test = { version = "2.0.0-rc3", path = "../../../client/service/test" }
futures = "0.3.4"
tempfile = "3.1.0"
assert_cmd = "1.0"
Expand Down
5 changes: 3 additions & 2 deletions bin/node/cli/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use browser_utils::{
Client,
browser_configuration, set_console_error_panic_hook, init_console_log,
};
use sc_cli::KeepAliveChainComponents;
use std::str::FromStr;

/// Starts the client.
Expand Down Expand Up @@ -52,8 +53,8 @@ async fn start_inner(chain_spec: Option<String>, log_level: String) -> Result<Cl
info!("👤 Role: {:?}", config.role);

// Create the service. This is the most heavy initialization step.
let service = crate::service::new_light(config)
let (KeepAliveChainComponents { task_manager, .. }, rpc_handlers) = crate::service::new_light_browser(config)
.map_err(|e| format!("{:?}", e))?;

Ok(browser_utils::start_client(service))
Ok(browser_utils::start_client(task_manager, rpc_handlers))
}
3 changes: 2 additions & 1 deletion bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ pub fn local_testnet_config() -> ChainSpec {
pub(crate) mod tests {
use super::*;
use crate::service::{new_full, new_light};
use sc_service_test;
use sp_runtime::BuildStorage;

fn local_testnet_genesis_instant_single() -> GenesisConfig {
Expand Down Expand Up @@ -425,6 +424,7 @@ pub(crate) mod tests {
)
}

/*
#[test]
#[ignore]
fn test_connectivity() {
Expand All @@ -434,6 +434,7 @@ pub(crate) mod tests {
|config| new_light(config),
);
}
*/

#[test]
fn test_create_development_chain_spec() {
Expand Down
Loading