Notify collators about seconded collation (#2430)

* Notify collators about seconded collation

This pr adds functionality to inform a collator that its collation was
seconded by a parachain validator. Before this signed statement was only
gossiped over the validation substream. Now, we explicitly send the
seconded statement to the collator after it was validated successfully.

Besides that it changes the `CollatorFn` to return an optional result
sender that is informed when the build collation was seconded by a
parachain validator.

* Add test

* Make sure we only send `Seconded` statements

* Make sure we only receive valid statements

* Review feedback
This commit is contained in:
Bastian Köcher
2021-02-14 17:36:04 +01:00
committed by GitHub
parent 1b3d00d9d3
commit 4975521d48
21 changed files with 315 additions and 147 deletions
+15 -6
View File
@@ -63,8 +63,13 @@ pub enum CandidateSelectionMessage {
/// A candidate collation can be fetched from a collator and should be considered for seconding.
Collation(Hash, ParaId, CollatorId),
/// We recommended a particular candidate to be seconded, but it was invalid; penalize the collator.
///
/// The hash is the relay parent.
Invalid(Hash, CandidateReceipt),
/// The candidate we recommended to be seconded was validated successfully.
///
/// The hash is the relay parent.
Seconded(Hash, SignedFullStatement),
}
impl BoundToRelayParent for CandidateSelectionMessage {
@@ -72,6 +77,7 @@ impl BoundToRelayParent for CandidateSelectionMessage {
match self {
Self::Collation(hash, ..) => *hash,
Self::Invalid(hash, _) => *hash,
Self::Seconded(hash, _) => *hash,
}
}
}
@@ -174,8 +180,11 @@ pub enum CollatorProtocolMessage {
///
/// This should be sent before any `DistributeCollation` message.
CollateOn(ParaId),
/// Provide a collation to distribute to validators.
DistributeCollation(CandidateReceipt, PoV),
/// Provide a collation to distribute to validators with an optional result sender.
///
/// The result sender should be informed when at least one parachain validator seconded the collation. It is also
/// completely okay to just drop the sender.
DistributeCollation(CandidateReceipt, PoV, Option<oneshot::Sender<SignedFullStatement>>),
/// Fetch a collation under the given relay-parent for the given ParaId.
FetchCollation(Hash, CollatorId, ParaId, oneshot::Sender<(CandidateReceipt, PoV)>),
/// Report a collator as having provided an invalid collation. This should lead to disconnect
@@ -183,6 +192,8 @@ pub enum CollatorProtocolMessage {
ReportCollator(CollatorId),
/// Note a collator as having provided a good collation.
NoteGoodCollation(CollatorId),
/// Notify a collator that its collation was seconded.
NotifyCollationSeconded(CollatorId, SignedFullStatement),
/// Get a network bridge update.
NetworkBridgeUpdateV1(NetworkBridgeEvent<protocol_v1::CollatorProtocolMessage>),
}
@@ -192,11 +203,12 @@ impl CollatorProtocolMessage {
pub fn relay_parent(&self) -> Option<Hash> {
match self {
Self::CollateOn(_) => None,
Self::DistributeCollation(receipt, _) => Some(receipt.descriptor().relay_parent),
Self::DistributeCollation(receipt, _, _) => Some(receipt.descriptor().relay_parent),
Self::FetchCollation(relay_parent, _, _, _) => Some(*relay_parent),
Self::ReportCollator(_) => None,
Self::NoteGoodCollation(_) => None,
Self::NetworkBridgeUpdateV1(_) => None,
Self::NotifyCollationSeconded(_, _) => None,
}
}
}
@@ -503,8 +515,6 @@ pub enum StatementDistributionMessage {
Share(Hash, SignedFullStatement),
/// Event from the network bridge.
NetworkBridgeUpdateV1(NetworkBridgeEvent<protocol_v1::StatementDistributionMessage>),
/// Register a listener for shared statements.
RegisterStatementListener(mpsc::Sender<SignedFullStatement>),
}
impl StatementDistributionMessage {
@@ -513,7 +523,6 @@ impl StatementDistributionMessage {
match self {
Self::Share(hash, _) => Some(*hash),
Self::NetworkBridgeUpdateV1(_) => None,
Self::RegisterStatementListener(_) => None,
}
}
}