From bda82e60377edd82780bac88633294207003b605 Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Fri, 9 Jul 2021 14:55:07 +0200 Subject: [PATCH 01/11] chore: unused deps --- node/overseer/Cargo.toml | 4 +--- node/overseer/src/lib.rs | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/node/overseer/Cargo.toml b/node/overseer/Cargo.toml index 76f96e0a4182..6f436c0d33fb 100644 --- a/node/overseer/Cargo.toml +++ b/node/overseer/Cargo.toml @@ -21,10 +21,8 @@ tracing = "0.1.26" lru = "0.6" [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } -polkadot-node-network-protocol = { path = "../network/protocol" } -polkadot-node-metrics = { path = "../metrics" } metered-channel = { path = "../metered-channel" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = { version = "0.3.15", features = ["thread-pool"] } femme = "2.1.1" kv-log-macro = "1.0.7" diff --git a/node/overseer/src/lib.rs b/node/overseer/src/lib.rs index ab30b9557df5..d712b8943a67 100644 --- a/node/overseer/src/lib.rs +++ b/node/overseer/src/lib.rs @@ -58,6 +58,7 @@ // unused dependencies can not work for test and examples at the same time // yielding false positives #![warn(missing_docs)] +#![deny(unused_crate_dependencies)] use std::fmt::{self, Debug}; use std::pin::Pin; From 4b0077ecae33e753efd7182e4b8eb3178f580d25 Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Fri, 9 Jul 2021 17:44:53 +0200 Subject: [PATCH 02/11] base --- Cargo.lock | 3 - node/collation-generation/src/lib.rs | 5 +- node/core/approval-voting/src/import.rs | 4 +- node/core/approval-voting/src/lib.rs | 14 +- node/core/av-store/Cargo.toml | 2 +- node/core/av-store/src/lib.rs | 17 +- node/core/candidate-validation/src/lib.rs | 8 +- node/core/chain-api/src/lib.rs | 4 +- node/core/chain-selection/src/lib.rs | 5 +- node/core/dispute-coordinator/src/lib.rs | 11 +- node/core/dispute-participation/src/lib.rs | 4 +- node/core/runtime-api/src/lib.rs | 4 +- node/malus/src/lib.rs | 4 +- node/network/approval-distribution/src/lib.rs | 29 +- .../availability-distribution/src/lib.rs | 4 +- node/network/availability-recovery/src/lib.rs | 7 +- node/network/bitfield-distribution/src/lib.rs | 4 +- node/network/bridge/src/lib.rs | 16 +- .../src/collator_side/mod.rs | 11 - node/network/collator-protocol/src/lib.rs | 6 +- .../src/validator_side/mod.rs | 32 +-- node/network/dispute-distribution/src/lib.rs | 12 +- node/network/gossip-support/src/lib.rs | 10 +- .../network/statement-distribution/src/lib.rs | 31 ++- node/overseer/Cargo.toml | 3 - node/overseer/examples/minimal-example.rs | 14 +- node/overseer/overseer-gen/examples/dummy.rs | 4 +- .../proc-macro/src/impl_builder.rs | 10 +- .../overseer-gen/proc-macro/src/impl_misc.rs | 248 ------------------ .../overseer-gen/proc-macro/src/lib.rs | 13 +- node/overseer/overseer-gen/src/lib.rs | 94 ------- node/overseer/src/lib.rs | 62 ++--- node/overseer/src/subsystems.rs | 18 +- node/overseer/src/tests.rs | 4 +- node/subsystem-test-helpers/src/lib.rs | 4 +- node/subsystem-types/src/errors.rs | 3 - node/subsystem-util/src/lib.rs | 10 +- .../src/rolling_session_window.rs | 4 +- node/subsystem-util/src/runtime/mod.rs | 2 +- node/subsystem/src/lib.rs | 51 ---- 40 files changed, 153 insertions(+), 638 deletions(-) delete mode 100644 node/overseer/overseer-gen/proc-macro/src/impl_misc.rs diff --git a/Cargo.lock b/Cargo.lock index 602d122c05da..57d7dbfcb83c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6520,16 +6520,13 @@ name = "polkadot-overseer" version = "0.1.0" dependencies = [ "assert_matches", - "async-trait", "femme", "futures 0.3.15", - "futures-timer 3.0.2", "kv-log-macro", "lru", "metered-channel", "polkadot-node-metrics", "polkadot-node-network-protocol", - "polkadot-node-primitives", "polkadot-node-subsystem-types", "polkadot-overseer-all-subsystems-gen", "polkadot-overseer-gen", diff --git a/node/collation-generation/src/lib.rs b/node/collation-generation/src/lib.rs index 72a1beaeafe8..77aaf03cd0b4 100644 --- a/node/collation-generation/src/lib.rs +++ b/node/collation-generation/src/lib.rs @@ -85,7 +85,6 @@ impl CollationGenerationSubsystem { /// Otherwise, most are logged and then discarded. async fn run(mut self, mut ctx: Context) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { // when we activate new leaves, we spawn a bunch of sub-tasks, each of which is @@ -123,7 +122,6 @@ impl CollationGenerationSubsystem { sender: &mpsc::Sender, ) -> bool where - Context: SubsystemContext, Context: overseer::SubsystemContext, { match incoming { @@ -169,9 +167,8 @@ impl CollationGenerationSubsystem { } } -impl overseer::Subsystem for CollationGenerationSubsystem +impl overseer::overseer::Subsystem for CollationGenerationSubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { diff --git a/node/core/approval-voting/src/import.rs b/node/core/approval-voting/src/import.rs index 93bcd69e74af..44cc3b248da1 100644 --- a/node/core/approval-voting/src/import.rs +++ b/node/core/approval-voting/src/import.rs @@ -85,7 +85,7 @@ struct ImportedBlockInfoEnv<'a> { // Computes information about the imported block. Returns `None` if the info couldn't be extracted - // failure to communicate with overseer, async fn imported_block_info( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, env: ImportedBlockInfoEnv<'_>, block_hash: Hash, block_header: &Header, @@ -286,7 +286,7 @@ pub struct BlockImportedCandidates { /// /// It is the responsibility of the caller to schedule wakeups for each block. pub(crate) async fn handle_new_head( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, state: &mut State, db: &mut OverlayedBackend<'_, impl Backend>, head: Hash, diff --git a/node/core/approval-voting/src/lib.rs b/node/core/approval-voting/src/lib.rs index aff7a8ee1499..03a2ee93044d 100644 --- a/node/core/approval-voting/src/lib.rs +++ b/node/core/approval-voting/src/lib.rs @@ -29,7 +29,7 @@ use polkadot_node_subsystem::{ AvailabilityRecoveryMessage, ChainSelectionMessage, }, errors::RecoveryError, - overseer::{self, SubsystemSender as _}, SubsystemContext, SubsystemError, SubsystemResult, SpawnedSubsystem, + overseer::{self, SubsystemSender as _}, SubsystemError, SubsystemResult, SpawnedSubsystem, FromOverseer, OverseerSignal, SubsystemSender, }; use polkadot_node_subsystem_util::{ @@ -333,9 +333,8 @@ impl ApprovalVotingSubsystem { } } -impl overseer::Subsystem for ApprovalVotingSubsystem +impl overseer::overseer::Subsystem for ApprovalVotingSubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, { @@ -674,7 +673,6 @@ async fn run( mut backend: B, ) -> SubsystemResult<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext, B: Backend, { @@ -801,7 +799,7 @@ async fn run( // // returns `true` if any of the actions was a `Conclude` command. async fn handle_actions( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, state: &mut State, overlayed_db: &mut OverlayedBackend<'_, impl Backend>, metrics: &Metrics, @@ -1021,7 +1019,7 @@ fn distribution_messages_for_activation( // Handle an incoming signal from the overseer. Returns true if execution should conclude. async fn handle_from_overseer( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, state: &mut State, db: &mut OverlayedBackend<'_, impl Backend>, metrics: &Metrics, @@ -1134,7 +1132,7 @@ async fn handle_from_overseer( } async fn handle_approved_ancestor( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, db: &OverlayedBackend<'_, impl Backend>, target: Hash, lower_bound: BlockNumber, @@ -1998,7 +1996,7 @@ fn process_wakeup( // spawned. When the background work is no longer needed, the `AbortHandle` should be dropped // to cancel the background work and any requests it has spawned. async fn launch_approval( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, metrics: Metrics, session_index: SessionIndex, candidate: CandidateReceipt, diff --git a/node/core/av-store/Cargo.toml b/node/core/av-store/Cargo.toml index f60dfd42b36e..4eedcdda191b 100644 --- a/node/core/av-store/Cargo.toml +++ b/node/core/av-store/Cargo.toml @@ -14,7 +14,7 @@ bitvec = "0.20.1" parity-scale-codec = { version = "2.0.0", features = ["derive"] } erasure = { package = "polkadot-erasure-coding", path = "../../../erasure-coding" } -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" } +polkadot-node-subsystem = { path = "../../subsystem" } polkadot-node-subsystem-util = { path = "../../subsystem-util" } polkadot-overseer = { path = "../../overseer" } polkadot-primitives = { path = "../../../primitives" } diff --git a/node/core/av-store/src/lib.rs b/node/core/av-store/src/lib.rs index 0160e87c434e..704afb0e4e78 100644 --- a/node/core/av-store/src/lib.rs +++ b/node/core/av-store/src/lib.rs @@ -36,20 +36,21 @@ use polkadot_primitives::v1::{ use polkadot_node_primitives::{ ErasureChunk, AvailableData, }; -use polkadot_subsystem::{ +use polkadot_node_subsystem::{ FromOverseer, OverseerSignal, SubsystemError, SubsystemContext, SpawnedSubsystem, overseer, ActiveLeavesUpdate, errors::{ChainApiError, RuntimeApiError}, + messages::{ + AvailabilityStoreMessage, ChainApiMessage, RuntimeApiMessage, RuntimeApiRequest, + } }; use polkadot_node_subsystem_util::{ self as util, metrics::{self, prometheus}, }; -use polkadot_subsystem::messages::{ - AvailabilityStoreMessage, ChainApiMessage, RuntimeApiMessage, RuntimeApiRequest, -}; +use polkadot_subsystem::; use bitvec::{vec::BitVec, order::Lsb0 as BitOrderLsb0}; #[cfg(test)] @@ -524,9 +525,8 @@ impl KnownUnfinalizedBlocks { } } -impl overseer::Subsystem for AvailabilityStoreSubsystem +impl overseer::overseer::Subsystem for AvailabilityStoreSubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -543,7 +543,6 @@ where async fn run(mut subsystem: AvailabilityStoreSubsystem, mut ctx: Context) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let mut next_pruning = Delay::new(subsystem.pruning_config.pruning_interval).fuse(); @@ -574,7 +573,6 @@ async fn run_iteration( ) -> Result where - Context: SubsystemContext, Context: overseer::SubsystemContext, { select! { @@ -626,7 +624,6 @@ async fn process_block_activated( activated: Hash, ) -> Result<(), Error> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let now = subsystem.clock.now()?; @@ -686,7 +683,6 @@ async fn process_new_head( header: Header, ) -> Result<(), Error> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { @@ -855,7 +851,6 @@ async fn process_block_finalized( finalized_number: BlockNumber, ) -> Result<(), Error> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let now = subsystem.clock.now()?; diff --git a/node/core/candidate-validation/src/lib.rs b/node/core/candidate-validation/src/lib.rs index 9b22d82a3704..466f5be18331 100644 --- a/node/core/candidate-validation/src/lib.rs +++ b/node/core/candidate-validation/src/lib.rs @@ -85,9 +85,8 @@ impl CandidateValidationSubsystem { } } -impl overseer::Subsystem for CandidateValidationSubsystem +impl overseer::overseer::Subsystem for CandidateValidationSubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -108,7 +107,6 @@ async fn run( program_path: PathBuf, ) -> SubsystemResult<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let (mut validation_host, task) = polkadot_node_core_pvf::start( @@ -188,7 +186,6 @@ async fn runtime_api_request( receiver: oneshot::Receiver>, ) -> SubsystemResult> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { ctx.send_message( @@ -214,7 +211,6 @@ async fn check_assumption_validation_data( assumption: OccupiedCoreAssumption, ) -> SubsystemResult where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let validation_data = { @@ -267,7 +263,6 @@ async fn find_assumed_validation_data( descriptor: &CandidateDescriptor, ) -> SubsystemResult where - Context: SubsystemContext, Context: overseer::SubsystemContext, { // The candidate descriptor has a `persisted_validation_data_hash` which corresponds to @@ -305,7 +300,6 @@ async fn spawn_validate_from_chain_state( metrics: &Metrics, ) -> SubsystemResult> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let (validation_data, validation_code) = diff --git a/node/core/chain-api/src/lib.rs b/node/core/chain-api/src/lib.rs index 264a27644d1f..c70ef0923694 100644 --- a/node/core/chain-api/src/lib.rs +++ b/node/core/chain-api/src/lib.rs @@ -67,10 +67,9 @@ impl ChainApiSubsystem { } } -impl overseer::Subsystem for ChainApiSubsystem +impl overseer::overseer::Subsystem for ChainApiSubsystem where Client: HeaderBackend + AuxStore + 'static, - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -90,7 +89,6 @@ async fn run( ) -> SubsystemResult<()> where Client: HeaderBackend + AuxStore, - Context: SubsystemContext, Context: overseer::SubsystemContext, { loop { diff --git a/node/core/chain-selection/src/lib.rs b/node/core/chain-selection/src/lib.rs index a52119c76ef5..363c26eb6e43 100644 --- a/node/core/chain-selection/src/lib.rs +++ b/node/core/chain-selection/src/lib.rs @@ -306,9 +306,8 @@ impl ChainSelectionSubsystem { } } -impl overseer::Subsystem for ChainSelectionSubsystem +impl overseer::overseer::Subsystem for ChainSelectionSubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -338,7 +337,6 @@ async fn run( clock: Box, ) where - Context: SubsystemContext, Context: overseer::SubsystemContext, B: Backend, { @@ -378,7 +376,6 @@ async fn run_iteration( ) -> Result<(), Error> where - Context: SubsystemContext, Context: overseer::SubsystemContext, B: Backend, { diff --git a/node/core/dispute-coordinator/src/lib.rs b/node/core/dispute-coordinator/src/lib.rs index c7038e424611..7f54abeec3cc 100644 --- a/node/core/dispute-coordinator/src/lib.rs +++ b/node/core/dispute-coordinator/src/lib.rs @@ -97,9 +97,8 @@ impl DisputeCoordinatorSubsystem { } } -impl overseer::Subsystem for DisputeCoordinatorSubsystem +impl overseer::overseer::Subsystem for DisputeCoordinatorSubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -163,8 +162,7 @@ impl Error { async fn run(subsystem: DisputeCoordinatorSubsystem, mut ctx: Context) where Context: overseer::SubsystemContext, - Context: SubsystemContext -{ + { loop { let res = run_iteration(&mut ctx, &subsystem).await; match res { @@ -192,8 +190,7 @@ async fn run_iteration(ctx: &mut Context, subsystem: &DisputeCoordinato -> Result<(), Error> where Context: overseer::SubsystemContext, - Context: SubsystemContext -{ + { let DisputeCoordinatorSubsystem { ref store, ref keystore, ref config } = *subsystem; let mut state = State { keystore: keystore.clone(), @@ -230,7 +227,7 @@ where } async fn handle_new_activations( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut (overseer::SubsystemContext), store: &dyn KeyValueDB, state: &mut State, config: &Config, diff --git a/node/core/dispute-participation/src/lib.rs b/node/core/dispute-participation/src/lib.rs index 619da6978575..e9c488ffdbeb 100644 --- a/node/core/dispute-participation/src/lib.rs +++ b/node/core/dispute-participation/src/lib.rs @@ -56,9 +56,8 @@ impl DisputeParticipationSubsystem { } } -impl overseer::Subsystem for DisputeParticipationSubsystem +impl overseer::overseer::Subsystem for DisputeParticipationSubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -115,7 +114,6 @@ impl Error { async fn run(mut ctx: Context) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let mut state = State { recent_block: None }; diff --git a/node/core/runtime-api/src/lib.rs b/node/core/runtime-api/src/lib.rs index 88c85a03726d..d1d86f03d1bb 100644 --- a/node/core/runtime-api/src/lib.rs +++ b/node/core/runtime-api/src/lib.rs @@ -87,10 +87,9 @@ impl RuntimeApiSubsystem { } } -impl overseer::Subsystem for RuntimeApiSubsystem where +impl overseer::overseer::Subsystem for RuntimeApiSubsystem where Client: ProvideRuntimeApi + Send + 'static + Sync, Client::Api: ParachainHost + BabeApi + AuthorityDiscoveryApi, - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -274,7 +273,6 @@ async fn run( ) -> SubsystemResult<()> where Client: ProvideRuntimeApi + Send + Sync + 'static, Client::Api: ParachainHost + BabeApi + AuthorityDiscoveryApi, - Context: SubsystemContext, Context: overseer::SubsystemContext, { loop { diff --git a/node/malus/src/lib.rs b/node/malus/src/lib.rs index 516d4840b3c4..555c22bf0652 100644 --- a/node/malus/src/lib.rs +++ b/node/malus/src/lib.rs @@ -50,7 +50,7 @@ pub struct FilteredSender { } #[async_trait::async_trait] -impl overseer::SubsystemSender for FilteredSender +impl overseer::SubsystemSenderAllMessages> for FilteredSender where Sender: overseer::SubsystemSender, Fil: MsgFilter, @@ -174,7 +174,7 @@ impl FilteredSubsystem { } } -impl overseer::Subsystem for FilteredSubsystem +impl overseer::overseer::Subsystem for FilteredSubsystem where Context: overseer::SubsystemContext + SubsystemContext + Sync + Send, Sub: overseer::Subsystem, SubsystemError>, diff --git a/node/network/approval-distribution/src/lib.rs b/node/network/approval-distribution/src/lib.rs index c0848a328173..ba895939e3c4 100644 --- a/node/network/approval-distribution/src/lib.rs +++ b/node/network/approval-distribution/src/lib.rs @@ -189,7 +189,7 @@ enum PendingMessage { impl State { async fn handle_network_msg( &mut self, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut (overseer::SubsystemContext), metrics: &Metrics, event: NetworkBridgeEvent, ) { @@ -259,7 +259,8 @@ impl State { async fn handle_new_blocks( &mut self, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), metrics: &Metrics, + ctx: &mut (overseer::SubsystemContext), + metrics: &Metrics, metas: Vec, ) { let mut new_hashes = HashSet::new(); @@ -361,7 +362,8 @@ impl State { async fn process_incoming_peer_message( &mut self, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), metrics: &Metrics, + ctx: &mut (overseer::SubsystemContext), + metrics: &Metrics, peer_id: PeerId, msg: protocol_v1::ApprovalDistributionMessage, ) { @@ -448,7 +450,8 @@ impl State { async fn handle_peer_view_change( &mut self, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), metrics: &Metrics, + ctx: &mut (overseer::SubsystemContext), + metrics: &Metrics, peer_id: PeerId, view: View, ) { @@ -511,7 +514,8 @@ impl State { async fn import_and_circulate_assignment( &mut self, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), metrics: &Metrics, + ctx: &mut (overseer::SubsystemContext), + metrics: &Metrics, source: MessageSource, assignment: IndirectAssignmentCert, claimed_candidate_index: CandidateIndex, @@ -747,7 +751,8 @@ impl State { async fn import_and_circulate_approval( &mut self, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), metrics: &Metrics, + ctx: &mut (overseer::SubsystemContext), + metrics: &Metrics, source: MessageSource, vote: IndirectSignedApprovalVote, ) { @@ -991,7 +996,7 @@ impl State { } async fn unify_with_peer( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), gossip_peers: &HashSet, + ctx: &mut (overseer::SubsystemContext), gossip_peers: &HashSet, metrics: &Metrics, entries: &mut HashMap, peer_id: PeerId, @@ -1056,7 +1061,8 @@ impl State { async fn send_gossip_messages_to_peer( entries: &HashMap, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), peer_id: PeerId, + ctx: &mut mut overseer::SubsystemContext), + peer_id: PeerId, blocks: Vec, ) { let mut assignments = Vec::new(); @@ -1150,7 +1156,7 @@ impl State { /// Modify the reputation of a peer based on its behavior. async fn modify_reputation( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut (overseer::SubsystemContext), peer_id: PeerId, rep: Rep, ) { @@ -1174,7 +1180,6 @@ impl ApprovalDistribution { async fn run(self, ctx: Context) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let mut state = State::default(); @@ -1184,7 +1189,6 @@ impl ApprovalDistribution { /// Used for testing. async fn run_inner(self, mut ctx: Context, state: &mut State) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { loop { @@ -1258,9 +1262,8 @@ impl ApprovalDistribution { } } -impl overseer::Subsystem for ApprovalDistribution +impl overseer::overseer::Subsystem for ApprovalDistribution where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { diff --git a/node/network/availability-distribution/src/lib.rs b/node/network/availability-distribution/src/lib.rs index 67de44ccdcb8..d753d4754d06 100644 --- a/node/network/availability-distribution/src/lib.rs +++ b/node/network/availability-distribution/src/lib.rs @@ -59,9 +59,8 @@ pub struct AvailabilityDistributionSubsystem { metrics: Metrics, } -impl overseer::Subsystem for AvailabilityDistributionSubsystem +impl overseer::overseer::Subsystem for AvailabilityDistributionSubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -88,7 +87,6 @@ impl AvailabilityDistributionSubsystem { /// Start processing work as passed on from the Overseer. async fn run(mut self, mut ctx: Context) -> std::result::Result<(), Fatal> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let mut requester = Requester::new(self.metrics.clone()).fuse(); diff --git a/node/network/availability-recovery/src/lib.rs b/node/network/availability-recovery/src/lib.rs index b164675083d1..c24dedc57996 100644 --- a/node/network/availability-recovery/src/lib.rs +++ b/node/network/availability-recovery/src/lib.rs @@ -574,9 +574,8 @@ impl Default for State { } } -impl Subsystem for AvailabilityRecoverySubsystem +impl overseer::Subsystem for AvailabilityRecoverySubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -621,7 +620,6 @@ async fn launch_interaction( response_sender: oneshot::Sender>, ) -> error::Result<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let candidate_hash = receipt.hash(); @@ -678,7 +676,6 @@ async fn handle_recover( response_sender: oneshot::Sender>, ) -> error::Result<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let candidate_hash = receipt.hash(); @@ -740,7 +737,6 @@ async fn query_full_data( candidate_hash: CandidateHash, ) -> error::Result> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let (tx, rx) = oneshot::channel(); @@ -767,7 +763,6 @@ impl AvailabilityRecoverySubsystem { mut ctx: Context, ) -> SubsystemResult<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let mut state = State::default(); diff --git a/node/network/bitfield-distribution/src/lib.rs b/node/network/bitfield-distribution/src/lib.rs index e339e6dc66f2..c5d11f9b8699 100644 --- a/node/network/bitfield-distribution/src/lib.rs +++ b/node/network/bitfield-distribution/src/lib.rs @@ -162,7 +162,6 @@ impl BitfieldDistribution { /// Start processing work as passed on from the Overseer. async fn run(self, mut ctx: Context) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { // work: process incoming messages from the overseer and process accordingly. @@ -697,9 +696,8 @@ where ).await; } -impl overseer::Subsystem for BitfieldDistribution +impl overseer::overseer::Subsystem for BitfieldDistribution where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { diff --git a/node/network/bridge/src/lib.rs b/node/network/bridge/src/lib.rs index 6f963e97c2aa..84f0153d9ecb 100644 --- a/node/network/bridge/src/lib.rs +++ b/node/network/bridge/src/lib.rs @@ -28,9 +28,8 @@ use polkadot_subsystem::messages::DisputeDistributionMessage; use sc_network::Event as NetworkEvent; use sp_consensus::SyncOracle; -use polkadot_overseer::gen::{ +use polkadot_overseer::{ Subsystem, - OverseerError, }; use polkadot_subsystem::{ overseer, @@ -305,11 +304,11 @@ impl NetworkBridge { } } -impl Subsystem for NetworkBridge +impl overseer::Subsystem for NetworkBridge where Net: Network + Sync, AD: validator_discovery::AuthorityDiscovery + Clone, - Context: SubsystemContext + overseer::SubsystemContext, + overseer::SubsystemContext, { fn start(mut self, ctx: Context) -> SpawnedSubsystem { // The stream of networking events has to be created at initialization, otherwise the @@ -351,12 +350,6 @@ impl From for UnexpectedAbort { } } -impl From for UnexpectedAbort { - fn from(e: OverseerError) -> Self { - UnexpectedAbort::SubsystemError(SubsystemError::from(e)) - } -} - #[derive(Default, Clone)] struct Shared(Arc>); @@ -381,7 +374,6 @@ async fn handle_subsystem_messages( metrics: Metrics, ) -> Result<(), UnexpectedAbort> where - Context: SubsystemContext, Context: overseer::SubsystemContext, N: Network, AD: validator_discovery::AuthorityDiscovery + Clone, @@ -882,7 +874,7 @@ async fn run_network( where N: Network, AD: validator_discovery::AuthorityDiscovery + Clone, - Context: SubsystemContext + overseer::SubsystemContext, + Context: overseer::SubsystemContext, { let shared = Shared::default(); diff --git a/node/network/collator-protocol/src/collator_side/mod.rs b/node/network/collator-protocol/src/collator_side/mod.rs index 6baa865232e3..f42e337184d3 100644 --- a/node/network/collator-protocol/src/collator_side/mod.rs +++ b/node/network/collator-protocol/src/collator_side/mod.rs @@ -312,7 +312,6 @@ async fn distribute_collation( result_sender: Option>, ) -> Result<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let relay_parent = receipt.descriptor.relay_parent; @@ -411,7 +410,6 @@ async fn determine_core( relay_parent: Hash, ) -> Result> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let cores = get_availability_cores(ctx, relay_parent).await?; @@ -447,7 +445,6 @@ async fn determine_our_validators( relay_parent: Hash, ) -> Result<(GroupValidators, GroupValidators)> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let session_index = runtime.get_session_index(ctx.sender(), relay_parent).await?; @@ -488,7 +485,6 @@ async fn declare( peer: PeerId, ) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let declare_signature_payload = protocol_v1::declare_signature_payload(&state.local_peer_id); @@ -516,7 +512,6 @@ async fn connect_to_validators( validator_ids: Vec, ) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { // ignore address resolution failure @@ -538,7 +533,6 @@ async fn advertise_collation( peer: PeerId, ) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let should_advertise = state.our_validators_groups @@ -602,7 +596,6 @@ async fn process_msg( msg: CollatorProtocolMessage, ) -> Result<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { use CollatorProtocolMessage::*; @@ -755,7 +748,6 @@ async fn handle_incoming_peer_message( msg: protocol_v1::CollatorProtocolMessage, ) -> Result<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { use protocol_v1::CollatorProtocolMessage::*; @@ -829,7 +821,6 @@ async fn handle_peer_view_change( view: View, ) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let current = state.peer_views.entry(peer_id.clone()).or_default(); @@ -851,7 +842,6 @@ async fn handle_network_msg( bridge_message: NetworkBridgeEvent, ) -> Result<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { use NetworkBridgeEvent::*; @@ -965,7 +955,6 @@ pub(crate) async fn run( metrics: Metrics, ) -> Result<()> where - Context: SubsystemContext, Context: overseer::SubsystemContext { use OverseerSignal::*; diff --git a/node/network/collator-protocol/src/lib.rs b/node/network/collator-protocol/src/lib.rs index 96af19aa1e58..10ad267722b6 100644 --- a/node/network/collator-protocol/src/lib.rs +++ b/node/network/collator-protocol/src/lib.rs @@ -100,8 +100,7 @@ impl CollatorProtocolSubsystem { async fn run(self, ctx: Context) -> Result<()> where Context: overseer::SubsystemContext, - Context: SubsystemContext, - { + { match self.protocol_side { ProtocolSide::Validator { keystore, eviction_policy, metrics } => validator_side::run( ctx, @@ -119,9 +118,8 @@ impl CollatorProtocolSubsystem { } } -impl overseer::Subsystem for CollatorProtocolSubsystem +impl overseer::overseer::Subsystem for CollatorProtocolSubsystem where - Context: SubsystemContext, Context: overseer::SubsystemContext, ::Sender: SubsystemSender, { diff --git a/node/network/collator-protocol/src/validator_side/mod.rs b/node/network/collator-protocol/src/validator_side/mod.rs index bd6d9cc86ba6..5e98fab42c80 100644 --- a/node/network/collator-protocol/src/validator_side/mod.rs +++ b/node/network/collator-protocol/src/validator_side/mod.rs @@ -587,7 +587,6 @@ fn collator_peer_id( async fn disconnect_peer(ctx: &mut Context, peer_id: PeerId) where Context: overseer::SubsystemContext, - Context: SubsystemContext, { ctx.send_message( NetworkBridgeMessage::DisconnectPeer(peer_id, PeerSet::Collation) @@ -603,7 +602,6 @@ async fn fetch_collation( ) where Context: overseer::SubsystemContext, - Context: SubsystemContext, { let (tx, rx) = oneshot::channel(); @@ -637,8 +635,7 @@ async fn note_good_collation( ) where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { if let Some(peer_id) = collator_peer_id(peer_data, &id) { modify_reputation(ctx, peer_id, BENEFIT_NOTIFY_GOOD).await; } @@ -653,8 +650,7 @@ async fn notify_collation_seconded( ) where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { let wire_message = protocol_v1::CollatorProtocolMessage::CollationSeconded(relay_parent, statement.into()); ctx.send_message( NetworkBridgeMessage::SendCollationMessage( @@ -699,8 +695,7 @@ async fn request_collation( ) where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { if !state.view.contains(&relay_parent) { tracing::debug!( target: LOG_TARGET, @@ -766,8 +761,7 @@ async fn process_incoming_peer_message( ) where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { use protocol_v1::CollatorProtocolMessage::*; use sp_runtime::traits::AppVerify; match msg { @@ -921,8 +915,7 @@ async fn handle_our_view_change( ) -> Result<()> where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { let old_view = std::mem::replace(&mut state.view, view); let added: HashMap> = state.view @@ -976,8 +969,7 @@ async fn handle_network_msg( ) -> Result<()> where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { use NetworkBridgeEvent::*; match bridge_message { @@ -1015,8 +1007,7 @@ async fn process_msg( ) where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { use CollatorProtocolMessage::*; let _timer = state.metrics.time_process_msg(); @@ -1125,8 +1116,7 @@ pub(crate) async fn run( ) -> Result<()> where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { use OverseerSignal::*; let mut state = State { @@ -1189,8 +1179,7 @@ async fn handle_collation_fetched_result( ) where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { // If no prior collation for this relay parent has been seconded, then // memoize the collation_event for that relay_parent, such that we may // notify the collator of their successful second backing @@ -1255,8 +1244,7 @@ async fn disconnect_inactive_peers( ) where Context: overseer::SubsystemContext, - Context: SubsystemContext, -{ + { for (peer, peer_data) in peers { if peer_data.is_inactive(&eviction_policy) { disconnect_peer(ctx, peer.clone()).await; diff --git a/node/network/dispute-distribution/src/lib.rs b/node/network/dispute-distribution/src/lib.rs index c9e53ad4489a..dbdffdcf8582 100644 --- a/node/network/dispute-distribution/src/lib.rs +++ b/node/network/dispute-distribution/src/lib.rs @@ -116,10 +116,9 @@ pub struct DisputeDistributionSubsystem { metrics: Metrics, } -impl overseer::Subsystem for DisputeDistributionSubsystem +impl overseer::overseer::Subsystem for DisputeDistributionSubsystem where - Context: SubsystemContext - + overseer::SubsystemContext + Context: overseer::SubsystemContext + Sync + Send, AD: AuthorityDiscovery + Clone, { @@ -136,7 +135,7 @@ where } } -impl DisputeDistributionSubsystem +impl DisputeDistributionSubsystem where AD: AuthorityDiscovery + Clone, { @@ -154,8 +153,7 @@ where /// Start processing work as passed on from the Overseer. async fn run(mut self, mut ctx: Context) -> std::result::Result<(), Fatal> where - Context: SubsystemContext - + overseer::SubsystemContext + Context: overseer::SubsystemContext + Sync + Send, { loop { @@ -248,7 +246,7 @@ enum MuxedMessage { impl MuxedMessage { async fn receive( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut (overseer::SubsystemContext), from_sender: &mut mpsc::Receiver, ) -> Self { // We are only fusing here to make `select` happy, in reality we will quit if the stream diff --git a/node/network/gossip-support/src/lib.rs b/node/network/gossip-support/src/lib.rs index fc56e75febd7..db69ac5a6802 100644 --- a/node/network/gossip-support/src/lib.rs +++ b/node/network/gossip-support/src/lib.rs @@ -97,7 +97,6 @@ impl GossipSupport { async fn run(self, ctx: Context) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let mut state = State::default(); @@ -106,7 +105,6 @@ impl GossipSupport { async fn run_inner(self, mut ctx: Context, state: &mut State) where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let Self { keystore } = self; @@ -149,7 +147,6 @@ async fn determine_relevant_authorities( relay_parent: Hash, ) -> Result, util::Error> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let authorities = util::request_authorities(relay_parent, ctx.sender()).await.await??; @@ -185,7 +182,6 @@ async fn connect_to_authorities( peer_set: PeerSet, ) -> oneshot::Receiver where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let (failed, failed_rx) = oneshot::channel(); @@ -214,7 +210,6 @@ async fn update_gossip_topology( relay_parent: Hash, ) -> Result<(), util::Error> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { // retrieve BABE randomness @@ -287,7 +282,6 @@ impl State { leaves: impl Iterator, ) -> Result<(), util::Error> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { for leaf in leaves { @@ -338,7 +332,6 @@ impl State { authorities: Vec, ) -> Result<(), util::Error> where - Context: SubsystemContext, Context: overseer::SubsystemContext, { let num = authorities.len(); @@ -388,9 +381,8 @@ impl State { } } -impl overseer::Subsystem for GossipSupport +impl overseer::overseer::Subsystem for GossipSupport where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { diff --git a/node/network/statement-distribution/src/lib.rs b/node/network/statement-distribution/src/lib.rs index 81e87d8ba35c..d6cfbf5d04e8 100644 --- a/node/network/statement-distribution/src/lib.rs +++ b/node/network/statement-distribution/src/lib.rs @@ -108,9 +108,8 @@ pub struct StatementDistribution { metrics: Metrics, } -impl overseer::Subsystem for StatementDistribution +impl overseer::overseer::Subsystem for StatementDistribution where - Context: SubsystemContext, Context: overseer::SubsystemContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -591,7 +590,7 @@ enum MuxedMessage { impl MuxedMessage { async fn receive( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut (overseer::SubsystemContext), from_requester: &mut mpsc::Receiver, from_responder: &mut mpsc::Receiver, ) -> MuxedMessage { @@ -849,7 +848,7 @@ async fn circulate_statement_and_dependents( gossip_peers: &HashSet, peers: &mut HashMap, active_heads: &mut HashMap, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, relay_parent: Hash, statement: SignedFullStatement, priority_peers: Vec, @@ -956,7 +955,7 @@ fn is_statement_large(statement: &SignedFullStatement) -> bool { async fn circulate_statement<'a>( gossip_peers: &HashSet, peers: &mut HashMap, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, relay_parent: Hash, stored: StoredStatement<'a>, mut priority_peers: Vec, @@ -1037,7 +1036,7 @@ async fn circulate_statement<'a>( async fn send_statements_about( peer: PeerId, peer_data: &mut PeerData, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, relay_parent: Hash, candidate_hash: CandidateHash, active_head: &ActiveHeadData, @@ -1074,7 +1073,7 @@ async fn send_statements_about( async fn send_statements( peer: PeerId, peer_data: &mut PeerData, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, relay_parent: Hash, active_head: &ActiveHeadData, metrics: &Metrics, @@ -1106,7 +1105,7 @@ async fn send_statements( } async fn report_peer( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, peer: PeerId, rep: Rep, ) { @@ -1126,7 +1125,7 @@ async fn retrieve_statement_from_message<'a>( peer: PeerId, message: protocol_v1::StatementDistributionMessage, active_head: &'a mut ActiveHeadData, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, req_sender: &mpsc::Sender, metrics: &Metrics, ) -> Option { @@ -1228,7 +1227,7 @@ async fn launch_request( meta: StatementMetadata, peer: PeerId, req_sender: mpsc::Sender, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, metrics: &Metrics, ) -> Option { @@ -1266,7 +1265,7 @@ async fn handle_incoming_message_and_circulate<'a>( gossip_peers: &HashSet, peers: &mut HashMap, active_heads: &'a mut HashMap, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, message: protocol_v1::StatementDistributionMessage, req_sender: &mpsc::Sender, metrics: &Metrics, @@ -1315,7 +1314,7 @@ async fn handle_incoming_message<'a>( peer: PeerId, peer_data: &mut PeerData, active_heads: &'a mut HashMap, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, message: protocol_v1::StatementDistributionMessage, req_sender: &mpsc::Sender, metrics: &Metrics, @@ -1462,7 +1461,7 @@ async fn update_peer_view_and_maybe_send_unlocked( peer: PeerId, gossip_peers: &HashSet, peer_data: &mut PeerData, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, active_heads: &HashMap, new_view: View, metrics: &Metrics, @@ -1506,7 +1505,7 @@ async fn handle_network_update( gossip_peers: &mut HashSet, authorities: &mut HashMap, active_heads: &mut HashMap, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut overseer::SubsystemContext, req_sender: &mpsc::Sender, update: NetworkBridgeEvent, metrics: &Metrics, @@ -1599,7 +1598,7 @@ async fn handle_network_update( impl StatementDistribution { async fn run( self, - mut ctx: (impl SubsystemContext + overseer::SubsystemContext), + mut ctx: impl overseer::SubsystemContext, ) -> std::result::Result<(), Fatal> { let mut peers: HashMap = HashMap::new(); let mut gossip_peers: HashSet = HashSet::new(); @@ -1831,7 +1830,7 @@ impl StatementDistribution { async fn handle_subsystem_message( &self, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, runtime: &mut RuntimeInfo, peers: &mut HashMap, gossip_peers: &mut HashSet, diff --git a/node/overseer/Cargo.toml b/node/overseer/Cargo.toml index 6f436c0d33fb..fe2b6c95ad57 100644 --- a/node/overseer/Cargo.toml +++ b/node/overseer/Cargo.toml @@ -5,13 +5,10 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -async-trait = "0.1.42" client = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "master" } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = "0.3.15" -futures-timer = "3.0.2" polkadot-node-network-protocol = { path = "../network/protocol" } -polkadot-node-primitives = { path = "../primitives" } polkadot-node-subsystem-types = { path = "../subsystem-types" } polkadot-node-metrics = { path = "../metrics" } polkadot-primitives = { path = "../../primitives" } diff --git a/node/overseer/examples/minimal-example.rs b/node/overseer/examples/minimal-example.rs index 71a703f99336..1345889bee7c 100644 --- a/node/overseer/examples/minimal-example.rs +++ b/node/overseer/examples/minimal-example.rs @@ -36,10 +36,8 @@ use polkadot_overseer::{ Overseer, OverseerSignal, SubsystemError, - gen::{ - FromOverseer, - SpawnedSubsystem, - }, + FromOverseer, + SpawnedSubsystem, }; use polkadot_node_subsystem_types::messages::{ CandidateValidationMessage, CandidateBackingMessage, @@ -58,7 +56,7 @@ struct Subsystem1; impl Subsystem1 { async fn run(mut ctx: Ctx) -> () where - Ctx: overseer::SubsystemContext, + Ctx: overseer::SubsystemContext, { 'louy: loop { match ctx.try_recv().await { @@ -92,7 +90,7 @@ impl Subsystem1 { } -impl overseer::Subsystem for Subsystem1 +impl overseer::Subsystem for Subsystem1 where Context: overseer::SubsystemContext, { @@ -144,11 +142,11 @@ impl Subsystem2 { } } -impl overseer::Subsystem for Subsystem2 +impl overseer::overseer::Subsystem for Subsystem2 where Context: overseer::SubsystemContext, { - fn start(self, ctx: Context) -> SpawnedSubsystem { + fn start(self, ctx: Context) -> SpawnedSubsystem { let future = Box::pin(async move { Self::run(ctx).await; Ok(()) diff --git a/node/overseer/overseer-gen/examples/dummy.rs b/node/overseer/overseer-gen/examples/dummy.rs index 401e70e89f2d..e09ed3701a5c 100644 --- a/node/overseer/overseer-gen/examples/dummy.rs +++ b/node/overseer/overseer-gen/examples/dummy.rs @@ -8,7 +8,7 @@ use polkadot_node_network_protocol::WrongVariant; #[derive(Default)] pub struct AwesomeSubSys; -impl ::polkadot_overseer_gen::Subsystem, Yikes> for AwesomeSubSys { +impl Subsystem, Yikes> for AwesomeSubSys { fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem < Yikes > { unimplemented!("starting yay!") } @@ -17,7 +17,7 @@ impl ::polkadot_overseer_gen::Subsystem, Yikes> f #[derive(Default)] pub struct GoblinTower; -impl ::polkadot_overseer_gen::Subsystem, Yikes> for GoblinTower { +impl Subsystem, Yikes> for GoblinTower { fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem < Yikes > { unimplemented!("welcum") } diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs index 256288368b8e..77b73d06fbb1 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs @@ -318,18 +318,18 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { // connection to the subsystems channels_out: ChannelsOut, ctx: Ctx, - s: SubSys, + subsystem: SubSys, futures: &mut #support_crate ::FuturesUnordered >>, ) -> ::std::result::Result, #error_ty > where S: #support_crate ::SpawnNamed, M: std::fmt::Debug + Send + 'static, TK: TaskKind, - Ctx: #support_crate ::SubsystemContext, + Ctx: SubsystemContext, E: std::error::Error + Send + Sync + 'static + From<#support_crate ::OverseerError>, - SubSys: #support_crate ::Subsystem, + SubSys: Subsystem, { - let #support_crate ::SpawnedSubsystem:: { future, name } = s.start(ctx); + let SpawnedSubsystem { future, name } = subsystem.start(ctx); let (tx, rx) = #support_crate ::oneshot::channel(); @@ -351,7 +351,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { }) )); - let instance = Some(SubsystemInstance { + let instance = Some(SubsystemInstance:: < M > { meters: #support_crate ::SubsystemMeters { unbounded: unbounded_meter, bounded: message_tx.meter().clone(), diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_misc.rs b/node/overseer/overseer-gen/proc-macro/src/impl_misc.rs deleted file mode 100644 index b3406b62f7eb..000000000000 --- a/node/overseer/overseer-gen/proc-macro/src/impl_misc.rs +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . - -use quote::quote; -use syn::Ident; - -use super::*; - -/// Implement a builder pattern for the `Overseer`-type, -/// which acts as the gateway to constructing the overseer. -pub(crate) fn impl_misc(info: &OverseerInfo) -> proc_macro2::TokenStream { - let overseer_name = info.overseer_name.clone(); - let subsystem_sender_name = Ident::new(&(overseer_name.to_string() + "SubsystemSender"), overseer_name.span()); - let subsystem_ctx_name = Ident::new(&(overseer_name.to_string() + "SubsystemContext"), overseer_name.span()); - let consumes = &info.consumes(); - let signal = &info.extern_signal_ty; - let wrapper_message = &info.message_wrapper; - let error_ty = &info.extern_error_ty; - let support_crate = info.support_crate_name(); - - let ts = quote! { - /// Connector to send messages towards all subsystems, - /// while tracking the which signals where already received. - #[derive(Debug, Clone)] - pub struct #subsystem_sender_name { - /// Collection of channels to all subsystems. - channels: ChannelsOut, - /// Systemwide tick for which signals were received by all subsystems. - signals_received: SignalsReceived, - } - - /// impl for wrapping message type... - #[#support_crate ::async_trait] - impl SubsystemSender< #wrapper_message > for #subsystem_sender_name { - async fn send_message(&mut self, msg: #wrapper_message) { - self.channels.send_and_log_error(self.signals_received.load(), msg).await; - } - - async fn send_messages(&mut self, msgs: T) - where - T: IntoIterator + Send, - T::IntoIter: Send, - { - // This can definitely be optimized if necessary. - for msg in msgs { - self.send_message(msg).await; - } - } - - fn send_unbounded_message(&mut self, msg: #wrapper_message) { - self.channels.send_unbounded_and_log_error(self.signals_received.load(), msg); - } - } - - // ... but also implement for all individual messages to avoid - // the necessity for manual wrapping, and do the conversion - // based on the generated `From::from` impl for the individual variants. - #( - #[#support_crate ::async_trait] - impl SubsystemSender< #consumes > for #subsystem_sender_name { - async fn send_message(&mut self, msg: #consumes) { - self.channels.send_and_log_error(self.signals_received.load(), #wrapper_message ::from ( msg )).await; - } - - async fn send_messages(&mut self, msgs: T) - where - T: IntoIterator + Send, - T::IntoIter: Send, - { - // This can definitely be optimized if necessary. - for msg in msgs { - self.send_message(msg).await; - } - } - - fn send_unbounded_message(&mut self, msg: #consumes) { - self.channels.send_unbounded_and_log_error(self.signals_received.load(), #wrapper_message ::from ( msg )); - } - } - )* - - /// A context type that is given to the [`Subsystem`] upon spawning. - /// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s - /// or to spawn it's [`SubsystemJob`]s. - /// - /// [`Overseer`]: struct.Overseer.html - /// [`Subsystem`]: trait.Subsystem.html - /// [`SubsystemJob`]: trait.SubsystemJob.html - #[derive(Debug)] - #[allow(missing_docs)] - pub struct #subsystem_ctx_name{ - signals: #support_crate ::metered::MeteredReceiver< #signal >, - messages: SubsystemIncomingMessages, - to_subsystems: #subsystem_sender_name, - to_overseer: #support_crate ::metered::UnboundedMeteredSender< - #support_crate ::ToOverseer - >, - signals_received: SignalsReceived, - pending_incoming: Option<(usize, M)>, - } - - impl #subsystem_ctx_name { - /// Create a new context. - fn new( - signals: #support_crate ::metered::MeteredReceiver< #signal >, - messages: SubsystemIncomingMessages, - to_subsystems: ChannelsOut, - to_overseer: #support_crate ::metered::UnboundedMeteredSender, - ) -> Self { - let signals_received = SignalsReceived::default(); - #subsystem_ctx_name { - signals, - messages, - to_subsystems: #subsystem_sender_name { - channels: to_subsystems, - signals_received: signals_received.clone(), - }, - to_overseer, - signals_received, - pending_incoming: None, - } - } - } - - #[#support_crate ::async_trait] - impl SubsystemContext for #subsystem_ctx_name - where - #subsystem_sender_name: #support_crate ::SubsystemSender< #wrapper_message >, - #wrapper_message: From, - { - type Message = M; - type Signal = #signal; - type Sender = #subsystem_sender_name; - type AllMessages = #wrapper_message; - type Error = #error_ty; - - async fn try_recv(&mut self) -> ::std::result::Result>, ()> { - match #support_crate ::poll!(self.recv()) { - #support_crate ::Poll::Ready(msg) => Ok(Some(msg.map_err(|_| ())?)), - #support_crate ::Poll::Pending => Ok(None), - } - } - - async fn recv(&mut self) -> ::std::result::Result, #error_ty> { - loop { - // If we have a message pending an overseer signal, we only poll for signals - // in the meantime. - if let Some((needs_signals_received, msg)) = self.pending_incoming.take() { - if needs_signals_received <= self.signals_received.load() { - return Ok(#support_crate ::FromOverseer::Communication { msg }); - } else { - self.pending_incoming = Some((needs_signals_received, msg)); - - // wait for next signal. - let signal = self.signals.next().await - .ok_or(#support_crate ::OverseerError::Context( - "Signal channel is terminated and empty." - .to_owned() - ))?; - - self.signals_received.inc(); - return Ok(#support_crate ::FromOverseer::Signal(signal)) - } - } - - let mut await_message = self.messages.next().fuse(); - let mut await_signal = self.signals.next().fuse(); - let signals_received = self.signals_received.load(); - let pending_incoming = &mut self.pending_incoming; - - // Otherwise, wait for the next signal or incoming message. - let from_overseer = #support_crate ::futures::select_biased! { - signal = await_signal => { - let signal = signal - .ok_or(#support_crate ::OverseerError::Context( - "Signal channel is terminated and empty." - .to_owned() - ))?; - - #support_crate ::FromOverseer::Signal(signal) - } - msg = await_message => { - let packet = msg - .ok_or(#support_crate ::OverseerError::Context( - "Message channel is terminated and empty." - .to_owned() - ))?; - - if packet.signals_received > signals_received { - // wait until we've received enough signals to return this message. - *pending_incoming = Some((packet.signals_received, packet.message)); - continue; - } else { - // we know enough to return this message. - #support_crate ::FromOverseer::Communication { msg: packet.message} - } - } - }; - - if let #support_crate ::FromOverseer::Signal(_) = from_overseer { - self.signals_received.inc(); - } - - return Ok(from_overseer); - } - } - - fn sender(&mut self) -> &mut Self::Sender { - &mut self.to_subsystems - } - - fn spawn(&mut self, name: &'static str, s: Pin + Send>>) - -> ::std::result::Result<(), #error_ty> - { - self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnJob { - name, - s, - }).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?; - Ok(()) - } - - fn spawn_blocking(&mut self, name: &'static str, s: Pin + Send>>) - -> ::std::result::Result<(), #error_ty> - { - self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnBlockingJob { - name, - s, - }).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?; - Ok(()) - } - } - }; - - ts -} diff --git a/node/overseer/overseer-gen/proc-macro/src/lib.rs b/node/overseer/overseer-gen/proc-macro/src/lib.rs index 9fecfd19241a..6b16b8312441 100644 --- a/node/overseer/overseer-gen/proc-macro/src/lib.rs +++ b/node/overseer/overseer-gen/proc-macro/src/lib.rs @@ -21,19 +21,21 @@ use syn::{parse2, Result}; use quote::{quote, ToTokens}; mod impl_builder; -mod impl_misc; +mod impl_subsystem_ctx; mod impl_overseer; -mod parse_attr; -mod parse_struct; mod impl_channels_out; mod impl_dispatch; mod impl_message_wrapper; +mod impl_trait; +mod parse_attr; +mod parse_struct; use impl_builder::*; use impl_channels_out::*; use impl_dispatch::*; use impl_message_wrapper::*; -use impl_misc::*; +use impl_subsystem_ctx::*; +use impl_trait::*; use impl_overseer::*; use parse_attr::*; use parse_struct::*; @@ -85,10 +87,11 @@ pub(crate) fn impl_overseer_gen(attr: TokenStream, orig: TokenStream) -> Result< additive.extend(impl_overseen_subsystem(&info)); additive.extend(impl_channels_out_struct(&info)); - additive.extend(impl_misc(&info)); + additive.extend(impl_subsystem_ctx(&info)); additive.extend(impl_message_wrapper_enum(&info)?); additive.extend(impl_dispatch(&info)); + additive.extend(impl_trait(&info)); Ok(additive) } diff --git a/node/overseer/overseer-gen/src/lib.rs b/node/overseer/overseer-gen/src/lib.rs index 4b6abdb2b20a..97133d0b45ba 100644 --- a/node/overseer/overseer-gen/src/lib.rs +++ b/node/overseer/overseer-gen/src/lib.rs @@ -357,100 +357,6 @@ impl From for FromOverseer { } } -/// A context type that is given to the [`Subsystem`] upon spawning. -/// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s -/// or spawn jobs. -/// -/// [`Overseer`]: struct.Overseer.html -/// [`SubsystemJob`]: trait.SubsystemJob.html -#[async_trait::async_trait] -pub trait SubsystemContext: Send + 'static { - /// The message type of this context. Subsystems launched with this context will expect - /// to receive messages of this type. Commonly uses the wrapping enum commonly called - /// `AllMessages`. - type Message: std::fmt::Debug + Send + 'static; - /// And the same for signals. - type Signal: std::fmt::Debug + Send + 'static; - /// The overarching all messages enum. - /// In some cases can be identical to `Self::Message`. - type AllMessages: From + Send + 'static; - /// The sender type as provided by `sender()` and underlying. - type Sender: SubsystemSender + Send + 'static; - /// The error type. - type Error: ::std::error::Error + ::std::convert::From< OverseerError > + Sync + Send + 'static; - - /// Try to asynchronously receive a message. - /// - /// This has to be used with caution, if you loop over this without - /// using `pending!()` macro you will end up with a busy loop! - async fn try_recv(&mut self) -> Result>, ()>; - - /// Receive a message. - async fn recv(&mut self) -> Result, Self::Error>; - - /// Spawn a child task on the executor. - fn spawn( - &mut self, - name: &'static str, - s: ::std::pin::Pin + Send>> - ) -> Result<(), Self::Error>; - - /// Spawn a blocking child task on the executor's dedicated thread pool. - fn spawn_blocking( - &mut self, - name: &'static str, - s: ::std::pin::Pin + Send>>, - ) -> Result<(), Self::Error>; - - /// Send a direct message to some other `Subsystem`, routed based on message type. - async fn send_message(&mut self, msg: X) - where - Self::AllMessages: From, - X: Send, - { - self.sender().send_message(::from(msg)).await - } - - /// Send multiple direct messages to other `Subsystem`s, routed based on message type. - async fn send_messages(&mut self, msgs: T) - where - T: IntoIterator + Send, - T::IntoIter: Send, - Self::AllMessages: From, - X: Send, - { - self.sender().send_messages(msgs.into_iter().map(|x| ::from(x))).await - } - - /// Send a message using the unbounded connection. - fn send_unbounded_message(&mut self, msg: X) - where - Self::AllMessages: From, - X: Send, - { - self.sender().send_unbounded_message(Self::AllMessages::from(msg)) - } - - /// Obtain the sender. - fn sender(&mut self) -> &mut Self::Sender; -} - -/// A trait that describes the [`Subsystem`]s that can run on the [`Overseer`]. -/// -/// It is generic over the message type circulating in the system. -/// The idea that we want some type containing persistent state that -/// can spawn actually running subsystems when asked. -/// -/// [`Overseer`]: struct.Overseer.html -/// [`Subsystem`]: trait.Subsystem.html -pub trait Subsystem -where - Ctx: SubsystemContext, - E: std::error::Error + Send + Sync + 'static + From, -{ - /// Start this `Subsystem` and return `SpawnedSubsystem`. - fn start(self, ctx: Ctx) -> SpawnedSubsystem < E >; -} /// Sender end of a channel to interface with a subsystem. diff --git a/node/overseer/src/lib.rs b/node/overseer/src/lib.rs index d712b8943a67..0edefb9d2ed4 100644 --- a/node/overseer/src/lib.rs +++ b/node/overseer/src/lib.rs @@ -96,7 +96,7 @@ use polkadot_node_subsystem_types::messages::{ }; pub use polkadot_node_subsystem_types::{ OverseerSignal, - errors::{SubsystemResult, SubsystemError,}, + errors::SubsystemError, ActiveLeavesUpdate, ActivatedLeaf, LeafStatus, jaeger, }; @@ -116,24 +116,24 @@ use polkadot_node_metrics::{ }, Metronome, }; -pub use polkadot_overseer_gen::{ + +pub use polkadot_overseer_gen as gen; + +pub use gen::{ TimeoutExt, SpawnNamed, - Subsystem, SubsystemMeterReadouts, SubsystemMeters, SubsystemIncomingMessages, - SubsystemInstance, - SubsystemSender, - SubsystemContext, overlord, MessagePacket, SignalsReceived, - FromOverseer, ToOverseer, MapSubsystem, + OverseerError, }; -pub use polkadot_overseer_gen as gen; + + /// Store 2 days worth of blocks, not accounting for forks, /// in the LRU cache. Assumes a 6-second block time. @@ -476,16 +476,15 @@ where /// # use polkadot_overseer::{ /// # self as overseer, /// # OverseerSignal, - /// # SubsystemSender as _, /// # AllMessages, /// # AllSubsystems, /// # HeadSupportsParachains, /// # Overseer, + /// # SubsystemSender, /// # SubsystemError, + /// # SpawnedSubsystem, /// # gen::{ - /// # SubsystemContext, /// # FromOverseer, - /// # SpawnedSubsystem, /// # }, /// # }; /// # use polkadot_node_subsystem_types::messages::{ @@ -495,19 +494,16 @@ where /// /// struct ValidationSubsystem; /// - /// impl overseer::Subsystem for ValidationSubsystem + /// impl overseer::Subsystem for ValidationSubsystem /// where /// Ctx: overseer::SubsystemContext< /// Message=CandidateValidationMessage, - /// AllMessages=AllMessages, - /// Signal=OverseerSignal, - /// Error=SubsystemError, /// >, /// { /// fn start( /// self, /// mut ctx: Ctx, - /// ) -> SpawnedSubsystem { + /// ) -> SpawnedSubsystem { /// SpawnedSubsystem { /// name: "validation-subsystem", /// future: Box::pin(async move { @@ -558,23 +554,23 @@ where s: S, ) -> SubsystemResult<(Self, Handle)> where - CV: Subsystem, SubsystemError> + Send, - CB: Subsystem, SubsystemError> + Send, - SD: Subsystem, SubsystemError> + Send, - AD: Subsystem, SubsystemError> + Send, - AR: Subsystem, SubsystemError> + Send, - BS: Subsystem, SubsystemError> + Send, - BD: Subsystem, SubsystemError> + Send, - P: Subsystem, SubsystemError> + Send, - RA: Subsystem, SubsystemError> + Send, - AS: Subsystem, SubsystemError> + Send, - NB: Subsystem, SubsystemError> + Send, - CA: Subsystem, SubsystemError> + Send, - CG: Subsystem, SubsystemError> + Send, - CP: Subsystem, SubsystemError> + Send, - ApD: Subsystem, SubsystemError> + Send, - ApV: Subsystem, SubsystemError> + Send, - GS: Subsystem, SubsystemError> + Send, + CV: Subsystem> + Send, + CB: Subsystem> + Send, + SD: Subsystem> + Send, + AD: Subsystem> + Send, + AR: Subsystem> + Send, + BS: Subsystem> + Send, + BD: Subsystem> + Send, + P: Subsystem> + Send, + RA: Subsystem> + Send, + AS: Subsystem> + Send, + NB: Subsystem> + Send, + CA: Subsystem> + Send, + CG: Subsystem> + Send, + CP: Subsystem> + Send, + ApD: Subsystem> + Send, + ApV: Subsystem> + Send, + GS: Subsystem> + Send, S: SpawnNamed, { let metrics: Metrics = ::register(prometheus_registry)?; diff --git a/node/overseer/src/subsystems.rs b/node/overseer/src/subsystems.rs index b75e7e50e6b8..eedf249c51d8 100644 --- a/node/overseer/src/subsystems.rs +++ b/node/overseer/src/subsystems.rs @@ -19,27 +19,29 @@ //! In the future, everything should be set up using the generated //! overeseer builder pattern instead. -use polkadot_node_subsystem_types::errors::SubsystemError; -use polkadot_overseer_gen::{ - MapSubsystem, SubsystemContext, +use crate::{ + SubsystemContext, Subsystem, + OverseerSignal, SpawnedSubsystem, FromOverseer, + gen::{ + MapSubsystem, + }, }; +// TODO remove legacy code use polkadot_overseer_all_subsystems_gen::AllSubsystemsGen; -use crate::OverseerSignal; -use crate::AllMessages; /// A dummy subsystem that implements [`Subsystem`] for all /// types of messages. Used for tests or as a placeholder. #[derive(Clone, Copy, Debug)] pub struct DummySubsystem; -impl Subsystem for DummySubsystem +impl Subsystem for DummySubsystem where - Context: SubsystemContext, + Context: SubsystemContext, { - fn start(self, mut ctx: Context) -> SpawnedSubsystem { + fn start(self, mut ctx: Context) -> SpawnedSubsystem { let future = Box::pin(async move { loop { match ctx.recv().await { diff --git a/node/overseer/src/tests.rs b/node/overseer/src/tests.rs index a4dd0359c70c..43a809c728d8 100644 --- a/node/overseer/src/tests.rs +++ b/node/overseer/src/tests.rs @@ -33,6 +33,7 @@ use polkadot_node_subsystem_types::{ use crate::{ self as overseer, + SpawnedSubsystem, Overseer, HeadSupportsParachains, gen::Delay, @@ -45,9 +46,6 @@ use assert_matches::assert_matches; use super::*; - -type SpawnedSubsystem = crate::gen::SpawnedSubsystem; - struct TestSubsystem1(metered::MeteredSender); impl overseer::Subsystem for TestSubsystem1 diff --git a/node/subsystem-test-helpers/src/lib.rs b/node/subsystem-test-helpers/src/lib.rs index 5ac6c5acdcaf..898d4f000b0b 100644 --- a/node/subsystem-test-helpers/src/lib.rs +++ b/node/subsystem-test-helpers/src/lib.rs @@ -346,10 +346,10 @@ pub fn subsystem_test_harness( /// This subsystem is useful for testing functionality that interacts with the overseer. pub struct ForwardSubsystem(pub mpsc::Sender); -impl overseer::Subsystem for ForwardSubsystem +impl overseer::overseer::Subsystem for ForwardSubsystem where M: std::fmt::Debug + Send + 'static, - Context: SubsystemContext + overseer::SubsystemContext, + Context: overseer::SubsystemContext, { fn start(mut self, mut ctx: Context) -> SpawnedSubsystem { let future = Box::pin(async move { diff --git a/node/subsystem-types/src/errors.rs b/node/subsystem-types/src/errors.rs index fffdc04ac131..af45c49afd87 100644 --- a/node/subsystem-types/src/errors.rs +++ b/node/subsystem-types/src/errors.rs @@ -144,6 +144,3 @@ impl SubsystemError { Self::FromOrigin { origin, source: Box::new(err) } } } - -/// Ease the use of subsystem errors. -pub type SubsystemResult = Result; diff --git a/node/subsystem-util/src/lib.rs b/node/subsystem-util/src/lib.rs index 096957167b45..45922f5d30b9 100644 --- a/node/subsystem-util/src/lib.rs +++ b/node/subsystem-util/src/lib.rs @@ -35,17 +35,15 @@ use polkadot_node_subsystem::{ BoundToRelayParent, }, ActiveLeavesUpdate, OverseerSignal, - SubsystemSender, errors::{ SubsystemError, }, - SubsystemContext, SpawnedSubsystem, - FromOverseer, }; pub use overseer::{ Subsystem, + SubsystemContext, TimeoutExt, gen::OverseerError, gen::Timeout, @@ -765,13 +763,13 @@ impl JobSubsystem { } } -impl Subsystem for JobSubsystem +impl overseer::Subsystem for JobSubsystem where Spawner: SpawnNamed + Send + Clone + Unpin + 'static, - Context: SubsystemContext, + Context: SubsystemContext, Job: 'static + JobTrait + Send, Job::RunArgs: Clone + Sync, - ::ToJob: Sync + From<::Message>, + ::ToJob: Sync + From<::Message>, Job::Metrics: Sync, { fn start(self, ctx: Context) -> SpawnedSubsystem { diff --git a/node/subsystem-util/src/rolling_session_window.rs b/node/subsystem-util/src/rolling_session_window.rs index 944fe0c05489..5b359f1fdcca 100644 --- a/node/subsystem-util/src/rolling_session_window.rs +++ b/node/subsystem-util/src/rolling_session_window.rs @@ -149,7 +149,7 @@ impl RollingSessionWindow { /// some backwards drift in session index is acceptable. pub async fn cache_session_info_for_head( &mut self, - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, block_hash: Hash, block_header: &Header, ) -> Result { @@ -265,7 +265,7 @@ impl RollingSessionWindow { } async fn load_all_sessions( - ctx: &mut (impl SubsystemContext + overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, block_hash: Hash, start: SessionIndex, end_inclusive: SessionIndex, diff --git a/node/subsystem-util/src/runtime/mod.rs b/node/subsystem-util/src/runtime/mod.rs index c691a0010165..f66e0a413931 100644 --- a/node/subsystem-util/src/runtime/mod.rs +++ b/node/subsystem-util/src/runtime/mod.rs @@ -26,7 +26,7 @@ use sp_core::crypto::Public; use sp_keystore::{CryptoStore, SyncCryptoStorePtr}; use polkadot_primitives::v1::{CoreState, EncodeAs, GroupIndex, GroupRotationInfo, Hash, OccupiedCore, SessionIndex, SessionInfo, Signed, SigningContext, UncheckedSigned, ValidatorId, ValidatorIndex}; -use polkadot_node_subsystem::{SubsystemSender, SubsystemContext}; +use polkadot_node_subsystem::overseer::{SubsystemSender, SubsystemContext}; use crate::{ diff --git a/node/subsystem/src/lib.rs b/node/subsystem/src/lib.rs index 98e76f9f9494..e77091b410b3 100644 --- a/node/subsystem/src/lib.rs +++ b/node/subsystem/src/lib.rs @@ -37,54 +37,3 @@ pub mod messages { pub use super::overseer::AllMessages; pub use polkadot_node_subsystem_types::messages::*; } - -/// A `Result` type that wraps [`SubsystemError`]. -/// -/// [`SubsystemError`]: struct.SubsystemError.html -pub type SubsystemResult = Result; - -// Simplify usage without having to do large scale modifications of all -// subsystems at once. - - -/// Specialized message type originating from the overseer. -pub type FromOverseer = polkadot_overseer::gen::FromOverseer; - -/// Specialized subsystem instance type of subsystems consuming a particular message type. -pub type SubsystemInstance = polkadot_overseer::gen::SubsystemInstance; - -/// Sender trait for the `AllMessages` wrapper. -pub trait SubsystemSender: polkadot_overseer::gen::SubsystemSender { -} - -impl SubsystemSender for T where T: polkadot_overseer::gen::SubsystemSender { -} - -/// Spawned subsystem. -pub type SpawnedSubsystem = polkadot_overseer::gen::SpawnedSubsystem; - - -/// Convenience trait specialization. -pub trait SubsystemContext: polkadot_overseer::gen::SubsystemContext< - Signal=OverseerSignal, - AllMessages=messages::AllMessages, - Error=SubsystemError, -> -{ - /// The message type the subsystem consumes. - type Message: std::fmt::Debug + Send + 'static; - /// Sender type to communicate with other subsystems. - type Sender: SubsystemSender + Send + Clone + 'static; -} - -impl SubsystemContext for T -where - T: polkadot_overseer::gen::SubsystemContext< - Signal=OverseerSignal, - AllMessages=messages::AllMessages, - Error=SubsystemError, - >, -{ - type Message = ::Message; - type Sender = ::Sender; -} From e8fd8faf72d954c4ecbb872dbe23efbc8585385a Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Fri, 9 Jul 2021 17:58:56 +0200 Subject: [PATCH 03/11] foo --- node/core/approval-voting/src/lib.rs | 6 +++--- node/overseer/src/tests.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/node/core/approval-voting/src/lib.rs b/node/core/approval-voting/src/lib.rs index 03a2ee93044d..2ec17c13843b 100644 --- a/node/core/approval-voting/src/lib.rs +++ b/node/core/approval-voting/src/lib.rs @@ -673,7 +673,7 @@ async fn run( mut backend: B, ) -> SubsystemResult<()> where - Context: overseer::SubsystemContext, + Context: overseer::SubsystemContext, B: Backend, { let mut state = State { @@ -799,7 +799,7 @@ async fn run( // // returns `true` if any of the actions was a `Conclude` command. async fn handle_actions( - ctx: &mut overseer::SubsystemContext, + ctx: &mut overseer::SubsystemContext, state: &mut State, overlayed_db: &mut OverlayedBackend<'_, impl Backend>, metrics: &Metrics, @@ -1996,7 +1996,7 @@ fn process_wakeup( // spawned. When the background work is no longer needed, the `AbortHandle` should be dropped // to cancel the background work and any requests it has spawned. async fn launch_approval( - ctx: &mut overseer::SubsystemContext, + ctx: &mut overseer::SubsystemContext, metrics: Metrics, session_index: SessionIndex, candidate: CandidateReceipt, diff --git a/node/overseer/src/tests.rs b/node/overseer/src/tests.rs index 43a809c728d8..76e2fdc8182c 100644 --- a/node/overseer/src/tests.rs +++ b/node/overseer/src/tests.rs @@ -48,7 +48,7 @@ use super::*; struct TestSubsystem1(metered::MeteredSender); -impl overseer::Subsystem for TestSubsystem1 +impl overseer::Subsystem for TestSubsystem1 where C: overseer::SubsystemContext, @@ -78,7 +78,7 @@ where struct TestSubsystem2(metered::MeteredSender); -impl overseer::Subsystem for TestSubsystem2 +impl overseer::Subsystem for TestSubsystem2 where C: overseer::SubsystemContext, { @@ -125,7 +125,7 @@ where struct ReturnOnStart; -impl overseer::Subsystem for ReturnOnStart +impl overseer::Subsystem for ReturnOnStart where C: overseer::SubsystemContext, { @@ -302,7 +302,7 @@ fn overseer_ends_on_subsystem_exit() { struct TestSubsystem5(metered::MeteredSender); -impl overseer::Subsystem for TestSubsystem5 +impl overseer::Subsystem for TestSubsystem5 where C: overseer::SubsystemContext, { @@ -334,7 +334,7 @@ where struct TestSubsystem6(metered::MeteredSender); -impl Subsystem for TestSubsystem6 +impl Subsystem for TestSubsystem6 where C: overseer::SubsystemContext, { @@ -683,7 +683,7 @@ impl CounterSubsystem { } } -impl Subsystem for CounterSubsystem +impl Subsystem for CounterSubsystem where C: overseer::SubsystemContext, M: Send, From 86b6e85cbb5005076516b658384685c6493ff409 Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Fri, 9 Jul 2021 18:10:53 +0200 Subject: [PATCH 04/11] fixup --- node/overseer/examples/minimal-example.rs | 2 +- node/overseer/overseer-gen/proc-macro/src/impl_builder.rs | 4 ++-- node/overseer/src/lib.rs | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/node/overseer/examples/minimal-example.rs b/node/overseer/examples/minimal-example.rs index 1345889bee7c..105ca4cdd6b7 100644 --- a/node/overseer/examples/minimal-example.rs +++ b/node/overseer/examples/minimal-example.rs @@ -83,7 +83,7 @@ impl Subsystem1 { }.into(), tx, ); - ctx.send_message(::AllMessages::from(msg)).await; + ctx.send_message(msg).await; } () } diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs index 77b73d06fbb1..7b031e361740 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs @@ -89,7 +89,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream { where S: #support_crate ::SpawnNamed, #( - #builder_generic_ty : Subsystem<#subsyste_ctx_name< #consumes >, #error_ty>, + #builder_generic_ty : Subsystem<#subsyste_ctx_name< #consumes >>, )* }; @@ -327,7 +327,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { TK: TaskKind, Ctx: SubsystemContext, E: std::error::Error + Send + Sync + 'static + From<#support_crate ::OverseerError>, - SubSys: Subsystem, + SubSys: Subsystem, { let SpawnedSubsystem { future, name } = subsystem.start(ctx); diff --git a/node/overseer/src/lib.rs b/node/overseer/src/lib.rs index 0edefb9d2ed4..116b62a40179 100644 --- a/node/overseer/src/lib.rs +++ b/node/overseer/src/lib.rs @@ -125,6 +125,7 @@ pub use gen::{ SubsystemMeterReadouts, SubsystemMeters, SubsystemIncomingMessages, + SubsystemSender, overlord, MessagePacket, SignalsReceived, From a4fa5d0a4fd8d0d631c696292199772828c6702e Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Fri, 9 Jul 2021 18:16:01 +0200 Subject: [PATCH 05/11] whopsy --- node/core/dispute-coordinator/src/lib.rs | 2 +- node/network/approval-distribution/src/lib.rs | 16 +- node/network/bridge/src/lib.rs | 2 +- node/network/dispute-distribution/src/lib.rs | 2 +- .../network/statement-distribution/src/lib.rs | 2 +- node/overseer/examples/minimal-example.rs | 2 +- .../proc-macro/src/impl_subsystem_ctx.rs | 245 ++++++++++++++++++ .../overseer-gen/proc-macro/src/impl_trait.rs | 142 ++++++++++ 8 files changed, 400 insertions(+), 13 deletions(-) create mode 100644 node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs create mode 100644 node/overseer/overseer-gen/proc-macro/src/impl_trait.rs diff --git a/node/core/dispute-coordinator/src/lib.rs b/node/core/dispute-coordinator/src/lib.rs index 7f54abeec3cc..8d84f58d3900 100644 --- a/node/core/dispute-coordinator/src/lib.rs +++ b/node/core/dispute-coordinator/src/lib.rs @@ -227,7 +227,7 @@ where } async fn handle_new_activations( - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, store: &dyn KeyValueDB, state: &mut State, config: &Config, diff --git a/node/network/approval-distribution/src/lib.rs b/node/network/approval-distribution/src/lib.rs index ba895939e3c4..51efcc841c36 100644 --- a/node/network/approval-distribution/src/lib.rs +++ b/node/network/approval-distribution/src/lib.rs @@ -189,7 +189,7 @@ enum PendingMessage { impl State { async fn handle_network_msg( &mut self, - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, metrics: &Metrics, event: NetworkBridgeEvent, ) { @@ -259,7 +259,7 @@ impl State { async fn handle_new_blocks( &mut self, - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, metrics: &Metrics, metas: Vec, ) { @@ -362,7 +362,7 @@ impl State { async fn process_incoming_peer_message( &mut self, - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, metrics: &Metrics, peer_id: PeerId, msg: protocol_v1::ApprovalDistributionMessage, @@ -450,7 +450,7 @@ impl State { async fn handle_peer_view_change( &mut self, - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, metrics: &Metrics, peer_id: PeerId, view: View, @@ -514,7 +514,7 @@ impl State { async fn import_and_circulate_assignment( &mut self, - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, metrics: &Metrics, source: MessageSource, assignment: IndirectAssignmentCert, @@ -751,7 +751,7 @@ impl State { async fn import_and_circulate_approval( &mut self, - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, metrics: &Metrics, source: MessageSource, vote: IndirectSignedApprovalVote, @@ -996,7 +996,7 @@ impl State { } async fn unify_with_peer( - ctx: &mut (overseer::SubsystemContext), gossip_peers: &HashSet, + ctx: &mut impl overseer::SubsystemContext, gossip_peers: &HashSet, metrics: &Metrics, entries: &mut HashMap, peer_id: PeerId, @@ -1156,7 +1156,7 @@ impl State { /// Modify the reputation of a peer based on its behavior. async fn modify_reputation( - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, peer_id: PeerId, rep: Rep, ) { diff --git a/node/network/bridge/src/lib.rs b/node/network/bridge/src/lib.rs index 84f0153d9ecb..9e39c3d2cabb 100644 --- a/node/network/bridge/src/lib.rs +++ b/node/network/bridge/src/lib.rs @@ -308,7 +308,7 @@ impl overseer::Subsystem for NetworkBridge where Net: Network + Sync, AD: validator_discovery::AuthorityDiscovery + Clone, - overseer::SubsystemContext, + Context: overseer::SubsystemContext, { fn start(mut self, ctx: Context) -> SpawnedSubsystem { // The stream of networking events has to be created at initialization, otherwise the diff --git a/node/network/dispute-distribution/src/lib.rs b/node/network/dispute-distribution/src/lib.rs index dbdffdcf8582..f2c2f4211efa 100644 --- a/node/network/dispute-distribution/src/lib.rs +++ b/node/network/dispute-distribution/src/lib.rs @@ -246,7 +246,7 @@ enum MuxedMessage { impl MuxedMessage { async fn receive( - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, from_sender: &mut mpsc::Receiver, ) -> Self { // We are only fusing here to make `select` happy, in reality we will quit if the stream diff --git a/node/network/statement-distribution/src/lib.rs b/node/network/statement-distribution/src/lib.rs index d6cfbf5d04e8..a33e2e67d09a 100644 --- a/node/network/statement-distribution/src/lib.rs +++ b/node/network/statement-distribution/src/lib.rs @@ -590,7 +590,7 @@ enum MuxedMessage { impl MuxedMessage { async fn receive( - ctx: &mut (overseer::SubsystemContext), + ctx: &mut impl overseer::SubsystemContext, from_requester: &mut mpsc::Receiver, from_responder: &mut mpsc::Receiver, ) -> MuxedMessage { diff --git a/node/overseer/examples/minimal-example.rs b/node/overseer/examples/minimal-example.rs index 105ca4cdd6b7..c199318cdbb3 100644 --- a/node/overseer/examples/minimal-example.rs +++ b/node/overseer/examples/minimal-example.rs @@ -142,7 +142,7 @@ impl Subsystem2 { } } -impl overseer::overseer::Subsystem for Subsystem2 +impl overseer::Subsystem for Subsystem2 where Context: overseer::SubsystemContext, { diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs b/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs new file mode 100644 index 000000000000..a31589886963 --- /dev/null +++ b/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs @@ -0,0 +1,245 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use quote::quote; +use syn::Ident; + +use super::*; + +/// Implement a builder pattern for the `Overseer`-type, +/// which acts as the gateway to constructing the overseer. +pub(crate) fn impl_trait(info: &OverseerInfo) -> proc_macro2::TokenStream { + let overseer_name = info.overseer_name.clone(); + let subsystem_sender_name = Ident::new(&(overseer_name.to_string() + "SubsystemSender"), overseer_name.span()); + let subsystem_ctx_name = Ident::new(&(overseer_name.to_string() + "SubsystemContext"), overseer_name.span()); + let consumes = &info.consumes(); + let signal = &info.extern_signal_ty; + let wrapper_message = &info.message_wrapper; + let error = &info.extern_error_ty; + let support_crate = info.support_crate_name(); + + let ts = quote! { + /// Connector to send messages towards all subsystems, + /// while tracking the which signals where already received. + #[derive(Debug, Clone)] + pub struct #subsystem_sender_name { + /// Collection of channels to all subsystems. + channels: ChannelsOut, + /// Systemwide tick for which signals were received by all subsystems. + signals_received: SignalsReceived, + } + + /// impl for wrapping message type... + #[#support_crate ::async_trait] + impl #support_crate ::SubsystemSender< #wrapper_message > for #subsystem_sender_name { + async fn send_message(&mut self, msg: #wrapper_message) { + self.channels.send_and_log_error(self.signals_received.load(), msg).await; + } + + async fn send_messages(&mut self, msgs: T) + where + T: IntoIterator + Send, + T::IntoIter: Send, + { + // This can definitely be optimized if necessary. + for msg in msgs { + self.send_message(msg).await; + } + } + + fn send_unbounded_message(&mut self, msg: #wrapper_message) { + self.channels.send_unbounded_and_log_error(self.signals_received.load(), msg); + } + } + + // ... but also implement for all individual messages to avoid + // the necessity for manual wrapping, and do the conversion + // based on the generated `From::from` impl for the individual variants. + #( + #[#support_crate ::async_trait] + impl #support_crate ::SubsystemSender< #consumes > for #subsystem_sender_name { + async fn send_message(&mut self, msg: #consumes) { + self.channels.send_and_log_error(self.signals_received.load(), #wrapper_message ::from ( msg )).await; + } + + async fn send_messages(&mut self, msgs: T) + where + T: IntoIterator + Send, + T::IntoIter: Send, + { + // This can definitely be optimized if necessary. + for msg in msgs { + self.send_message(msg).await; + } + } + + fn send_unbounded_message(&mut self, msg: #consumes) { + self.channels.send_unbounded_and_log_error(self.signals_received.load(), #wrapper_message ::from ( msg )); + } + } + )* + + /// A context type that is given to the [`Subsystem`] upon spawning. + /// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s + /// or to spawn it's [`SubsystemJob`]s. + /// + /// [`Overseer`]: struct.Overseer.html + /// [`Subsystem`]: trait.Subsystem.html + /// [`SubsystemJob`]: trait.SubsystemJob.html + #[derive(Debug)] + #[allow(missing_docs)] + pub struct #subsystem_ctx_name{ + signals: #support_crate ::metered::MeteredReceiver< #signal >, + messages: SubsystemIncomingMessages, + to_subsystems: #subsystem_sender_name, + to_overseer: #support_crate ::metered::UnboundedMeteredSender< + #support_crate ::ToOverseer + >, + signals_received: SignalsReceived, + pending_incoming: Option<(usize, M)>, + } + + impl #subsystem_ctx_name { + /// Create a new context. + fn new( + signals: #support_crate ::metered::MeteredReceiver< #signal >, + messages: SubsystemIncomingMessages, + to_subsystems: ChannelsOut, + to_overseer: #support_crate ::metered::UnboundedMeteredSender, + ) -> Self { + let signals_received = SignalsReceived::default(); + #subsystem_ctx_name { + signals, + messages, + to_subsystems: #subsystem_sender_name { + channels: to_subsystems, + signals_received: signals_received.clone(), + }, + to_overseer, + signals_received, + pending_incoming: None, + } + } + } + + #[#support_crate ::async_trait] + impl SubsystemContext for #subsystem_ctx_name + where + #subsystem_sender_name: #support_crate:: SubsystemSender< #wrapper_message >, + #wrapper_message: From, + { + type Message = M; + type Sender = #subsystem_sender_name; + + async fn try_recv(&mut self) -> ::std::result::Result>, ()> { + match #support_crate ::poll!(self.recv()) { + #support_crate ::Poll::Ready(msg) => Ok(Some(msg.map_err(|_| ())?)), + #support_crate ::Poll::Pending => Ok(None), + } + } + + async fn recv(&mut self) -> ::std::result::Result<#support_crate ::FromOverseer, #error> { + loop { + // If we have a message pending an overseer signal, we only poll for signals + // in the meantime. + if let Some((needs_signals_received, msg)) = self.pending_incoming.take() { + if needs_signals_received <= self.signals_received.load() { + return Ok(#support_crate ::FromOverseer::Communication { msg }); + } else { + self.pending_incoming = Some((needs_signals_received, msg)); + + // wait for next signal. + let signal = self.signals.next().await + .ok_or(#support_crate ::OverseerError::Context( + "Signal channel is terminated and empty." + .to_owned() + ))?; + + self.signals_received.inc(); + return Ok(#support_crate ::FromOverseer::Signal(signal)) + } + } + + let mut await_message = self.messages.next().fuse(); + let mut await_signal = self.signals.next().fuse(); + let signals_received = self.signals_received.load(); + let pending_incoming = &mut self.pending_incoming; + + // Otherwise, wait for the next signal or incoming message. + let from_overseer = #support_crate ::futures::select_biased! { + signal = await_signal => { + let signal = signal + .ok_or(#support_crate ::OverseerError::Context( + "Signal channel is terminated and empty." + .to_owned() + ))?; + + #support_crate ::FromOverseer::Signal(signal) + } + msg = await_message => { + let packet = msg + .ok_or(#support_crate ::OverseerError::Context( + "Message channel is terminated and empty." + .to_owned() + ))?; + + if packet.signals_received > signals_received { + // wait until we've received enough signals to return this message. + *pending_incoming = Some((packet.signals_received, packet.message)); + continue; + } else { + // we know enough to return this message. + #support_crate ::FromOverseer::Communication { msg: packet.message} + } + } + }; + + if let #support_crate ::FromOverseer::Signal(_) = from_overseer { + self.signals_received.inc(); + } + + return Ok(from_overseer); + } + } + + fn sender(&mut self) -> &mut Self::Sender { + &mut self.to_subsystems + } + + fn spawn(&mut self, name: &'static str, s: Pin + Send>>) + -> ::std::result::Result<(), #error> + { + self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnJob { + name, + s, + }).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?; + Ok(()) + } + + fn spawn_blocking(&mut self, name: &'static str, s: Pin + Send>>) + -> ::std::result::Result<(), #error> + { + self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnBlockingJob { + name, + s, + }).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?; + Ok(()) + } + } + }; + + ts +} diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_trait.rs b/node/overseer/overseer-gen/proc-macro/src/impl_trait.rs new file mode 100644 index 000000000000..e12c84ef62ea --- /dev/null +++ b/node/overseer/overseer-gen/proc-macro/src/impl_trait.rs @@ -0,0 +1,142 @@ + +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use quote::quote; +use syn::Ident; + +use super::*; + +/// Implement a builder pattern for the `Overseer`-type, +/// which acts as the gateway to constructing the overseer. +pub(crate) fn impl_subsystem_ctx(info: &OverseerInfo) -> proc_macro2::TokenStream { + let signal = &info.extern_signal_ty; + let message_wrapper = &info.message_wrapper; + let error = &info.extern_error_ty; + let support_crate = info.support_crate_name(); + + let subsystem_context_trait = Ident::new("SubsystemContext", Span::call_site()); + + let ts = quote!{ + + + /// A `Result` type that wraps [`SubsystemError`]. + /// + /// [`SubsystemError`]: struct.SubsystemError.html + pub type SubsystemResult = ::std::result::Result; + + /// Specialized message type originating from the overseer. + pub type FromOverseer = #support_crate ::FromOverseer; + + /// Specialized subsystem instance type of subsystems consuming a particular message type. + pub type SubsystemInstance = #support_crate ::SubsystemInstance; + + /// Spawned subsystem. + pub type SpawnedSubsystem = #support_crate ::SpawnedSubsystem< #error >; + + /// A context type that is given to the [`Subsystem`] upon spawning. + /// It can be used by [`Subsystem`] to obtain a sender to communicate + /// with other [`Subsystem`]s or spawn jobs via the overseer instance. + #[ #support_crate ::async_trait] + pub trait #subsystem_context_trait: Send + 'static { + /// The message type of this context. Subsystems launched with this context will expect + /// to receive messages of this type. Commonly uses the wrapping enum commonly called + /// `AllMessages`. + type Message: std::fmt::Debug + Send + 'static; + /// The sender type as provided by `sender()` and underlying. + type Sender: #support_crate ::SubsystemSender<#message_wrapper>; + + /// Try to asynchronously receive a message. + /// + /// This has to be used with caution, if you loop over this without + /// using `pending!()` macro you will end up with a busy loop! + async fn try_recv(&mut self) -> Result>, ()>; + + /// Receive a message. + async fn recv(&mut self) -> Result<#support_crate ::FromOverseer, #error>; + + /// Spawn a child task on the executor. + fn spawn( + &mut self, + name: &'static str, + s: ::std::pin::Pin + Send>> + ) -> Result<(), #error>; + + /// Spawn a blocking child task on the executor's dedicated thread pool. + fn spawn_blocking( + &mut self, + name: &'static str, + s: ::std::pin::Pin + Send>>, + ) -> Result<(), #error>; + + /// Send a direct message to some other `Subsystem`, routed based on message type. + async fn send_message(&mut self, msg: X) + where + #message_wrapper: From, + X: Send, + { + self.sender().send_message(<#message_wrapper as ::std::convert::From>::from(msg)).await + } + + /// Send multiple direct messages to other `Subsystem`s, routed based on message type. + async fn send_messages(&mut self, msgs: T) + where + T: IntoIterator + Send, + T::IntoIter: Send, + #message_wrapper: From, + X: Send, + { + self.sender() + .send_messages( + msgs.into_iter() + .map(<#message_wrapper as ::std::convert::From>::from) + ).await + } + + /// Send a message using the unbounded connection. + fn send_unbounded_message(&mut self, msg: X) + where + #message_wrapper: From, + X: Send, + { + self.sender().send_unbounded_message(<#message_wrapper as ::std::convert::From>::from(msg)) + } + + /// Obtain the sender. + fn sender(&mut self) -> &mut Self::Sender; + } + + + /// A trait that describes the [`Subsystem`]s that can run on the [`Overseer`]. + /// + /// It is generic over the message type circulating in the system. + /// The idea that we want some type containing persistent state that + /// can spawn actually running subsystems when asked. + /// + /// [`Overseer`]: struct.Overseer.html + /// [`Subsystem`]: trait.Subsystem.html + pub trait Subsystem + where + Ctx: SubsystemContext, + { + /// Start this `Subsystem` and return `SpawnedSubsystem`. + fn start(self, ctx: Ctx) -> #support_crate:: SpawnedSubsystem < #error >; + } + }; + + + ts +} From 1038730270d7a86990f4d171928b6db46e760ab0 Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Fri, 9 Jul 2021 18:48:01 +0200 Subject: [PATCH 06/11] not quite --- node/core/approval-voting/src/lib.rs | 4 +-- node/overseer/overseer-gen/examples/dummy.rs | 10 +++--- .../proc-macro/src/impl_builder.rs | 2 +- .../overseer-gen/proc-macro/src/lib.rs | 17 ++++------ .../overseer-gen/proc-macro/src/tests.rs | 34 ------------------- node/overseer/overseer-gen/src/lib.rs | 34 +++++++++++++++++++ 6 files changed, 49 insertions(+), 52 deletions(-) diff --git a/node/core/approval-voting/src/lib.rs b/node/core/approval-voting/src/lib.rs index 2ec17c13843b..3649bed349c5 100644 --- a/node/core/approval-voting/src/lib.rs +++ b/node/core/approval-voting/src/lib.rs @@ -29,8 +29,8 @@ use polkadot_node_subsystem::{ AvailabilityRecoveryMessage, ChainSelectionMessage, }, errors::RecoveryError, - overseer::{self, SubsystemSender as _}, SubsystemError, SubsystemResult, SpawnedSubsystem, - FromOverseer, OverseerSignal, SubsystemSender, + overseer::{self, SubsystemSender}, SubsystemError, SubsystemResult, SpawnedSubsystem, + FromOverseer, OverseerSignal, }; use polkadot_node_subsystem_util::{ TimeoutExt, diff --git a/node/overseer/overseer-gen/examples/dummy.rs b/node/overseer/overseer-gen/examples/dummy.rs index e09ed3701a5c..492a3c453c81 100644 --- a/node/overseer/overseer-gen/examples/dummy.rs +++ b/node/overseer/overseer-gen/examples/dummy.rs @@ -1,6 +1,6 @@ //! A dummy to be used with cargo expand -use polkadot_overseer_gen::*; +use polkadot_overseer_gen::prelude::*; use polkadot_node_network_protocol::WrongVariant; @@ -8,8 +8,8 @@ use polkadot_node_network_protocol::WrongVariant; #[derive(Default)] pub struct AwesomeSubSys; -impl Subsystem, Yikes> for AwesomeSubSys { - fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem < Yikes > { +impl Subsystem> for AwesomeSubSys { + fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem { unimplemented!("starting yay!") } } @@ -17,8 +17,8 @@ impl Subsystem, Yikes> for AwesomeSubSys { #[derive(Default)] pub struct GoblinTower; -impl Subsystem, Yikes> for GoblinTower { - fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem < Yikes > { +impl Subsystem> for GoblinTower { + fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem { unimplemented!("welcum") } } diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs index 7b031e361740..791a6fb67ac5 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs @@ -351,7 +351,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { }) )); - let instance = Some(SubsystemInstance:: < M > { + let instance = Some(#support_crate ::SubsystemInstance:: < M, #signal > { meters: #support_crate ::SubsystemMeters { unbounded: unbounded_meter, bounded: message_tx.meter().clone(), diff --git a/node/overseer/overseer-gen/proc-macro/src/lib.rs b/node/overseer/overseer-gen/proc-macro/src/lib.rs index 6b16b8312441..5860cfd860e9 100644 --- a/node/overseer/overseer-gen/proc-macro/src/lib.rs +++ b/node/overseer/overseer-gen/proc-macro/src/lib.rs @@ -56,17 +56,14 @@ pub(crate) fn impl_overseer_gen(attr: TokenStream, orig: TokenStream) -> Result< let of: OverseerGuts = parse2(orig)?; - let support_crate_name = if cfg!(test) { - quote!{crate} - } else { - use proc_macro_crate::{crate_name, FoundCrate}; - let crate_name = crate_name("polkadot-overseer-gen") - .expect("Support crate polkadot-overseer-gen is present in `Cargo.toml`. qed"); - match crate_name { - FoundCrate::Itself => quote!{crate}, - FoundCrate::Name(name) => Ident::new(&name, Span::call_site()).to_token_stream(), - } + use proc_macro_crate::{crate_name, FoundCrate}; + let crate_name = crate_name("polkadot-overseer-gen") + .expect("Support crate polkadot-overseer-gen is present in `Cargo.toml`. qed"); + let support_crate_name = match crate_name { + FoundCrate::Itself => quote!{crate}, + FoundCrate::Name(name) => Ident::new(&name, Span::call_site()).to_token_stream(), }; + let info = OverseerInfo { support_crate_name, subsystems: of.subsystems, diff --git a/node/overseer/overseer-gen/proc-macro/src/tests.rs b/node/overseer/overseer-gen/proc-macro/src/tests.rs index 40df210fb6f0..12f958992f61 100644 --- a/node/overseer/overseer-gen/proc-macro/src/tests.rs +++ b/node/overseer/overseer-gen/proc-macro/src/tests.rs @@ -19,40 +19,6 @@ use assert_matches::assert_matches; use quote::quote; use syn::parse_quote; -#[test] -fn print() { - let attr = quote! { - gen=AllMessage, - event=::some::why::ExternEvent, - signal=SigSigSig, - signal_capacity=111, - message_capacity=222, - error=OverseerError, - }; - - let item = quote! { - pub struct Ooooh where X: Secrit { - #[subsystem(no_dispatch, Foo)] - sub0: FooSubsystem, - - #[subsystem(blocking, Bar)] - yyy: BaersBuyBilliardBalls, - - #[subsystem(no_dispatch, blocking, Twain)] - fff: Beeeeep, - - #[subsystem(Rope)] - mc: MountainCave, - - metrics: Metrics, - } - }; - - let output = impl_overseer_gen(attr, item).expect("Simple example always works. qed"); - println!("//generated:"); - println!("{}", output); -} - #[test] fn struct_parse_full() { let item: OverseerGuts = parse_quote! { diff --git a/node/overseer/overseer-gen/src/lib.rs b/node/overseer/overseer-gen/src/lib.rs index 97133d0b45ba..4da1dea4f94d 100644 --- a/node/overseer/overseer-gen/src/lib.rs +++ b/node/overseer/overseer-gen/src/lib.rs @@ -103,6 +103,40 @@ pub use polkadot_node_network_protocol::WrongVariant; use std::fmt; +/// Import just the right amount of types. +pub mod prelude { + pub use crate::{ + overlord, + async_trait, + ToOverseer, + Timeout, + TimeoutExt, + MapSubsystem, + MessagePacket, + SubsystemIncomingMessages, + OverseerError, + SubsystemMeters, + SubsystemMeterReadouts, + SpawnNamed, + Future, + Pin, + Duration, + make_packet, + Delay, + BoxFuture, + select, + StreamExt, + poll, + Poll, + stream, + SignalsReceived, + FutureExt, + metered, + futures, + oneshot, + FuturesUnordered, + }; +} #[cfg(test)] mod tests; From f73989ce19917fba3aa8199824e5636bee3f4f0b Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Fri, 9 Jul 2021 19:22:23 +0200 Subject: [PATCH 07/11] minor --- .../overseer-gen/proc-macro/src/impl_trait.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_trait.rs b/node/overseer/overseer-gen/proc-macro/src/impl_trait.rs index e12c84ef62ea..2cd61bf38cda 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_trait.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_trait.rs @@ -39,10 +39,10 @@ pub(crate) fn impl_subsystem_ctx(info: &OverseerInfo) -> proc_macro2::TokenStrea pub type SubsystemResult = ::std::result::Result; /// Specialized message type originating from the overseer. - pub type FromOverseer = #support_crate ::FromOverseer; + pub type FromOverseer = #support_crate ::FromOverseer; /// Specialized subsystem instance type of subsystems consuming a particular message type. - pub type SubsystemInstance = #support_crate ::SubsystemInstance; + pub type SubsystemInstance = #support_crate ::SubsystemInstance; /// Spawned subsystem. pub type SpawnedSubsystem = #support_crate ::SpawnedSubsystem< #error >; @@ -57,30 +57,30 @@ pub(crate) fn impl_subsystem_ctx(info: &OverseerInfo) -> proc_macro2::TokenStrea /// `AllMessages`. type Message: std::fmt::Debug + Send + 'static; /// The sender type as provided by `sender()` and underlying. - type Sender: #support_crate ::SubsystemSender<#message_wrapper>; + type Sender: #support_crate ::SubsystemSender< #message_wrapper >; /// Try to asynchronously receive a message. /// /// This has to be used with caution, if you loop over this without /// using `pending!()` macro you will end up with a busy loop! - async fn try_recv(&mut self) -> Result>, ()>; + async fn try_recv(&mut self) -> ::std::result::Result>, ()>; /// Receive a message. - async fn recv(&mut self) -> Result<#support_crate ::FromOverseer, #error>; + async fn recv(&mut self) -> ::std::result::Result<#support_crate ::FromOverseer, #error>; /// Spawn a child task on the executor. fn spawn( &mut self, name: &'static str, s: ::std::pin::Pin + Send>> - ) -> Result<(), #error>; + ) -> ::std::result::Result<(), #error>; /// Spawn a blocking child task on the executor's dedicated thread pool. fn spawn_blocking( &mut self, name: &'static str, s: ::std::pin::Pin + Send>>, - ) -> Result<(), #error>; + ) -> ::std::result::Result<(), #error>; /// Send a direct message to some other `Subsystem`, routed based on message type. async fn send_message(&mut self, msg: X) From c734f08f4a473a65abc297bdfc7992841bfb939e Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Thu, 15 Jul 2021 14:29:46 +0200 Subject: [PATCH 08/11] foo --- node/overseer/overseer-gen/examples/dummy.rs | 2 +- .../proc-macro/src/impl_builder.rs | 8 +-- .../proc-macro/src/impl_overseer.rs | 4 +- node/overseer/overseer-gen/src/lib.rs | 60 ++++++++----------- node/overseer/src/subsystems.rs | 12 +--- node/subsystem/src/lib.rs | 8 ++- 6 files changed, 41 insertions(+), 53 deletions(-) diff --git a/node/overseer/overseer-gen/examples/dummy.rs b/node/overseer/overseer-gen/examples/dummy.rs index 492a3c453c81..d2a97943914a 100644 --- a/node/overseer/overseer-gen/examples/dummy.rs +++ b/node/overseer/overseer-gen/examples/dummy.rs @@ -1,6 +1,6 @@ //! A dummy to be used with cargo expand -use polkadot_overseer_gen::prelude::*; +pub use polkadot_overseer_gen::prelude::*; use polkadot_node_network_protocol::WrongVariant; diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs index 791a6fb67ac5..89ff7ecf04d9 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs @@ -229,7 +229,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream { to_overseer_tx.clone(), ); - let #subsystem_name: OverseenSubsystem< #consumes > = + let #subsystem_name: crate::OverseenSubsystem< #consumes > = spawn::<_,_, #blocking, _, _, _>( &mut spawner, #channel_name_tx, @@ -320,7 +320,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { ctx: Ctx, subsystem: SubSys, futures: &mut #support_crate ::FuturesUnordered >>, - ) -> ::std::result::Result, #error_ty > + ) -> ::std::result::Result, #error_ty > where S: #support_crate ::SpawnNamed, M: std::fmt::Debug + Send + 'static, @@ -351,7 +351,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { }) )); - let instance = Some(#support_crate ::SubsystemInstance:: < M, #signal > { + let instance = Some(#support_crate ::SubsystemInstance { meters: #support_crate ::SubsystemMeters { unbounded: unbounded_meter, bounded: message_tx.meter().clone(), @@ -363,7 +363,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { name, }); - Ok(OverseenSubsystem { + Ok(crate::OverseenSubsystem { instance, }) } diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_overseer.rs b/node/overseer/overseer-gen/proc-macro/src/impl_overseer.rs index 3c578fdf4a51..ba9b94ac7afc 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_overseer.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_overseer.rs @@ -72,7 +72,7 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr #( /// A subsystem instance. - #subsystem_name: OverseenSubsystem< #consumes >, + #subsystem_name: crate::OverseenSubsystem< #consumes >, )* #( @@ -143,7 +143,7 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr match message { #( #message_wrapper :: #consumes_variant ( inner ) => - OverseenSubsystem::< #consumes >::send_message2(&mut self. #subsystem_name, inner, origin ).await?, + crate::OverseenSubsystem::< #consumes >::send_message2(&mut self. #subsystem_name, inner, origin ).await?, )* // subsystems that are still work in progress #( diff --git a/node/overseer/overseer-gen/src/lib.rs b/node/overseer/overseer-gen/src/lib.rs index 4da1dea4f94d..90ac08455521 100644 --- a/node/overseer/overseer-gen/src/lib.rs +++ b/node/overseer/overseer-gen/src/lib.rs @@ -60,6 +60,10 @@ #![deny(missing_docs)] #![deny(unused_crate_dependencies)] + +/// Prelude. +pub mod prelude { + pub use polkadot_overseer_gen_proc_macro::overlord; #[doc(hidden)] @@ -94,50 +98,36 @@ pub use async_trait::async_trait; #[doc(hidden)] pub use std::time::Duration; -use std::sync::{Arc, atomic::{self, AtomicUsize}}; #[doc(hidden)] pub use futures_timer::Delay; pub use polkadot_node_network_protocol::WrongVariant; -use std::fmt; -/// Import just the right amount of types. -pub mod prelude { - pub use crate::{ - overlord, - async_trait, - ToOverseer, - Timeout, - TimeoutExt, - MapSubsystem, - MessagePacket, - SubsystemIncomingMessages, - OverseerError, - SubsystemMeters, - SubsystemMeterReadouts, - SpawnNamed, - Future, - Pin, - Duration, - make_packet, - Delay, - BoxFuture, - select, - StreamExt, - poll, - Poll, - stream, - SignalsReceived, - FutureExt, - metered, - futures, - oneshot, - FuturesUnordered, - }; +pub use crate::{ + ToOverseer, + Timeout, + TimeoutExt, + MapSubsystem, + MessagePacket, + SubsystemIncomingMessages, + OverseerError, + SubsystemMeters, + SubsystemMeterReadouts, + SignalsReceived, + SubsystemSender, + SubsystemInstance, + make_packet, +}; } + +use std::fmt; +use std::sync::{Arc, atomic::{self, AtomicUsize}}; + +pub use prelude::*; + #[cfg(test)] mod tests; diff --git a/node/overseer/src/subsystems.rs b/node/overseer/src/subsystems.rs index eedf249c51d8..98f4ccbfcb21 100644 --- a/node/overseer/src/subsystems.rs +++ b/node/overseer/src/subsystems.rs @@ -19,16 +19,8 @@ //! In the future, everything should be set up using the generated //! overeseer builder pattern instead. -use crate::{ - SubsystemContext, - Subsystem, - OverseerSignal, - SpawnedSubsystem, - FromOverseer, - gen::{ - MapSubsystem, - }, -}; +use super::*; + // TODO remove legacy code use polkadot_overseer_all_subsystems_gen::AllSubsystemsGen; diff --git a/node/subsystem/src/lib.rs b/node/subsystem/src/lib.rs index e77091b410b3..c9138fafe276 100644 --- a/node/subsystem/src/lib.rs +++ b/node/subsystem/src/lib.rs @@ -24,7 +24,13 @@ pub use polkadot_node_jaeger as jaeger; pub use jaeger::*; -pub use polkadot_overseer::{OverseerSignal, ActiveLeavesUpdate, self as overseer}; +pub use polkadot_overseer::{ + OverseerSignal, + ActiveLeavesUpdate, + self as overseer, + // FromOverseer, + // SubsystemInstance, +}; pub use polkadot_node_subsystem_types::{ errors::{self, *}, From 0318d6e8407ff06de0e77f2b9b8597401282d75e Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Thu, 15 Jul 2021 15:43:06 +0200 Subject: [PATCH 09/11] more support crate prefixes --- .../overseer-gen/proc-macro/src/impl_builder.rs | 14 +++++++------- .../overseer-gen/proc-macro/src/impl_overseer.rs | 6 +++--- .../proc-macro/src/impl_subsystem_ctx.rs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs index 89ff7ecf04d9..6db5341edab8 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs @@ -89,7 +89,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream { where S: #support_crate ::SpawnNamed, #( - #builder_generic_ty : Subsystem<#subsyste_ctx_name< #consumes >>, + #builder_generic_ty : Subsystem<#subsyste_ctx_name< #consumes >, #error_ty>, )* }; @@ -229,7 +229,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream { to_overseer_tx.clone(), ); - let #subsystem_name: crate::OverseenSubsystem< #consumes > = + let #subsystem_name: OverseenSubsystem< #consumes > = spawn::<_,_, #blocking, _, _, _>( &mut spawner, #channel_name_tx, @@ -320,16 +320,16 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { ctx: Ctx, subsystem: SubSys, futures: &mut #support_crate ::FuturesUnordered >>, - ) -> ::std::result::Result, #error_ty > + ) -> ::std::result::Result, #error_ty > where S: #support_crate ::SpawnNamed, M: std::fmt::Debug + Send + 'static, TK: TaskKind, - Ctx: SubsystemContext, + Ctx: #support_crate ::SubsystemContext, E: std::error::Error + Send + Sync + 'static + From<#support_crate ::OverseerError>, - SubSys: Subsystem, + SubSys: #support_crate ::Subsystem, { - let SpawnedSubsystem { future, name } = subsystem.start(ctx); + let #support_crate ::SpawnedSubsystem:: { future, name } = s.start(ctx); let (tx, rx) = #support_crate ::oneshot::channel(); @@ -363,7 +363,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { name, }); - Ok(crate::OverseenSubsystem { + Ok(OverseenSubsystem { instance, }) } diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_overseer.rs b/node/overseer/overseer-gen/proc-macro/src/impl_overseer.rs index ba9b94ac7afc..1769de00ff8d 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_overseer.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_overseer.rs @@ -72,7 +72,7 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr #( /// A subsystem instance. - #subsystem_name: crate::OverseenSubsystem< #consumes >, + #subsystem_name: OverseenSubsystem< #consumes >, )* #( @@ -90,7 +90,7 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr /// Gather running subsystems' outbound streams into one. to_overseer_rx: #support_crate ::stream::Fuse< - #support_crate ::metered::UnboundedMeteredReceiver< ToOverseer > + #support_crate ::metered::UnboundedMeteredReceiver< #support_crate ::ToOverseer > >, /// Events that are sent to the overseer from the outside world. @@ -143,7 +143,7 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr match message { #( #message_wrapper :: #consumes_variant ( inner ) => - crate::OverseenSubsystem::< #consumes >::send_message2(&mut self. #subsystem_name, inner, origin ).await?, + OverseenSubsystem::< #consumes >::send_message2(&mut self. #subsystem_name, inner, origin ).await?, )* // subsystems that are still work in progress #( diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs b/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs index a31589886963..4e3b22ac029f 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs @@ -118,7 +118,7 @@ pub(crate) fn impl_trait(info: &OverseerInfo) -> proc_macro2::TokenStream { signals: #support_crate ::metered::MeteredReceiver< #signal >, messages: SubsystemIncomingMessages, to_subsystems: ChannelsOut, - to_overseer: #support_crate ::metered::UnboundedMeteredSender, + to_overseer: #support_crate ::metered::UnboundedMeteredSender<#support_crate:: ToOverseer>, ) -> Self { let signals_received = SignalsReceived::default(); #subsystem_ctx_name { @@ -136,7 +136,7 @@ pub(crate) fn impl_trait(info: &OverseerInfo) -> proc_macro2::TokenStream { } #[#support_crate ::async_trait] - impl SubsystemContext for #subsystem_ctx_name + impl #support_crate ::SubsystemContext for #subsystem_ctx_name where #subsystem_sender_name: #support_crate:: SubsystemSender< #wrapper_message >, #wrapper_message: From, From e4081cfef03713ef381659e3311949d1fe12bb43 Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Thu, 15 Jul 2021 15:43:28 +0200 Subject: [PATCH 10/11] attempt to move things into one spot --- Cargo.lock | 3 + node/overseer/Cargo.toml | 3 + node/overseer/examples/minimal-example.rs | 16 +- node/overseer/overseer-gen/examples/dummy.rs | 10 +- .../proc-macro/src/impl_builder.rs | 2 +- .../overseer-gen/proc-macro/src/impl_misc.rs | 248 ++++++++++++++++++ .../proc-macro/src/impl_subsystem_ctx.rs | 2 +- .../overseer-gen/proc-macro/src/lib.rs | 30 +-- .../overseer-gen/proc-macro/src/tests.rs | 34 +++ node/overseer/overseer-gen/src/lib.rs | 120 +++++++-- node/overseer/src/convenience.rs | 105 ++++++++ node/overseer/src/lib.rs | 66 ++--- node/overseer/src/subsystems.rs | 11 +- node/overseer/src/tests.rs | 16 +- node/subsystem/src/lib.rs | 11 +- 15 files changed, 576 insertions(+), 101 deletions(-) create mode 100644 node/overseer/overseer-gen/proc-macro/src/impl_misc.rs create mode 100644 node/overseer/src/convenience.rs diff --git a/Cargo.lock b/Cargo.lock index 57d7dbfcb83c..602d122c05da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6520,13 +6520,16 @@ name = "polkadot-overseer" version = "0.1.0" dependencies = [ "assert_matches", + "async-trait", "femme", "futures 0.3.15", + "futures-timer 3.0.2", "kv-log-macro", "lru", "metered-channel", "polkadot-node-metrics", "polkadot-node-network-protocol", + "polkadot-node-primitives", "polkadot-node-subsystem-types", "polkadot-overseer-all-subsystems-gen", "polkadot-overseer-gen", diff --git a/node/overseer/Cargo.toml b/node/overseer/Cargo.toml index fe2b6c95ad57..6f436c0d33fb 100644 --- a/node/overseer/Cargo.toml +++ b/node/overseer/Cargo.toml @@ -5,10 +5,13 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] +async-trait = "0.1.42" client = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "master" } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = "0.3.15" +futures-timer = "3.0.2" polkadot-node-network-protocol = { path = "../network/protocol" } +polkadot-node-primitives = { path = "../primitives" } polkadot-node-subsystem-types = { path = "../subsystem-types" } polkadot-node-metrics = { path = "../metrics" } polkadot-primitives = { path = "../../primitives" } diff --git a/node/overseer/examples/minimal-example.rs b/node/overseer/examples/minimal-example.rs index c199318cdbb3..71a703f99336 100644 --- a/node/overseer/examples/minimal-example.rs +++ b/node/overseer/examples/minimal-example.rs @@ -36,8 +36,10 @@ use polkadot_overseer::{ Overseer, OverseerSignal, SubsystemError, - FromOverseer, - SpawnedSubsystem, + gen::{ + FromOverseer, + SpawnedSubsystem, + }, }; use polkadot_node_subsystem_types::messages::{ CandidateValidationMessage, CandidateBackingMessage, @@ -56,7 +58,7 @@ struct Subsystem1; impl Subsystem1 { async fn run(mut ctx: Ctx) -> () where - Ctx: overseer::SubsystemContext, + Ctx: overseer::SubsystemContext, { 'louy: loop { match ctx.try_recv().await { @@ -83,14 +85,14 @@ impl Subsystem1 { }.into(), tx, ); - ctx.send_message(msg).await; + ctx.send_message(::AllMessages::from(msg)).await; } () } } -impl overseer::Subsystem for Subsystem1 +impl overseer::Subsystem for Subsystem1 where Context: overseer::SubsystemContext, { @@ -142,11 +144,11 @@ impl Subsystem2 { } } -impl overseer::Subsystem for Subsystem2 +impl overseer::Subsystem for Subsystem2 where Context: overseer::SubsystemContext, { - fn start(self, ctx: Context) -> SpawnedSubsystem { + fn start(self, ctx: Context) -> SpawnedSubsystem { let future = Box::pin(async move { Self::run(ctx).await; Ok(()) diff --git a/node/overseer/overseer-gen/examples/dummy.rs b/node/overseer/overseer-gen/examples/dummy.rs index d2a97943914a..401e70e89f2d 100644 --- a/node/overseer/overseer-gen/examples/dummy.rs +++ b/node/overseer/overseer-gen/examples/dummy.rs @@ -1,6 +1,6 @@ //! A dummy to be used with cargo expand -pub use polkadot_overseer_gen::prelude::*; +use polkadot_overseer_gen::*; use polkadot_node_network_protocol::WrongVariant; @@ -8,8 +8,8 @@ use polkadot_node_network_protocol::WrongVariant; #[derive(Default)] pub struct AwesomeSubSys; -impl Subsystem> for AwesomeSubSys { - fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem { +impl ::polkadot_overseer_gen::Subsystem, Yikes> for AwesomeSubSys { + fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem < Yikes > { unimplemented!("starting yay!") } } @@ -17,8 +17,8 @@ impl Subsystem> for AwesomeSubSys { #[derive(Default)] pub struct GoblinTower; -impl Subsystem> for GoblinTower { - fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem { +impl ::polkadot_overseer_gen::Subsystem, Yikes> for GoblinTower { + fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem < Yikes > { unimplemented!("welcum") } } diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs index 6db5341edab8..2464dcafca0f 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs @@ -318,7 +318,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { // connection to the subsystems channels_out: ChannelsOut, ctx: Ctx, - subsystem: SubSys, + s: SubSys, futures: &mut #support_crate ::FuturesUnordered >>, ) -> ::std::result::Result, #error_ty > where diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_misc.rs b/node/overseer/overseer-gen/proc-macro/src/impl_misc.rs new file mode 100644 index 000000000000..6f4b8d0e4a15 --- /dev/null +++ b/node/overseer/overseer-gen/proc-macro/src/impl_misc.rs @@ -0,0 +1,248 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use quote::quote; +use syn::Ident; + +use super::*; + +/// Implement a builder pattern for the `Overseer`-type, +/// which acts as the gateway to constructing the overseer. +pub(crate) fn impl_misc(info: &OverseerInfo) -> proc_macro2::TokenStream { + let overseer_name = info.overseer_name.clone(); + let subsystem_sender_name = Ident::new(&(overseer_name.to_string() + "SubsystemSender"), overseer_name.span()); + let subsystem_ctx_name = Ident::new(&(overseer_name.to_string() + "SubsystemContext"), overseer_name.span()); + let consumes = &info.consumes(); + let signal = &info.extern_signal_ty; + let wrapper_message = &info.message_wrapper; + let error_ty = &info.extern_error_ty; + let support_crate = info.support_crate_name(); + + let ts = quote! { + /// Connector to send messages towards all subsystems, + /// while tracking the which signals where already received. + #[derive(Debug, Clone)] + pub struct #subsystem_sender_name { + /// Collection of channels to all subsystems. + channels: ChannelsOut, + /// Systemwide tick for which signals were received by all subsystems. + signals_received: SignalsReceived, + } + + /// impl for wrapping message type... + #[#support_crate ::async_trait] + impl SubsystemSender< #wrapper_message > for #subsystem_sender_name { + async fn send_message(&mut self, msg: #wrapper_message) { + self.channels.send_and_log_error(self.signals_received.load(), msg).await; + } + + async fn send_messages(&mut self, msgs: T) + where + T: IntoIterator + Send, + T::IntoIter: Send, + { + // This can definitely be optimized if necessary. + for msg in msgs { + self.send_message(msg).await; + } + } + + fn send_unbounded_message(&mut self, msg: #wrapper_message) { + self.channels.send_unbounded_and_log_error(self.signals_received.load(), msg); + } + } + + // ... but also implement for all individual messages to avoid + // the necessity for manual wrapping, and do the conversion + // based on the generated `From::from` impl for the individual variants. + #( + #[#support_crate ::async_trait] + impl SubsystemSender< #consumes > for #subsystem_sender_name { + async fn send_message(&mut self, msg: #consumes) { + self.channels.send_and_log_error(self.signals_received.load(), #wrapper_message ::from ( msg )).await; + } + + async fn send_messages(&mut self, msgs: T) + where + T: IntoIterator + Send, + T::IntoIter: Send, + { + // This can definitely be optimized if necessary. + for msg in msgs { + self.send_message(msg).await; + } + } + + fn send_unbounded_message(&mut self, msg: #consumes) { + self.channels.send_unbounded_and_log_error(self.signals_received.load(), #wrapper_message ::from ( msg )); + } + } + )* + + /// A context type that is given to the [`Subsystem`] upon spawning. + /// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s + /// or to spawn it's [`SubsystemJob`]s. + /// + /// [`Overseer`]: struct.Overseer.html + /// [`Subsystem`]: trait.Subsystem.html + /// [`SubsystemJob`]: trait.SubsystemJob.html + #[derive(Debug)] + #[allow(missing_docs)] + pub struct #subsystem_ctx_name{ + signals: #support_crate ::metered::MeteredReceiver< #signal >, + messages: SubsystemIncomingMessages, + to_subsystems: #subsystem_sender_name, + to_overseer: #support_crate ::metered::UnboundedMeteredSender< + #support_crate ::ToOverseer + >, + signals_received: SignalsReceived, + pending_incoming: Option<(usize, M)>, + } + + impl #subsystem_ctx_name { + /// Create a new context. + fn new( + signals: #support_crate ::metered::MeteredReceiver< #signal >, + messages: SubsystemIncomingMessages, + to_subsystems: ChannelsOut, + to_overseer: #support_crate ::metered::UnboundedMeteredSender<#support_crate ::ToOverseer>, + ) -> Self { + let signals_received = SignalsReceived::default(); + #subsystem_ctx_name { + signals, + messages, + to_subsystems: #subsystem_sender_name { + channels: to_subsystems, + signals_received: signals_received.clone(), + }, + to_overseer, + signals_received, + pending_incoming: None, + } + } + } + + #[#support_crate ::async_trait] + impl #support_crate ::SubsystemContext for #subsystem_ctx_name + where + #subsystem_sender_name: #support_crate ::SubsystemSender< #wrapper_message >, + #wrapper_message: From, + { + type Message = M; + type Signal = #signal; + type Sender = #subsystem_sender_name; + type AllMessages = #wrapper_message; + type Error = #error_ty; + + async fn try_recv(&mut self) -> ::std::result::Result>, ()> { + match #support_crate ::poll!(self.recv()) { + #support_crate ::Poll::Ready(msg) => Ok(Some(msg.map_err(|_| ())?)), + #support_crate ::Poll::Pending => Ok(None), + } + } + + async fn recv(&mut self) -> ::std::result::Result<#support_crate:: FromOverseer, #error_ty> { + loop { + // If we have a message pending an overseer signal, we only poll for signals + // in the meantime. + if let Some((needs_signals_received, msg)) = self.pending_incoming.take() { + if needs_signals_received <= self.signals_received.load() { + return Ok(#support_crate ::FromOverseer::Communication { msg }); + } else { + self.pending_incoming = Some((needs_signals_received, msg)); + + // wait for next signal. + let signal = self.signals.next().await + .ok_or(#support_crate ::OverseerError::Context( + "Signal channel is terminated and empty." + .to_owned() + ))?; + + self.signals_received.inc(); + return Ok(#support_crate ::FromOverseer::Signal(signal)) + } + } + + let mut await_message = self.messages.next().fuse(); + let mut await_signal = self.signals.next().fuse(); + let signals_received = self.signals_received.load(); + let pending_incoming = &mut self.pending_incoming; + + // Otherwise, wait for the next signal or incoming message. + let from_overseer = #support_crate ::futures::select_biased! { + signal = await_signal => { + let signal = signal + .ok_or(#support_crate ::OverseerError::Context( + "Signal channel is terminated and empty." + .to_owned() + ))?; + + #support_crate ::FromOverseer::Signal(signal) + } + msg = await_message => { + let packet = msg + .ok_or(#support_crate ::OverseerError::Context( + "Message channel is terminated and empty." + .to_owned() + ))?; + + if packet.signals_received > signals_received { + // wait until we've received enough signals to return this message. + *pending_incoming = Some((packet.signals_received, packet.message)); + continue; + } else { + // we know enough to return this message. + #support_crate ::FromOverseer::Communication { msg: packet.message} + } + } + }; + + if let #support_crate ::FromOverseer::Signal(_) = from_overseer { + self.signals_received.inc(); + } + + return Ok(from_overseer); + } + } + + fn sender(&mut self) -> &mut Self::Sender { + &mut self.to_subsystems + } + + fn spawn(&mut self, name: &'static str, s: Pin + Send>>) + -> ::std::result::Result<(), #error_ty> + { + self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnJob { + name, + s, + }).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?; + Ok(()) + } + + fn spawn_blocking(&mut self, name: &'static str, s: Pin + Send>>) + -> ::std::result::Result<(), #error_ty> + { + self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnBlockingJob { + name, + s, + }).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?; + Ok(()) + } + } + }; + + ts +} diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs b/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs index 4e3b22ac029f..0cf52807396f 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs @@ -215,7 +215,7 @@ pub(crate) fn impl_trait(info: &OverseerInfo) -> proc_macro2::TokenStream { } } - fn sender(&mut self) -> &mut Self::Sender { + fn sender(&mut self) -> &mut ::Sender { &mut self.to_subsystems } diff --git a/node/overseer/overseer-gen/proc-macro/src/lib.rs b/node/overseer/overseer-gen/proc-macro/src/lib.rs index 5860cfd860e9..9fecfd19241a 100644 --- a/node/overseer/overseer-gen/proc-macro/src/lib.rs +++ b/node/overseer/overseer-gen/proc-macro/src/lib.rs @@ -21,21 +21,19 @@ use syn::{parse2, Result}; use quote::{quote, ToTokens}; mod impl_builder; -mod impl_subsystem_ctx; +mod impl_misc; mod impl_overseer; +mod parse_attr; +mod parse_struct; mod impl_channels_out; mod impl_dispatch; mod impl_message_wrapper; -mod impl_trait; -mod parse_attr; -mod parse_struct; use impl_builder::*; use impl_channels_out::*; use impl_dispatch::*; use impl_message_wrapper::*; -use impl_subsystem_ctx::*; -use impl_trait::*; +use impl_misc::*; use impl_overseer::*; use parse_attr::*; use parse_struct::*; @@ -56,14 +54,17 @@ pub(crate) fn impl_overseer_gen(attr: TokenStream, orig: TokenStream) -> Result< let of: OverseerGuts = parse2(orig)?; - use proc_macro_crate::{crate_name, FoundCrate}; - let crate_name = crate_name("polkadot-overseer-gen") - .expect("Support crate polkadot-overseer-gen is present in `Cargo.toml`. qed"); - let support_crate_name = match crate_name { - FoundCrate::Itself => quote!{crate}, - FoundCrate::Name(name) => Ident::new(&name, Span::call_site()).to_token_stream(), + let support_crate_name = if cfg!(test) { + quote!{crate} + } else { + use proc_macro_crate::{crate_name, FoundCrate}; + let crate_name = crate_name("polkadot-overseer-gen") + .expect("Support crate polkadot-overseer-gen is present in `Cargo.toml`. qed"); + match crate_name { + FoundCrate::Itself => quote!{crate}, + FoundCrate::Name(name) => Ident::new(&name, Span::call_site()).to_token_stream(), + } }; - let info = OverseerInfo { support_crate_name, subsystems: of.subsystems, @@ -84,11 +85,10 @@ pub(crate) fn impl_overseer_gen(attr: TokenStream, orig: TokenStream) -> Result< additive.extend(impl_overseen_subsystem(&info)); additive.extend(impl_channels_out_struct(&info)); - additive.extend(impl_subsystem_ctx(&info)); + additive.extend(impl_misc(&info)); additive.extend(impl_message_wrapper_enum(&info)?); additive.extend(impl_dispatch(&info)); - additive.extend(impl_trait(&info)); Ok(additive) } diff --git a/node/overseer/overseer-gen/proc-macro/src/tests.rs b/node/overseer/overseer-gen/proc-macro/src/tests.rs index 12f958992f61..40df210fb6f0 100644 --- a/node/overseer/overseer-gen/proc-macro/src/tests.rs +++ b/node/overseer/overseer-gen/proc-macro/src/tests.rs @@ -19,6 +19,40 @@ use assert_matches::assert_matches; use quote::quote; use syn::parse_quote; +#[test] +fn print() { + let attr = quote! { + gen=AllMessage, + event=::some::why::ExternEvent, + signal=SigSigSig, + signal_capacity=111, + message_capacity=222, + error=OverseerError, + }; + + let item = quote! { + pub struct Ooooh where X: Secrit { + #[subsystem(no_dispatch, Foo)] + sub0: FooSubsystem, + + #[subsystem(blocking, Bar)] + yyy: BaersBuyBilliardBalls, + + #[subsystem(no_dispatch, blocking, Twain)] + fff: Beeeeep, + + #[subsystem(Rope)] + mc: MountainCave, + + metrics: Metrics, + } + }; + + let output = impl_overseer_gen(attr, item).expect("Simple example always works. qed"); + println!("//generated:"); + println!("{}", output); +} + #[test] fn struct_parse_full() { let item: OverseerGuts = parse_quote! { diff --git a/node/overseer/overseer-gen/src/lib.rs b/node/overseer/overseer-gen/src/lib.rs index 90ac08455521..4b6abdb2b20a 100644 --- a/node/overseer/overseer-gen/src/lib.rs +++ b/node/overseer/overseer-gen/src/lib.rs @@ -60,10 +60,6 @@ #![deny(missing_docs)] #![deny(unused_crate_dependencies)] - -/// Prelude. -pub mod prelude { - pub use polkadot_overseer_gen_proc_macro::overlord; #[doc(hidden)] @@ -98,35 +94,15 @@ pub use async_trait::async_trait; #[doc(hidden)] pub use std::time::Duration; +use std::sync::{Arc, atomic::{self, AtomicUsize}}; #[doc(hidden)] pub use futures_timer::Delay; pub use polkadot_node_network_protocol::WrongVariant; - -pub use crate::{ - ToOverseer, - Timeout, - TimeoutExt, - MapSubsystem, - MessagePacket, - SubsystemIncomingMessages, - OverseerError, - SubsystemMeters, - SubsystemMeterReadouts, - SignalsReceived, - SubsystemSender, - SubsystemInstance, - make_packet, -}; -} - - use std::fmt; -use std::sync::{Arc, atomic::{self, AtomicUsize}}; -pub use prelude::*; #[cfg(test)] mod tests; @@ -381,6 +357,100 @@ impl From for FromOverseer { } } +/// A context type that is given to the [`Subsystem`] upon spawning. +/// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s +/// or spawn jobs. +/// +/// [`Overseer`]: struct.Overseer.html +/// [`SubsystemJob`]: trait.SubsystemJob.html +#[async_trait::async_trait] +pub trait SubsystemContext: Send + 'static { + /// The message type of this context. Subsystems launched with this context will expect + /// to receive messages of this type. Commonly uses the wrapping enum commonly called + /// `AllMessages`. + type Message: std::fmt::Debug + Send + 'static; + /// And the same for signals. + type Signal: std::fmt::Debug + Send + 'static; + /// The overarching all messages enum. + /// In some cases can be identical to `Self::Message`. + type AllMessages: From + Send + 'static; + /// The sender type as provided by `sender()` and underlying. + type Sender: SubsystemSender + Send + 'static; + /// The error type. + type Error: ::std::error::Error + ::std::convert::From< OverseerError > + Sync + Send + 'static; + + /// Try to asynchronously receive a message. + /// + /// This has to be used with caution, if you loop over this without + /// using `pending!()` macro you will end up with a busy loop! + async fn try_recv(&mut self) -> Result>, ()>; + + /// Receive a message. + async fn recv(&mut self) -> Result, Self::Error>; + + /// Spawn a child task on the executor. + fn spawn( + &mut self, + name: &'static str, + s: ::std::pin::Pin + Send>> + ) -> Result<(), Self::Error>; + + /// Spawn a blocking child task on the executor's dedicated thread pool. + fn spawn_blocking( + &mut self, + name: &'static str, + s: ::std::pin::Pin + Send>>, + ) -> Result<(), Self::Error>; + + /// Send a direct message to some other `Subsystem`, routed based on message type. + async fn send_message(&mut self, msg: X) + where + Self::AllMessages: From, + X: Send, + { + self.sender().send_message(::from(msg)).await + } + + /// Send multiple direct messages to other `Subsystem`s, routed based on message type. + async fn send_messages(&mut self, msgs: T) + where + T: IntoIterator + Send, + T::IntoIter: Send, + Self::AllMessages: From, + X: Send, + { + self.sender().send_messages(msgs.into_iter().map(|x| ::from(x))).await + } + + /// Send a message using the unbounded connection. + fn send_unbounded_message(&mut self, msg: X) + where + Self::AllMessages: From, + X: Send, + { + self.sender().send_unbounded_message(Self::AllMessages::from(msg)) + } + + /// Obtain the sender. + fn sender(&mut self) -> &mut Self::Sender; +} + +/// A trait that describes the [`Subsystem`]s that can run on the [`Overseer`]. +/// +/// It is generic over the message type circulating in the system. +/// The idea that we want some type containing persistent state that +/// can spawn actually running subsystems when asked. +/// +/// [`Overseer`]: struct.Overseer.html +/// [`Subsystem`]: trait.Subsystem.html +pub trait Subsystem +where + Ctx: SubsystemContext, + E: std::error::Error + Send + Sync + 'static + From, +{ + /// Start this `Subsystem` and return `SpawnedSubsystem`. + fn start(self, ctx: Ctx) -> SpawnedSubsystem < E >; +} /// Sender end of a channel to interface with a subsystem. diff --git a/node/overseer/src/convenience.rs b/node/overseer/src/convenience.rs new file mode 100644 index 000000000000..8dd17d6ad02e --- /dev/null +++ b/node/overseer/src/convenience.rs @@ -0,0 +1,105 @@ +use crate::AllMessages; +use crate::OverseerSignal; +use crate::gen::{self, SubsystemSender}; +use crate::SubsystemError; +use crate::{self as overseer}; + +/// A `Result` type that wraps [`SubsystemError`]. +/// +/// [`SubsystemError`]: struct.SubsystemError.html +pub type SubsystemResult = Result; + +// Simplify usage without having to do large scale modifications of all +// subsystems at once. + + +/// Specialized message type originating from the overseer. +pub type FromOverseer = gen::FromOverseer; + +/// Specialized subsystem instance type of subsystems consuming a particular message type. +pub type SubsystemInstance = gen::SubsystemInstance; + +/// Spawned subsystem. +pub type SpawnedSubsystem = gen::SpawnedSubsystem; + +/// Convenience trait to reduce the number of trait parameters required. +#[async_trait::async_trait] +pub trait SubsystemContext: gen::SubsystemContext< + Signal=OverseerSignal, + AllMessages=AllMessages, + Error=SubsystemError, +> +{ + /// The message type the subsystem consumes. + type Message: std::fmt::Debug + Send + 'static; + /// Sender type to communicate with other subsystems. + type Sender: gen::SubsystemSender + Send + Clone + 'static; + + /// Try to asynchronously receive a message. + /// + /// This has to be used with caution, if you loop over this without + /// using `pending!()` macro you will end up with a busy loop! + async fn try_recv(&mut self) -> Result::Message>>, ()>; + + /// Receive a message. + async fn recv(&mut self) -> SubsystemResult::Message>>; + + /// Spawn a child task on the executor. + async fn spawn( + &mut self, + name: &'static str, + s: ::std::pin::Pin + Send>> + ) -> SubsystemResult<()>; + + /// Spawn a blocking child task on the executor's dedicated thread pool. + async fn spawn_blocking( + &mut self, + name: &'static str, + s: ::std::pin::Pin + Send>>, + ) -> SubsystemResult<()>; + + /// Obtain the sender. + fn sender(&mut self) -> &mut ::Sender; +} + +#[async_trait::async_trait] +impl gen::SubsystemContext for T +where + T: SubsystemContext, +{ + type Message = ::Message; + type Sender = ::Sender; + type Signal = OverseerSignal; + type AllMessages = AllMessages; + type Error = SubsystemError; + + async fn try_recv(&mut self) -> Result::Message, Self::Signal>>, ()> { + ::try_recv(self).await + } + + async fn recv(&mut self) -> Result::Message, Self::Signal>, Self::Error> { + ::recv(self).await + } + + async fn spawn( + &mut self, + name: &'static str, + future: ::std::pin::Pin + Send>> + ) -> Result<(), Self::Error> { + ::spawn(self, name, future).await + } + + async fn spawn_blocking( + &mut self, + name: &'static str, + future: ::std::pin::Pin + Send>>, + ) -> Result<(), Self::Error> { + ::spawn_blocking(self, name, future).await + } + + + /// Obtain the sender. + fn sender(&mut self) -> &mut ::Sender { + ::sender(self) + } +} diff --git a/node/overseer/src/lib.rs b/node/overseer/src/lib.rs index 116b62a40179..df093414d51f 100644 --- a/node/overseer/src/lib.rs +++ b/node/overseer/src/lib.rs @@ -58,7 +58,7 @@ // unused dependencies can not work for test and examples at the same time // yielding false positives #![warn(missing_docs)] -#![deny(unused_crate_dependencies)] +// #![deny(unused_crate_dependencies)] use std::fmt::{self, Debug}; use std::pin::Pin; @@ -101,6 +101,7 @@ pub use polkadot_node_subsystem_types::{ jaeger, }; + // TODO legacy, to be deleted, left for easier integration // TODO https://github.com/paritytech/polkadot/issues/3427 mod subsystems; @@ -109,6 +110,9 @@ pub use self::subsystems::AllSubsystems; mod metrics; use self::metrics::Metrics; +pub mod convenience; +pub use convenience::{SubsystemResult}; + use polkadot_node_metrics::{ metrics::{ prometheus, @@ -116,12 +120,11 @@ use polkadot_node_metrics::{ }, Metronome, }; - -pub use polkadot_overseer_gen as gen; - -pub use gen::{ +pub use polkadot_overseer_gen::{ + self as gen, TimeoutExt, SpawnNamed, + Subsystem, SubsystemMeterReadouts, SubsystemMeters, SubsystemIncomingMessages, @@ -131,11 +134,9 @@ pub use gen::{ SignalsReceived, ToOverseer, MapSubsystem, - OverseerError, }; - /// Store 2 days worth of blocks, not accounting for forks, /// in the LRU cache. Assumes a 6-second block time. const KNOWN_LEAVES_CACHE_SIZE: usize = 2 * 24 * 3600 / 6; @@ -477,15 +478,16 @@ where /// # use polkadot_overseer::{ /// # self as overseer, /// # OverseerSignal, + /// # SubsystemSender as _, /// # AllMessages, /// # AllSubsystems, /// # HeadSupportsParachains, /// # Overseer, - /// # SubsystemSender, /// # SubsystemError, - /// # SpawnedSubsystem, /// # gen::{ + /// # SubsystemContext, /// # FromOverseer, + /// # SpawnedSubsystem, /// # }, /// # }; /// # use polkadot_node_subsystem_types::messages::{ @@ -495,16 +497,19 @@ where /// /// struct ValidationSubsystem; /// - /// impl overseer::Subsystem for ValidationSubsystem + /// impl overseer::gen::Subsystem for ValidationSubsystem /// where - /// Ctx: overseer::SubsystemContext< + /// Ctx: overseer::gen::SubsystemContext< /// Message=CandidateValidationMessage, + /// AllMessages=AllMessages, + /// Signal=OverseerSignal, + /// Error=SubsystemError, /// >, /// { /// fn start( /// self, /// mut ctx: Ctx, - /// ) -> SpawnedSubsystem { + /// ) -> SpawnedSubsystem { /// SpawnedSubsystem { /// name: "validation-subsystem", /// future: Box::pin(async move { @@ -555,23 +560,23 @@ where s: S, ) -> SubsystemResult<(Self, Handle)> where - CV: Subsystem> + Send, - CB: Subsystem> + Send, - SD: Subsystem> + Send, - AD: Subsystem> + Send, - AR: Subsystem> + Send, - BS: Subsystem> + Send, - BD: Subsystem> + Send, - P: Subsystem> + Send, - RA: Subsystem> + Send, - AS: Subsystem> + Send, - NB: Subsystem> + Send, - CA: Subsystem> + Send, - CG: Subsystem> + Send, - CP: Subsystem> + Send, - ApD: Subsystem> + Send, - ApV: Subsystem> + Send, - GS: Subsystem> + Send, + CV: Subsystem, SubsystemError> + Send, + CB: Subsystem, SubsystemError> + Send, + SD: Subsystem, SubsystemError> + Send, + AD: Subsystem, SubsystemError> + Send, + AR: Subsystem, SubsystemError> + Send, + BS: Subsystem, SubsystemError> + Send, + BD: Subsystem, SubsystemError> + Send, + P: Subsystem, SubsystemError> + Send, + RA: Subsystem, SubsystemError> + Send, + AS: Subsystem, SubsystemError> + Send, + NB: Subsystem, SubsystemError> + Send, + CA: Subsystem, SubsystemError> + Send, + CG: Subsystem, SubsystemError> + Send, + CP: Subsystem, SubsystemError> + Send, + ApD: Subsystem, SubsystemError> + Send, + ApV: Subsystem, SubsystemError> + Send, + GS: Subsystem, SubsystemError> + Send, S: SpawnNamed, { let metrics: Metrics = ::register(prometheus_registry)?; @@ -704,9 +709,6 @@ where ToOverseer::SpawnJob { name, s } => { self.spawn_job(name, s); } - ToOverseer::SpawnBlockingJob { name, s } => { - self.spawn_blocking_job(name, s); - } } }, res = self.running_subsystems.select_next_some() => { diff --git a/node/overseer/src/subsystems.rs b/node/overseer/src/subsystems.rs index 98f4ccbfcb21..b255569caa74 100644 --- a/node/overseer/src/subsystems.rs +++ b/node/overseer/src/subsystems.rs @@ -19,21 +19,22 @@ //! In the future, everything should be set up using the generated //! overeseer builder pattern instead. -use super::*; - -// TODO remove legacy code +use polkadot_node_subsystem_types::errors::SubsystemError; use polkadot_overseer_all_subsystems_gen::AllSubsystemsGen; +use crate::OverseerSignal; +use crate::AllMessages; +use crate::gen::*; /// A dummy subsystem that implements [`Subsystem`] for all /// types of messages. Used for tests or as a placeholder. #[derive(Clone, Copy, Debug)] pub struct DummySubsystem; -impl Subsystem for DummySubsystem +impl Subsystem for DummySubsystem where Context: SubsystemContext, { - fn start(self, mut ctx: Context) -> SpawnedSubsystem { + fn start(self, mut ctx: Context) -> SpawnedSubsystem { let future = Box::pin(async move { loop { match ctx.recv().await { diff --git a/node/overseer/src/tests.rs b/node/overseer/src/tests.rs index 76e2fdc8182c..a4dd0359c70c 100644 --- a/node/overseer/src/tests.rs +++ b/node/overseer/src/tests.rs @@ -33,7 +33,6 @@ use polkadot_node_subsystem_types::{ use crate::{ self as overseer, - SpawnedSubsystem, Overseer, HeadSupportsParachains, gen::Delay, @@ -46,9 +45,12 @@ use assert_matches::assert_matches; use super::*; + +type SpawnedSubsystem = crate::gen::SpawnedSubsystem; + struct TestSubsystem1(metered::MeteredSender); -impl overseer::Subsystem for TestSubsystem1 +impl overseer::Subsystem for TestSubsystem1 where C: overseer::SubsystemContext, @@ -78,7 +80,7 @@ where struct TestSubsystem2(metered::MeteredSender); -impl overseer::Subsystem for TestSubsystem2 +impl overseer::Subsystem for TestSubsystem2 where C: overseer::SubsystemContext, { @@ -125,7 +127,7 @@ where struct ReturnOnStart; -impl overseer::Subsystem for ReturnOnStart +impl overseer::Subsystem for ReturnOnStart where C: overseer::SubsystemContext, { @@ -302,7 +304,7 @@ fn overseer_ends_on_subsystem_exit() { struct TestSubsystem5(metered::MeteredSender); -impl overseer::Subsystem for TestSubsystem5 +impl overseer::Subsystem for TestSubsystem5 where C: overseer::SubsystemContext, { @@ -334,7 +336,7 @@ where struct TestSubsystem6(metered::MeteredSender); -impl Subsystem for TestSubsystem6 +impl Subsystem for TestSubsystem6 where C: overseer::SubsystemContext, { @@ -683,7 +685,7 @@ impl CounterSubsystem { } } -impl Subsystem for CounterSubsystem +impl Subsystem for CounterSubsystem where C: overseer::SubsystemContext, M: Send, diff --git a/node/subsystem/src/lib.rs b/node/subsystem/src/lib.rs index c9138fafe276..773253b6e640 100644 --- a/node/subsystem/src/lib.rs +++ b/node/subsystem/src/lib.rs @@ -25,11 +25,16 @@ pub use polkadot_node_jaeger as jaeger; pub use jaeger::*; pub use polkadot_overseer::{ + self as overseer, OverseerSignal, ActiveLeavesUpdate, - self as overseer, - // FromOverseer, - // SubsystemInstance, + SubsystemContext, + FromOverseer, + SubsystemInstance, + SubsystemSender, + SpawnedSubsystem, + SubsystemError, + SubsystemResult, }; pub use polkadot_node_subsystem_types::{ From 4e4096ac2379e13bbbfeae9fdc90dfcdd623bfff Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Thu, 15 Jul 2021 15:43:50 +0200 Subject: [PATCH 11/11] Revert "attempt to move things into one spot" This reverts commit e4081cfef03713ef381659e3311949d1fe12bb43. --- Cargo.lock | 3 - node/overseer/Cargo.toml | 3 - node/overseer/examples/minimal-example.rs | 16 +- node/overseer/overseer-gen/examples/dummy.rs | 10 +- .../proc-macro/src/impl_builder.rs | 2 +- .../overseer-gen/proc-macro/src/impl_misc.rs | 248 ------------------ .../proc-macro/src/impl_subsystem_ctx.rs | 2 +- .../overseer-gen/proc-macro/src/lib.rs | 30 +-- .../overseer-gen/proc-macro/src/tests.rs | 34 --- node/overseer/overseer-gen/src/lib.rs | 120 ++------- node/overseer/src/convenience.rs | 105 -------- node/overseer/src/lib.rs | 66 +++-- node/overseer/src/subsystems.rs | 11 +- node/overseer/src/tests.rs | 16 +- node/subsystem/src/lib.rs | 11 +- 15 files changed, 101 insertions(+), 576 deletions(-) delete mode 100644 node/overseer/overseer-gen/proc-macro/src/impl_misc.rs delete mode 100644 node/overseer/src/convenience.rs diff --git a/Cargo.lock b/Cargo.lock index 602d122c05da..57d7dbfcb83c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6520,16 +6520,13 @@ name = "polkadot-overseer" version = "0.1.0" dependencies = [ "assert_matches", - "async-trait", "femme", "futures 0.3.15", - "futures-timer 3.0.2", "kv-log-macro", "lru", "metered-channel", "polkadot-node-metrics", "polkadot-node-network-protocol", - "polkadot-node-primitives", "polkadot-node-subsystem-types", "polkadot-overseer-all-subsystems-gen", "polkadot-overseer-gen", diff --git a/node/overseer/Cargo.toml b/node/overseer/Cargo.toml index 6f436c0d33fb..fe2b6c95ad57 100644 --- a/node/overseer/Cargo.toml +++ b/node/overseer/Cargo.toml @@ -5,13 +5,10 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -async-trait = "0.1.42" client = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "master" } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = "0.3.15" -futures-timer = "3.0.2" polkadot-node-network-protocol = { path = "../network/protocol" } -polkadot-node-primitives = { path = "../primitives" } polkadot-node-subsystem-types = { path = "../subsystem-types" } polkadot-node-metrics = { path = "../metrics" } polkadot-primitives = { path = "../../primitives" } diff --git a/node/overseer/examples/minimal-example.rs b/node/overseer/examples/minimal-example.rs index 71a703f99336..c199318cdbb3 100644 --- a/node/overseer/examples/minimal-example.rs +++ b/node/overseer/examples/minimal-example.rs @@ -36,10 +36,8 @@ use polkadot_overseer::{ Overseer, OverseerSignal, SubsystemError, - gen::{ - FromOverseer, - SpawnedSubsystem, - }, + FromOverseer, + SpawnedSubsystem, }; use polkadot_node_subsystem_types::messages::{ CandidateValidationMessage, CandidateBackingMessage, @@ -58,7 +56,7 @@ struct Subsystem1; impl Subsystem1 { async fn run(mut ctx: Ctx) -> () where - Ctx: overseer::SubsystemContext, + Ctx: overseer::SubsystemContext, { 'louy: loop { match ctx.try_recv().await { @@ -85,14 +83,14 @@ impl Subsystem1 { }.into(), tx, ); - ctx.send_message(::AllMessages::from(msg)).await; + ctx.send_message(msg).await; } () } } -impl overseer::Subsystem for Subsystem1 +impl overseer::Subsystem for Subsystem1 where Context: overseer::SubsystemContext, { @@ -144,11 +142,11 @@ impl Subsystem2 { } } -impl overseer::Subsystem for Subsystem2 +impl overseer::Subsystem for Subsystem2 where Context: overseer::SubsystemContext, { - fn start(self, ctx: Context) -> SpawnedSubsystem { + fn start(self, ctx: Context) -> SpawnedSubsystem { let future = Box::pin(async move { Self::run(ctx).await; Ok(()) diff --git a/node/overseer/overseer-gen/examples/dummy.rs b/node/overseer/overseer-gen/examples/dummy.rs index 401e70e89f2d..d2a97943914a 100644 --- a/node/overseer/overseer-gen/examples/dummy.rs +++ b/node/overseer/overseer-gen/examples/dummy.rs @@ -1,6 +1,6 @@ //! A dummy to be used with cargo expand -use polkadot_overseer_gen::*; +pub use polkadot_overseer_gen::prelude::*; use polkadot_node_network_protocol::WrongVariant; @@ -8,8 +8,8 @@ use polkadot_node_network_protocol::WrongVariant; #[derive(Default)] pub struct AwesomeSubSys; -impl ::polkadot_overseer_gen::Subsystem, Yikes> for AwesomeSubSys { - fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem < Yikes > { +impl Subsystem> for AwesomeSubSys { + fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem { unimplemented!("starting yay!") } } @@ -17,8 +17,8 @@ impl ::polkadot_overseer_gen::Subsystem, Yikes> f #[derive(Default)] pub struct GoblinTower; -impl ::polkadot_overseer_gen::Subsystem, Yikes> for GoblinTower { - fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem < Yikes > { +impl Subsystem> for GoblinTower { + fn start(self, _ctx: XxxSubsystemContext) -> SpawnedSubsystem { unimplemented!("welcum") } } diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs index 2464dcafca0f..6db5341edab8 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_builder.rs @@ -318,7 +318,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream { // connection to the subsystems channels_out: ChannelsOut, ctx: Ctx, - s: SubSys, + subsystem: SubSys, futures: &mut #support_crate ::FuturesUnordered >>, ) -> ::std::result::Result, #error_ty > where diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_misc.rs b/node/overseer/overseer-gen/proc-macro/src/impl_misc.rs deleted file mode 100644 index 6f4b8d0e4a15..000000000000 --- a/node/overseer/overseer-gen/proc-macro/src/impl_misc.rs +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . - -use quote::quote; -use syn::Ident; - -use super::*; - -/// Implement a builder pattern for the `Overseer`-type, -/// which acts as the gateway to constructing the overseer. -pub(crate) fn impl_misc(info: &OverseerInfo) -> proc_macro2::TokenStream { - let overseer_name = info.overseer_name.clone(); - let subsystem_sender_name = Ident::new(&(overseer_name.to_string() + "SubsystemSender"), overseer_name.span()); - let subsystem_ctx_name = Ident::new(&(overseer_name.to_string() + "SubsystemContext"), overseer_name.span()); - let consumes = &info.consumes(); - let signal = &info.extern_signal_ty; - let wrapper_message = &info.message_wrapper; - let error_ty = &info.extern_error_ty; - let support_crate = info.support_crate_name(); - - let ts = quote! { - /// Connector to send messages towards all subsystems, - /// while tracking the which signals where already received. - #[derive(Debug, Clone)] - pub struct #subsystem_sender_name { - /// Collection of channels to all subsystems. - channels: ChannelsOut, - /// Systemwide tick for which signals were received by all subsystems. - signals_received: SignalsReceived, - } - - /// impl for wrapping message type... - #[#support_crate ::async_trait] - impl SubsystemSender< #wrapper_message > for #subsystem_sender_name { - async fn send_message(&mut self, msg: #wrapper_message) { - self.channels.send_and_log_error(self.signals_received.load(), msg).await; - } - - async fn send_messages(&mut self, msgs: T) - where - T: IntoIterator + Send, - T::IntoIter: Send, - { - // This can definitely be optimized if necessary. - for msg in msgs { - self.send_message(msg).await; - } - } - - fn send_unbounded_message(&mut self, msg: #wrapper_message) { - self.channels.send_unbounded_and_log_error(self.signals_received.load(), msg); - } - } - - // ... but also implement for all individual messages to avoid - // the necessity for manual wrapping, and do the conversion - // based on the generated `From::from` impl for the individual variants. - #( - #[#support_crate ::async_trait] - impl SubsystemSender< #consumes > for #subsystem_sender_name { - async fn send_message(&mut self, msg: #consumes) { - self.channels.send_and_log_error(self.signals_received.load(), #wrapper_message ::from ( msg )).await; - } - - async fn send_messages(&mut self, msgs: T) - where - T: IntoIterator + Send, - T::IntoIter: Send, - { - // This can definitely be optimized if necessary. - for msg in msgs { - self.send_message(msg).await; - } - } - - fn send_unbounded_message(&mut self, msg: #consumes) { - self.channels.send_unbounded_and_log_error(self.signals_received.load(), #wrapper_message ::from ( msg )); - } - } - )* - - /// A context type that is given to the [`Subsystem`] upon spawning. - /// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s - /// or to spawn it's [`SubsystemJob`]s. - /// - /// [`Overseer`]: struct.Overseer.html - /// [`Subsystem`]: trait.Subsystem.html - /// [`SubsystemJob`]: trait.SubsystemJob.html - #[derive(Debug)] - #[allow(missing_docs)] - pub struct #subsystem_ctx_name{ - signals: #support_crate ::metered::MeteredReceiver< #signal >, - messages: SubsystemIncomingMessages, - to_subsystems: #subsystem_sender_name, - to_overseer: #support_crate ::metered::UnboundedMeteredSender< - #support_crate ::ToOverseer - >, - signals_received: SignalsReceived, - pending_incoming: Option<(usize, M)>, - } - - impl #subsystem_ctx_name { - /// Create a new context. - fn new( - signals: #support_crate ::metered::MeteredReceiver< #signal >, - messages: SubsystemIncomingMessages, - to_subsystems: ChannelsOut, - to_overseer: #support_crate ::metered::UnboundedMeteredSender<#support_crate ::ToOverseer>, - ) -> Self { - let signals_received = SignalsReceived::default(); - #subsystem_ctx_name { - signals, - messages, - to_subsystems: #subsystem_sender_name { - channels: to_subsystems, - signals_received: signals_received.clone(), - }, - to_overseer, - signals_received, - pending_incoming: None, - } - } - } - - #[#support_crate ::async_trait] - impl #support_crate ::SubsystemContext for #subsystem_ctx_name - where - #subsystem_sender_name: #support_crate ::SubsystemSender< #wrapper_message >, - #wrapper_message: From, - { - type Message = M; - type Signal = #signal; - type Sender = #subsystem_sender_name; - type AllMessages = #wrapper_message; - type Error = #error_ty; - - async fn try_recv(&mut self) -> ::std::result::Result>, ()> { - match #support_crate ::poll!(self.recv()) { - #support_crate ::Poll::Ready(msg) => Ok(Some(msg.map_err(|_| ())?)), - #support_crate ::Poll::Pending => Ok(None), - } - } - - async fn recv(&mut self) -> ::std::result::Result<#support_crate:: FromOverseer, #error_ty> { - loop { - // If we have a message pending an overseer signal, we only poll for signals - // in the meantime. - if let Some((needs_signals_received, msg)) = self.pending_incoming.take() { - if needs_signals_received <= self.signals_received.load() { - return Ok(#support_crate ::FromOverseer::Communication { msg }); - } else { - self.pending_incoming = Some((needs_signals_received, msg)); - - // wait for next signal. - let signal = self.signals.next().await - .ok_or(#support_crate ::OverseerError::Context( - "Signal channel is terminated and empty." - .to_owned() - ))?; - - self.signals_received.inc(); - return Ok(#support_crate ::FromOverseer::Signal(signal)) - } - } - - let mut await_message = self.messages.next().fuse(); - let mut await_signal = self.signals.next().fuse(); - let signals_received = self.signals_received.load(); - let pending_incoming = &mut self.pending_incoming; - - // Otherwise, wait for the next signal or incoming message. - let from_overseer = #support_crate ::futures::select_biased! { - signal = await_signal => { - let signal = signal - .ok_or(#support_crate ::OverseerError::Context( - "Signal channel is terminated and empty." - .to_owned() - ))?; - - #support_crate ::FromOverseer::Signal(signal) - } - msg = await_message => { - let packet = msg - .ok_or(#support_crate ::OverseerError::Context( - "Message channel is terminated and empty." - .to_owned() - ))?; - - if packet.signals_received > signals_received { - // wait until we've received enough signals to return this message. - *pending_incoming = Some((packet.signals_received, packet.message)); - continue; - } else { - // we know enough to return this message. - #support_crate ::FromOverseer::Communication { msg: packet.message} - } - } - }; - - if let #support_crate ::FromOverseer::Signal(_) = from_overseer { - self.signals_received.inc(); - } - - return Ok(from_overseer); - } - } - - fn sender(&mut self) -> &mut Self::Sender { - &mut self.to_subsystems - } - - fn spawn(&mut self, name: &'static str, s: Pin + Send>>) - -> ::std::result::Result<(), #error_ty> - { - self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnJob { - name, - s, - }).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?; - Ok(()) - } - - fn spawn_blocking(&mut self, name: &'static str, s: Pin + Send>>) - -> ::std::result::Result<(), #error_ty> - { - self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnBlockingJob { - name, - s, - }).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?; - Ok(()) - } - } - }; - - ts -} diff --git a/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs b/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs index 0cf52807396f..4e3b22ac029f 100644 --- a/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs +++ b/node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx.rs @@ -215,7 +215,7 @@ pub(crate) fn impl_trait(info: &OverseerInfo) -> proc_macro2::TokenStream { } } - fn sender(&mut self) -> &mut ::Sender { + fn sender(&mut self) -> &mut Self::Sender { &mut self.to_subsystems } diff --git a/node/overseer/overseer-gen/proc-macro/src/lib.rs b/node/overseer/overseer-gen/proc-macro/src/lib.rs index 9fecfd19241a..5860cfd860e9 100644 --- a/node/overseer/overseer-gen/proc-macro/src/lib.rs +++ b/node/overseer/overseer-gen/proc-macro/src/lib.rs @@ -21,19 +21,21 @@ use syn::{parse2, Result}; use quote::{quote, ToTokens}; mod impl_builder; -mod impl_misc; +mod impl_subsystem_ctx; mod impl_overseer; -mod parse_attr; -mod parse_struct; mod impl_channels_out; mod impl_dispatch; mod impl_message_wrapper; +mod impl_trait; +mod parse_attr; +mod parse_struct; use impl_builder::*; use impl_channels_out::*; use impl_dispatch::*; use impl_message_wrapper::*; -use impl_misc::*; +use impl_subsystem_ctx::*; +use impl_trait::*; use impl_overseer::*; use parse_attr::*; use parse_struct::*; @@ -54,17 +56,14 @@ pub(crate) fn impl_overseer_gen(attr: TokenStream, orig: TokenStream) -> Result< let of: OverseerGuts = parse2(orig)?; - let support_crate_name = if cfg!(test) { - quote!{crate} - } else { - use proc_macro_crate::{crate_name, FoundCrate}; - let crate_name = crate_name("polkadot-overseer-gen") - .expect("Support crate polkadot-overseer-gen is present in `Cargo.toml`. qed"); - match crate_name { - FoundCrate::Itself => quote!{crate}, - FoundCrate::Name(name) => Ident::new(&name, Span::call_site()).to_token_stream(), - } + use proc_macro_crate::{crate_name, FoundCrate}; + let crate_name = crate_name("polkadot-overseer-gen") + .expect("Support crate polkadot-overseer-gen is present in `Cargo.toml`. qed"); + let support_crate_name = match crate_name { + FoundCrate::Itself => quote!{crate}, + FoundCrate::Name(name) => Ident::new(&name, Span::call_site()).to_token_stream(), }; + let info = OverseerInfo { support_crate_name, subsystems: of.subsystems, @@ -85,10 +84,11 @@ pub(crate) fn impl_overseer_gen(attr: TokenStream, orig: TokenStream) -> Result< additive.extend(impl_overseen_subsystem(&info)); additive.extend(impl_channels_out_struct(&info)); - additive.extend(impl_misc(&info)); + additive.extend(impl_subsystem_ctx(&info)); additive.extend(impl_message_wrapper_enum(&info)?); additive.extend(impl_dispatch(&info)); + additive.extend(impl_trait(&info)); Ok(additive) } diff --git a/node/overseer/overseer-gen/proc-macro/src/tests.rs b/node/overseer/overseer-gen/proc-macro/src/tests.rs index 40df210fb6f0..12f958992f61 100644 --- a/node/overseer/overseer-gen/proc-macro/src/tests.rs +++ b/node/overseer/overseer-gen/proc-macro/src/tests.rs @@ -19,40 +19,6 @@ use assert_matches::assert_matches; use quote::quote; use syn::parse_quote; -#[test] -fn print() { - let attr = quote! { - gen=AllMessage, - event=::some::why::ExternEvent, - signal=SigSigSig, - signal_capacity=111, - message_capacity=222, - error=OverseerError, - }; - - let item = quote! { - pub struct Ooooh where X: Secrit { - #[subsystem(no_dispatch, Foo)] - sub0: FooSubsystem, - - #[subsystem(blocking, Bar)] - yyy: BaersBuyBilliardBalls, - - #[subsystem(no_dispatch, blocking, Twain)] - fff: Beeeeep, - - #[subsystem(Rope)] - mc: MountainCave, - - metrics: Metrics, - } - }; - - let output = impl_overseer_gen(attr, item).expect("Simple example always works. qed"); - println!("//generated:"); - println!("{}", output); -} - #[test] fn struct_parse_full() { let item: OverseerGuts = parse_quote! { diff --git a/node/overseer/overseer-gen/src/lib.rs b/node/overseer/overseer-gen/src/lib.rs index 4b6abdb2b20a..90ac08455521 100644 --- a/node/overseer/overseer-gen/src/lib.rs +++ b/node/overseer/overseer-gen/src/lib.rs @@ -60,6 +60,10 @@ #![deny(missing_docs)] #![deny(unused_crate_dependencies)] + +/// Prelude. +pub mod prelude { + pub use polkadot_overseer_gen_proc_macro::overlord; #[doc(hidden)] @@ -94,15 +98,35 @@ pub use async_trait::async_trait; #[doc(hidden)] pub use std::time::Duration; -use std::sync::{Arc, atomic::{self, AtomicUsize}}; #[doc(hidden)] pub use futures_timer::Delay; pub use polkadot_node_network_protocol::WrongVariant; + +pub use crate::{ + ToOverseer, + Timeout, + TimeoutExt, + MapSubsystem, + MessagePacket, + SubsystemIncomingMessages, + OverseerError, + SubsystemMeters, + SubsystemMeterReadouts, + SignalsReceived, + SubsystemSender, + SubsystemInstance, + make_packet, +}; +} + + use std::fmt; +use std::sync::{Arc, atomic::{self, AtomicUsize}}; +pub use prelude::*; #[cfg(test)] mod tests; @@ -357,100 +381,6 @@ impl From for FromOverseer { } } -/// A context type that is given to the [`Subsystem`] upon spawning. -/// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s -/// or spawn jobs. -/// -/// [`Overseer`]: struct.Overseer.html -/// [`SubsystemJob`]: trait.SubsystemJob.html -#[async_trait::async_trait] -pub trait SubsystemContext: Send + 'static { - /// The message type of this context. Subsystems launched with this context will expect - /// to receive messages of this type. Commonly uses the wrapping enum commonly called - /// `AllMessages`. - type Message: std::fmt::Debug + Send + 'static; - /// And the same for signals. - type Signal: std::fmt::Debug + Send + 'static; - /// The overarching all messages enum. - /// In some cases can be identical to `Self::Message`. - type AllMessages: From + Send + 'static; - /// The sender type as provided by `sender()` and underlying. - type Sender: SubsystemSender + Send + 'static; - /// The error type. - type Error: ::std::error::Error + ::std::convert::From< OverseerError > + Sync + Send + 'static; - - /// Try to asynchronously receive a message. - /// - /// This has to be used with caution, if you loop over this without - /// using `pending!()` macro you will end up with a busy loop! - async fn try_recv(&mut self) -> Result>, ()>; - - /// Receive a message. - async fn recv(&mut self) -> Result, Self::Error>; - - /// Spawn a child task on the executor. - fn spawn( - &mut self, - name: &'static str, - s: ::std::pin::Pin + Send>> - ) -> Result<(), Self::Error>; - - /// Spawn a blocking child task on the executor's dedicated thread pool. - fn spawn_blocking( - &mut self, - name: &'static str, - s: ::std::pin::Pin + Send>>, - ) -> Result<(), Self::Error>; - - /// Send a direct message to some other `Subsystem`, routed based on message type. - async fn send_message(&mut self, msg: X) - where - Self::AllMessages: From, - X: Send, - { - self.sender().send_message(::from(msg)).await - } - - /// Send multiple direct messages to other `Subsystem`s, routed based on message type. - async fn send_messages(&mut self, msgs: T) - where - T: IntoIterator + Send, - T::IntoIter: Send, - Self::AllMessages: From, - X: Send, - { - self.sender().send_messages(msgs.into_iter().map(|x| ::from(x))).await - } - - /// Send a message using the unbounded connection. - fn send_unbounded_message(&mut self, msg: X) - where - Self::AllMessages: From, - X: Send, - { - self.sender().send_unbounded_message(Self::AllMessages::from(msg)) - } - - /// Obtain the sender. - fn sender(&mut self) -> &mut Self::Sender; -} - -/// A trait that describes the [`Subsystem`]s that can run on the [`Overseer`]. -/// -/// It is generic over the message type circulating in the system. -/// The idea that we want some type containing persistent state that -/// can spawn actually running subsystems when asked. -/// -/// [`Overseer`]: struct.Overseer.html -/// [`Subsystem`]: trait.Subsystem.html -pub trait Subsystem -where - Ctx: SubsystemContext, - E: std::error::Error + Send + Sync + 'static + From, -{ - /// Start this `Subsystem` and return `SpawnedSubsystem`. - fn start(self, ctx: Ctx) -> SpawnedSubsystem < E >; -} /// Sender end of a channel to interface with a subsystem. diff --git a/node/overseer/src/convenience.rs b/node/overseer/src/convenience.rs deleted file mode 100644 index 8dd17d6ad02e..000000000000 --- a/node/overseer/src/convenience.rs +++ /dev/null @@ -1,105 +0,0 @@ -use crate::AllMessages; -use crate::OverseerSignal; -use crate::gen::{self, SubsystemSender}; -use crate::SubsystemError; -use crate::{self as overseer}; - -/// A `Result` type that wraps [`SubsystemError`]. -/// -/// [`SubsystemError`]: struct.SubsystemError.html -pub type SubsystemResult = Result; - -// Simplify usage without having to do large scale modifications of all -// subsystems at once. - - -/// Specialized message type originating from the overseer. -pub type FromOverseer = gen::FromOverseer; - -/// Specialized subsystem instance type of subsystems consuming a particular message type. -pub type SubsystemInstance = gen::SubsystemInstance; - -/// Spawned subsystem. -pub type SpawnedSubsystem = gen::SpawnedSubsystem; - -/// Convenience trait to reduce the number of trait parameters required. -#[async_trait::async_trait] -pub trait SubsystemContext: gen::SubsystemContext< - Signal=OverseerSignal, - AllMessages=AllMessages, - Error=SubsystemError, -> -{ - /// The message type the subsystem consumes. - type Message: std::fmt::Debug + Send + 'static; - /// Sender type to communicate with other subsystems. - type Sender: gen::SubsystemSender + Send + Clone + 'static; - - /// Try to asynchronously receive a message. - /// - /// This has to be used with caution, if you loop over this without - /// using `pending!()` macro you will end up with a busy loop! - async fn try_recv(&mut self) -> Result::Message>>, ()>; - - /// Receive a message. - async fn recv(&mut self) -> SubsystemResult::Message>>; - - /// Spawn a child task on the executor. - async fn spawn( - &mut self, - name: &'static str, - s: ::std::pin::Pin + Send>> - ) -> SubsystemResult<()>; - - /// Spawn a blocking child task on the executor's dedicated thread pool. - async fn spawn_blocking( - &mut self, - name: &'static str, - s: ::std::pin::Pin + Send>>, - ) -> SubsystemResult<()>; - - /// Obtain the sender. - fn sender(&mut self) -> &mut ::Sender; -} - -#[async_trait::async_trait] -impl gen::SubsystemContext for T -where - T: SubsystemContext, -{ - type Message = ::Message; - type Sender = ::Sender; - type Signal = OverseerSignal; - type AllMessages = AllMessages; - type Error = SubsystemError; - - async fn try_recv(&mut self) -> Result::Message, Self::Signal>>, ()> { - ::try_recv(self).await - } - - async fn recv(&mut self) -> Result::Message, Self::Signal>, Self::Error> { - ::recv(self).await - } - - async fn spawn( - &mut self, - name: &'static str, - future: ::std::pin::Pin + Send>> - ) -> Result<(), Self::Error> { - ::spawn(self, name, future).await - } - - async fn spawn_blocking( - &mut self, - name: &'static str, - future: ::std::pin::Pin + Send>>, - ) -> Result<(), Self::Error> { - ::spawn_blocking(self, name, future).await - } - - - /// Obtain the sender. - fn sender(&mut self) -> &mut ::Sender { - ::sender(self) - } -} diff --git a/node/overseer/src/lib.rs b/node/overseer/src/lib.rs index df093414d51f..116b62a40179 100644 --- a/node/overseer/src/lib.rs +++ b/node/overseer/src/lib.rs @@ -58,7 +58,7 @@ // unused dependencies can not work for test and examples at the same time // yielding false positives #![warn(missing_docs)] -// #![deny(unused_crate_dependencies)] +#![deny(unused_crate_dependencies)] use std::fmt::{self, Debug}; use std::pin::Pin; @@ -101,7 +101,6 @@ pub use polkadot_node_subsystem_types::{ jaeger, }; - // TODO legacy, to be deleted, left for easier integration // TODO https://github.com/paritytech/polkadot/issues/3427 mod subsystems; @@ -110,9 +109,6 @@ pub use self::subsystems::AllSubsystems; mod metrics; use self::metrics::Metrics; -pub mod convenience; -pub use convenience::{SubsystemResult}; - use polkadot_node_metrics::{ metrics::{ prometheus, @@ -120,11 +116,12 @@ use polkadot_node_metrics::{ }, Metronome, }; -pub use polkadot_overseer_gen::{ - self as gen, + +pub use polkadot_overseer_gen as gen; + +pub use gen::{ TimeoutExt, SpawnNamed, - Subsystem, SubsystemMeterReadouts, SubsystemMeters, SubsystemIncomingMessages, @@ -134,9 +131,11 @@ pub use polkadot_overseer_gen::{ SignalsReceived, ToOverseer, MapSubsystem, + OverseerError, }; + /// Store 2 days worth of blocks, not accounting for forks, /// in the LRU cache. Assumes a 6-second block time. const KNOWN_LEAVES_CACHE_SIZE: usize = 2 * 24 * 3600 / 6; @@ -478,16 +477,15 @@ where /// # use polkadot_overseer::{ /// # self as overseer, /// # OverseerSignal, - /// # SubsystemSender as _, /// # AllMessages, /// # AllSubsystems, /// # HeadSupportsParachains, /// # Overseer, + /// # SubsystemSender, /// # SubsystemError, + /// # SpawnedSubsystem, /// # gen::{ - /// # SubsystemContext, /// # FromOverseer, - /// # SpawnedSubsystem, /// # }, /// # }; /// # use polkadot_node_subsystem_types::messages::{ @@ -497,19 +495,16 @@ where /// /// struct ValidationSubsystem; /// - /// impl overseer::gen::Subsystem for ValidationSubsystem + /// impl overseer::Subsystem for ValidationSubsystem /// where - /// Ctx: overseer::gen::SubsystemContext< + /// Ctx: overseer::SubsystemContext< /// Message=CandidateValidationMessage, - /// AllMessages=AllMessages, - /// Signal=OverseerSignal, - /// Error=SubsystemError, /// >, /// { /// fn start( /// self, /// mut ctx: Ctx, - /// ) -> SpawnedSubsystem { + /// ) -> SpawnedSubsystem { /// SpawnedSubsystem { /// name: "validation-subsystem", /// future: Box::pin(async move { @@ -560,23 +555,23 @@ where s: S, ) -> SubsystemResult<(Self, Handle)> where - CV: Subsystem, SubsystemError> + Send, - CB: Subsystem, SubsystemError> + Send, - SD: Subsystem, SubsystemError> + Send, - AD: Subsystem, SubsystemError> + Send, - AR: Subsystem, SubsystemError> + Send, - BS: Subsystem, SubsystemError> + Send, - BD: Subsystem, SubsystemError> + Send, - P: Subsystem, SubsystemError> + Send, - RA: Subsystem, SubsystemError> + Send, - AS: Subsystem, SubsystemError> + Send, - NB: Subsystem, SubsystemError> + Send, - CA: Subsystem, SubsystemError> + Send, - CG: Subsystem, SubsystemError> + Send, - CP: Subsystem, SubsystemError> + Send, - ApD: Subsystem, SubsystemError> + Send, - ApV: Subsystem, SubsystemError> + Send, - GS: Subsystem, SubsystemError> + Send, + CV: Subsystem> + Send, + CB: Subsystem> + Send, + SD: Subsystem> + Send, + AD: Subsystem> + Send, + AR: Subsystem> + Send, + BS: Subsystem> + Send, + BD: Subsystem> + Send, + P: Subsystem> + Send, + RA: Subsystem> + Send, + AS: Subsystem> + Send, + NB: Subsystem> + Send, + CA: Subsystem> + Send, + CG: Subsystem> + Send, + CP: Subsystem> + Send, + ApD: Subsystem> + Send, + ApV: Subsystem> + Send, + GS: Subsystem> + Send, S: SpawnNamed, { let metrics: Metrics = ::register(prometheus_registry)?; @@ -709,6 +704,9 @@ where ToOverseer::SpawnJob { name, s } => { self.spawn_job(name, s); } + ToOverseer::SpawnBlockingJob { name, s } => { + self.spawn_blocking_job(name, s); + } } }, res = self.running_subsystems.select_next_some() => { diff --git a/node/overseer/src/subsystems.rs b/node/overseer/src/subsystems.rs index b255569caa74..98f4ccbfcb21 100644 --- a/node/overseer/src/subsystems.rs +++ b/node/overseer/src/subsystems.rs @@ -19,22 +19,21 @@ //! In the future, everything should be set up using the generated //! overeseer builder pattern instead. -use polkadot_node_subsystem_types::errors::SubsystemError; +use super::*; + +// TODO remove legacy code use polkadot_overseer_all_subsystems_gen::AllSubsystemsGen; -use crate::OverseerSignal; -use crate::AllMessages; -use crate::gen::*; /// A dummy subsystem that implements [`Subsystem`] for all /// types of messages. Used for tests or as a placeholder. #[derive(Clone, Copy, Debug)] pub struct DummySubsystem; -impl Subsystem for DummySubsystem +impl Subsystem for DummySubsystem where Context: SubsystemContext, { - fn start(self, mut ctx: Context) -> SpawnedSubsystem { + fn start(self, mut ctx: Context) -> SpawnedSubsystem { let future = Box::pin(async move { loop { match ctx.recv().await { diff --git a/node/overseer/src/tests.rs b/node/overseer/src/tests.rs index a4dd0359c70c..76e2fdc8182c 100644 --- a/node/overseer/src/tests.rs +++ b/node/overseer/src/tests.rs @@ -33,6 +33,7 @@ use polkadot_node_subsystem_types::{ use crate::{ self as overseer, + SpawnedSubsystem, Overseer, HeadSupportsParachains, gen::Delay, @@ -45,12 +46,9 @@ use assert_matches::assert_matches; use super::*; - -type SpawnedSubsystem = crate::gen::SpawnedSubsystem; - struct TestSubsystem1(metered::MeteredSender); -impl overseer::Subsystem for TestSubsystem1 +impl overseer::Subsystem for TestSubsystem1 where C: overseer::SubsystemContext, @@ -80,7 +78,7 @@ where struct TestSubsystem2(metered::MeteredSender); -impl overseer::Subsystem for TestSubsystem2 +impl overseer::Subsystem for TestSubsystem2 where C: overseer::SubsystemContext, { @@ -127,7 +125,7 @@ where struct ReturnOnStart; -impl overseer::Subsystem for ReturnOnStart +impl overseer::Subsystem for ReturnOnStart where C: overseer::SubsystemContext, { @@ -304,7 +302,7 @@ fn overseer_ends_on_subsystem_exit() { struct TestSubsystem5(metered::MeteredSender); -impl overseer::Subsystem for TestSubsystem5 +impl overseer::Subsystem for TestSubsystem5 where C: overseer::SubsystemContext, { @@ -336,7 +334,7 @@ where struct TestSubsystem6(metered::MeteredSender); -impl Subsystem for TestSubsystem6 +impl Subsystem for TestSubsystem6 where C: overseer::SubsystemContext, { @@ -685,7 +683,7 @@ impl CounterSubsystem { } } -impl Subsystem for CounterSubsystem +impl Subsystem for CounterSubsystem where C: overseer::SubsystemContext, M: Send, diff --git a/node/subsystem/src/lib.rs b/node/subsystem/src/lib.rs index 773253b6e640..c9138fafe276 100644 --- a/node/subsystem/src/lib.rs +++ b/node/subsystem/src/lib.rs @@ -25,16 +25,11 @@ pub use polkadot_node_jaeger as jaeger; pub use jaeger::*; pub use polkadot_overseer::{ - self as overseer, OverseerSignal, ActiveLeavesUpdate, - SubsystemContext, - FromOverseer, - SubsystemInstance, - SubsystemSender, - SpawnedSubsystem, - SubsystemError, - SubsystemResult, + self as overseer, + // FromOverseer, + // SubsystemInstance, }; pub use polkadot_node_subsystem_types::{