Simplify subsystem jobs (#2037)

* Simplify subsystem jobs

This pr simplifies the subsystem jobs interface. Instead of requiring an
extra message that is used to signal that a job should be ended, a job
now ends when the receiver returns `None`. Besides that it changes the
interface to enforce that messages to a job provide a relay parent.

* Drop ToJobTrait

* Remove FromJob

We always convert this message to FromJobCommand anyway.
This commit is contained in:
Bastian Köcher
2020-11-30 17:01:26 +01:00
committed by GitHub
parent 2d4aa3a42e
commit 536dceb4f6
9 changed files with 246 additions and 686 deletions
+24 -23
View File
@@ -39,8 +39,13 @@ use polkadot_primitives::v1::{
ValidationCode, ValidatorId, ValidationData, CandidateHash,
ValidatorIndex, ValidatorSignature, InboundDownwardMessage, InboundHrmpMessage,
};
use std::sync::Arc;
use std::collections::btree_map::BTreeMap;
use std::{sync::Arc, collections::btree_map::BTreeMap};
/// Subsystem messages where each message is always bound to a relay parent.
pub trait BoundToRelayParent {
/// Returns the relay parent this message is bound to.
fn relay_parent(&self) -> Hash;
}
/// A notification of a new backed candidate.
#[derive(Debug)]
@@ -56,12 +61,11 @@ pub enum CandidateSelectionMessage {
Invalid(Hash, CandidateReceipt),
}
impl CandidateSelectionMessage {
/// If the current variant contains the relay parent hash, return it.
pub fn relay_parent(&self) -> Option<Hash> {
impl BoundToRelayParent for CandidateSelectionMessage {
fn relay_parent(&self) -> Hash {
match self {
Self::Collation(hash, ..) => Some(*hash),
Self::Invalid(hash, _) => Some(*hash),
Self::Collation(hash, ..) => *hash,
Self::Invalid(hash, _) => *hash,
}
}
}
@@ -86,13 +90,12 @@ pub enum CandidateBackingMessage {
Statement(Hash, SignedFullStatement),
}
impl CandidateBackingMessage {
/// If the current variant contains the relay parent hash, return it.
pub fn relay_parent(&self) -> Option<Hash> {
impl BoundToRelayParent for CandidateBackingMessage {
fn relay_parent(&self) -> Hash {
match self {
Self::GetBackedCandidates(hash, _) => Some(*hash),
Self::Second(hash, _, _) => Some(*hash),
Self::Statement(hash, _) => Some(*hash),
Self::GetBackedCandidates(hash, _) => *hash,
Self::Second(hash, _, _) => *hash,
Self::Statement(hash, _) => *hash,
}
}
}
@@ -273,10 +276,9 @@ impl BitfieldDistributionMessage {
#[derive(Debug)]
pub enum BitfieldSigningMessage {}
impl BitfieldSigningMessage {
/// If the current variant contains the relay parent hash, return it.
pub fn relay_parent(&self) -> Option<Hash> {
None
impl BoundToRelayParent for BitfieldSigningMessage {
fn relay_parent(&self) -> Hash {
match *self {}
}
}
@@ -525,13 +527,12 @@ pub enum ProvisionerMessage {
ProvisionableData(Hash, ProvisionableData),
}
impl ProvisionerMessage {
/// If the current variant contains the relay parent hash, return it.
pub fn relay_parent(&self) -> Option<Hash> {
impl BoundToRelayParent for ProvisionerMessage {
fn relay_parent(&self) -> Hash {
match self {
Self::RequestBlockAuthorshipData(hash, _) => Some(*hash),
Self::RequestInherentData(hash, _) => Some(*hash),
Self::ProvisionableData(hash, _) => Some(*hash),
Self::RequestBlockAuthorshipData(hash, _) => *hash,
Self::RequestInherentData(hash, _) => *hash,
Self::ProvisionableData(hash, _) => *hash,
}
}
}