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

establish new node folder for overseer, messages, and subsystems #1200

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ members = [
"erasure-coding",
"network",
"network/test",
"overseer",
"primitives",
"runtime/common",
"runtime/parachains",
Expand All @@ -41,6 +40,9 @@ members = [
"service",
"validation",

"node/messages",
"node/overseer",

"parachain/test-parachains",
"parachain/test-parachains/adder",
"parachain/test-parachains/adder/collator",
Expand Down
1 change: 1 addition & 0 deletions node/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stub - This folder will hold core subsystem implementations, each with their own crate.
9 changes: 9 additions & 0 deletions node/messages/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "polkadot-node-messages"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
description = "Message types used by Subsystems"

[dependencies]
polkadot-primitives = { path = "../../primitives" }
80 changes: 80 additions & 0 deletions node/messages/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2017-2020 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 <http://www.gnu.org/licenses/>.

//! Message types for the overseer and subsystems.
//!
//! Subsystems' APIs are defined separately from their implementation, leading to easier mocking.

use polkadot_primitives::Hash;

/// A signal used by [`Overseer`] to communicate with the [`Subsystem`]s.
///
/// [`Overseer`]: struct.Overseer.html
montekki marked this conversation as resolved.
Show resolved Hide resolved
/// [`Subsystem`]: trait.Subsystem.html
montekki marked this conversation as resolved.
Show resolved Hide resolved
#[derive(PartialEq, Clone, Debug)]
pub enum OverseerSignal {
/// `Subsystem` should start working on block-based work, given by the relay-chain block hash.
StartWork(Hash),
/// `Subsystem` should stop working on block-based work specified by the relay-chain block hash.
StopWork(Hash),
/// Conclude the work of the `Overseer` and all `Subsystem`s.
Conclude,
}

/// A message type used by the Validation [`Subsystem`].
///
/// [`Subsystem`]: trait.Subsystem.html
montekki marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Debug)]
pub enum ValidationSubsystemMessage {
ValidityAttestation,
}

/// A message type used by the CandidateBacking [`Subsystem`].
///
/// [`Subsystem`]: trait.Subsystem.html
montekki marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Debug)]
pub enum CandidateBackingSubsystemMessage {
RegisterBackingWatcher,
Second,
}

/// A message type tying together all message types that are used across [`Subsystem`]s.
///
/// [`Subsystem`]: trait.Subsystem.html
montekki marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Debug)]
pub enum AllMessages {
Validation(ValidationSubsystemMessage),
CandidateBacking(CandidateBackingSubsystemMessage),
}

/// A message type that a [`Subsystem`] receives from the [`Overseer`].
/// It wraps siglans from the [`Overseer`] and messages that are circulating
/// between subsystems.
///
/// It is generic over over the message type `M` that a particular `Subsystem` may use.
///
/// [`Overseer`]: struct.Overseer.html
montekki marked this conversation as resolved.
Show resolved Hide resolved
/// [`Subsystem`]: trait.Subsystem.html
montekki marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Debug)]
pub enum FromOverseer<M: std::fmt::Debug> {
/// Signal from the `Overseer`.
Signal(OverseerSignal),

/// Some other `Subsystem`'s message.
Communication {
msg: M,
},
}
1 change: 1 addition & 0 deletions node/network/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stub - This folder will hold networking subsystem implementations, each with their own crate.
5 changes: 3 additions & 2 deletions overseer/Cargo.toml → node/overseer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "overseer"
name = "polkadot-overseer"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
Expand All @@ -9,8 +9,9 @@ futures = "0.3.5"
log = "0.4.8"
futures-timer = "3.0.2"
streamunordered = "0.5.1"
polkadot-primitives = { path = "../primitives" }
polkadot-primitives = { path = "../../primitives" }
client = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "master" }
messages = { package = "polkadot-node-messages", path = "../messages" }

[dev-dependencies]
futures = { version = "0.3.5", features = ["thread-pool"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ use futures::{
use futures_timer::Delay;
use kv_log_macro as log;

use overseer::{
AllMessages, CandidateBackingSubsystemMessage, FromOverseer,
Overseer, Subsystem, SubsystemContext, SpawnedSubsystem, ValidationSubsystemMessage,
use polkadot_overseer::{Overseer, Subsystem, SubsystemContext, SpawnedSubsystem};

use messages::{
AllMessages, CandidateBackingSubsystemMessage, FromOverseer, ValidationSubsystemMessage
};

struct Subsystem1;
Expand Down
77 changes: 8 additions & 69 deletions overseer/src/lib.rs → node/overseer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ use streamunordered::{StreamYield, StreamUnordered};
use polkadot_primitives::{Block, BlockNumber, Hash};
use client::{BlockImportNotification, BlockchainEvents, FinalityNotification};

pub use messages::{
OverseerSignal, ValidationSubsystemMessage, CandidateBackingSubsystemMessage, AllMessages,
FromOverseer,
};

/// An error type that describes faults that may happen
///
/// These are:
Expand Down Expand Up @@ -183,13 +188,6 @@ enum Event {
Stop,
}

/// Some message that is sent from one of the `Subsystem`s to the outside world.
pub enum OutboundMessage {
SubsystemMessage {
msg: AllMessages,
}
}

/// A handler used to communicate with the [`Overseer`].
///
/// [`Overseer`]: struct.Overseer.html
Expand Down Expand Up @@ -228,7 +226,7 @@ impl OverseerHandler {
}
}

/// Glues together the [`Overseer`] and `BlockchainEvents` by forwarding
/// Glues together the [`Overseer`] and `BlockchainEvents` by forwarding
/// import and finality notifications into the [`OverseerHandler`].
///
/// [`Overseer`]: struct.Overseer.html
Expand Down Expand Up @@ -295,65 +293,6 @@ pub struct SubsystemContext<M: Debug>{
tx: mpsc::Sender<ToOverseer>,
}

/// A signal used by [`Overseer`] to communicate with the [`Subsystem`]s.
///
/// [`Overseer`]: struct.Overseer.html
/// [`Subsystem`]: trait.Subsystem.html
#[derive(PartialEq, Clone, Debug)]
pub enum OverseerSignal {
/// `Subsystem` should start working.
StartWork(Hash),
/// `Subsystem` should stop working.
StopWork(Hash),
/// Conclude the work of the `Overseer` and all `Subsystem`s.
Conclude,
}

#[derive(Debug)]
/// A message type used by the Validation [`Subsystem`].
///
/// [`Subsystem`]: trait.Subsystem.html
pub enum ValidationSubsystemMessage {
ValidityAttestation,
}

#[derive(Debug)]
/// A message type used by the CandidateBacking [`Subsystem`].
///
/// [`Subsystem`]: trait.Subsystem.html
pub enum CandidateBackingSubsystemMessage {
RegisterBackingWatcher,
Second,
}

/// A message type tying together all message types that are used across [`Subsystem`]s.
///
/// [`Subsystem`]: trait.Subsystem.html
#[derive(Debug)]
pub enum AllMessages {
Validation(ValidationSubsystemMessage),
CandidateBacking(CandidateBackingSubsystemMessage),
}

/// A message type that a [`Subsystem`] receives from the [`Overseer`].
/// It wraps siglans from the [`Overseer`] and messages that are circulating
/// between subsystems.
///
/// It is generic over over the message type `M` that a particular `Subsystem` may use.
///
/// [`Overseer`]: struct.Overseer.html
/// [`Subsystem`]: trait.Subsystem.html
#[derive(Debug)]
pub enum FromOverseer<M: Debug> {
/// Signal from the `Overseer`.
Signal(OverseerSignal),

/// Some other `Subsystem`'s message.
Communication {
msg: M,
},
}

impl<M: Debug> SubsystemContext<M> {
/// Try to asyncronously receive a message.
///
Expand Down Expand Up @@ -501,7 +440,7 @@ where
/// # use std::time::Duration;
/// # use futures::{executor, pin_mut, select, FutureExt};
/// # use futures_timer::Delay;
/// # use overseer::{
/// # use polkadot_overseer::{
/// # Overseer, Subsystem, SpawnedSubsystem, SubsystemContext,
/// # ValidationSubsystemMessage, CandidateBackingSubsystemMessage,
/// # };
Expand Down Expand Up @@ -898,7 +837,7 @@ mod tests {
//
// Should immediately conclude the overseer itself with an error.
#[test]
fn overseer_panics_on_sybsystem_exit() {
fn overseer_panics_on_subsystem_exit() {
let spawner = executor::ThreadPool::new().unwrap();

executor::block_on(async move {
Expand Down