From 16f8da1da330cd84689c8ffc6a04d470a98fc086 Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Sat, 31 Oct 2020 06:20:29 +0300 Subject: [PATCH] A real overseer feature (#1892) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * A real overseer feature * Fix build without feature * Update node/service/src/lib.rs Co-authored-by: Bastian Köcher Co-authored-by: Robert Habermeier Co-authored-by: Bastian Köcher --- polkadot/Cargo.toml | 1 + polkadot/cli/Cargo.toml | 1 + polkadot/node/service/Cargo.toml | 6 +- polkadot/node/service/src/lib.rs | 113 ++++++++++++++++++++++++++++++- 4 files changed, 118 insertions(+), 3 deletions(-) diff --git a/polkadot/Cargo.toml b/polkadot/Cargo.toml index c168f06b2e..8c3f43e3d2 100644 --- a/polkadot/Cargo.toml +++ b/polkadot/Cargo.toml @@ -85,6 +85,7 @@ panic = "unwind" [features] runtime-benchmarks=["cli/runtime-benchmarks"] +real-overseer=["cli/real-overseer"] # Configuration for building a .deb package - for use with `cargo-deb` [package.metadata.deb] diff --git a/polkadot/cli/Cargo.toml b/polkadot/cli/Cargo.toml index 05567acd63..b1c366a3ab 100644 --- a/polkadot/cli/Cargo.toml +++ b/polkadot/cli/Cargo.toml @@ -54,3 +54,4 @@ browser = [ runtime-benchmarks = [ "service/runtime-benchmarks" ] trie-memory-tracker = [ "sp-trie/memory-tracker" ] full-node = [ "service/full-node" ] +real-overseer = [ "service/real-overseer" ] diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index 78b25605c1..813d5f595a 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -99,14 +99,16 @@ env_logger = "0.8.1" [features] default = ["db", "full-node"] db = ["service/db"] -runtime-benchmarks = ["polkadot-runtime/runtime-benchmarks", "kusama-runtime/runtime-benchmarks", "westend-runtime/runtime-benchmarks"] full-node = [ + "polkadot-node-core-av-store", +] +runtime-benchmarks = ["polkadot-runtime/runtime-benchmarks", "kusama-runtime/runtime-benchmarks", "westend-runtime/runtime-benchmarks"] +real-overseer = [ "polkadot-availability-bitfield-distribution", "polkadot-availability-distribution", "polkadot-collator-protocol", "polkadot-network-bridge", "polkadot-node-collation-generation", - "polkadot-node-core-av-store", "polkadot-node-core-backing", "polkadot-node-core-bitfield-signing", "polkadot-node-core-candidate-selection", diff --git a/polkadot/node/service/src/lib.rs b/polkadot/node/service/src/lib.rs index 90fef8235d..046c1b1383 100644 --- a/polkadot/node/service/src/lib.rs +++ b/polkadot/node/service/src/lib.rs @@ -285,7 +285,7 @@ fn new_partial(config: &mut Configuration) -> Result< }) } -#[cfg(feature="full-node")] +#[cfg(all(feature="full-node", not(feature = "real-overseer")))] fn real_overseer( leaves: impl IntoIterator, _: SyncCryptoStorePtr, @@ -310,6 +310,117 @@ where ).map_err(|e| Error::Other(format!("Failed to create an Overseer: {:?}", e))) } +#[cfg(all(feature = "full-node", feature = "real-overseer"))] +fn real_overseer( + leaves: impl IntoIterator, + keystore: SyncCryptoStorePtr, + runtime_client: Arc, + availability_config: AvailabilityConfig, + network_service: Arc>, + authority_discovery: AuthorityDiscoveryService, + registry: Option<&Registry>, + spawner: Spawner, + is_collator: IsCollator, +) -> Result<(Overseer, OverseerHandler), Error> +where + RuntimeClient: 'static + ProvideRuntimeApi + HeaderBackend, + RuntimeClient::Api: ParachainHost, + Spawner: 'static + SpawnNamed + Clone + Unpin, +{ + use polkadot_node_subsystem_util::metrics::Metrics; + + use polkadot_availability_distribution::AvailabilityDistributionSubsystem; + use polkadot_node_core_av_store::AvailabilityStoreSubsystem; + use polkadot_availability_bitfield_distribution::BitfieldDistribution as BitfieldDistributionSubsystem; + use polkadot_node_core_bitfield_signing::BitfieldSigningSubsystem; + use polkadot_node_core_backing::CandidateBackingSubsystem; + use polkadot_node_core_candidate_selection::CandidateSelectionSubsystem; + use polkadot_node_core_candidate_validation::CandidateValidationSubsystem; + use polkadot_node_core_chain_api::ChainApiSubsystem; + use polkadot_node_collation_generation::CollationGenerationSubsystem; + use polkadot_collator_protocol::{CollatorProtocolSubsystem, ProtocolSide}; + use polkadot_network_bridge::NetworkBridge as NetworkBridgeSubsystem; + use polkadot_pov_distribution::PoVDistribution as PoVDistributionSubsystem; + use polkadot_node_core_provisioner::ProvisioningSubsystem as ProvisionerSubsystem; + use polkadot_node_core_runtime_api::RuntimeApiSubsystem; + use polkadot_statement_distribution::StatementDistribution as StatementDistributionSubsystem; + + let all_subsystems = AllSubsystems { + availability_distribution: AvailabilityDistributionSubsystem::new( + keystore.clone(), + Metrics::register(registry)?, + ), + availability_store: AvailabilityStoreSubsystem::new_on_disk( + availability_config, + Metrics::register(registry)?, + )?, + bitfield_distribution: BitfieldDistributionSubsystem::new( + Metrics::register(registry)?, + ), + bitfield_signing: BitfieldSigningSubsystem::new( + spawner.clone(), + keystore.clone(), + Metrics::register(registry)?, + ), + candidate_backing: CandidateBackingSubsystem::new( + spawner.clone(), + keystore.clone(), + Metrics::register(registry)?, + ), + candidate_selection: CandidateSelectionSubsystem::new( + spawner.clone(), + (), + Metrics::register(registry)?, + ), + candidate_validation: CandidateValidationSubsystem::new( + spawner.clone(), + Metrics::register(registry)?, + ), + chain_api: ChainApiSubsystem::new( + runtime_client.clone(), + Metrics::register(registry)?, + ), + collation_generation: CollationGenerationSubsystem::new( + Metrics::register(registry)?, + ), + collator_protocol: { + let side = match is_collator { + IsCollator::Yes(id) => ProtocolSide::Collator(id, Metrics::register(registry)?), + IsCollator::No => ProtocolSide::Validator(Metrics::register(registry)?), + }; + CollatorProtocolSubsystem::new( + side, + ) + }, + network_bridge: NetworkBridgeSubsystem::new( + network_service, + authority_discovery, + ), + pov_distribution: PoVDistributionSubsystem::new( + Metrics::register(registry)?, + ), + provisioner: ProvisionerSubsystem::new( + spawner.clone(), + (), + Metrics::register(registry)?, + ), + runtime_api: RuntimeApiSubsystem::new( + runtime_client, + Metrics::register(registry)?, + ), + statement_distribution: StatementDistributionSubsystem::new( + Metrics::register(registry)?, + ), + }; + + Overseer::new( + leaves, + all_subsystems, + registry, + spawner, + ).map_err(|e| Error::Other(format!("Failed to create an Overseer: {:?}", e))) +} + #[cfg(feature = "full-node")] pub struct NewFull { pub task_manager: TaskManager,