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
@@ -276,8 +276,8 @@ async fn handle_new_activations<Context: SubsystemContext>(
ctx.spawn("collation generation collation builder", Box::pin(async move {
let persisted_validation_data_hash = validation_data.hash();
let collation = match (task_config.collator)(relay_parent, &validation_data).await {
Some(collation) => collation,
let (collation, result_sender) = match (task_config.collator)(relay_parent, &validation_data).await {
Some(collation) => collation.into_inner(),
None => {
tracing::debug!(
target: LOG_TARGET,
@@ -348,7 +348,7 @@ async fn handle_new_activations<Context: SubsystemContext>(
metrics.on_collation_generated();
if let Err(err) = task_sender.send(AllMessages::CollatorProtocol(
CollatorProtocolMessage::DistributeCollation(ccr, collation.proof_of_validity)
CollatorProtocolMessage::DistributeCollation(ccr, collation.proof_of_validity, result_sender)
)).await {
tracing::warn!(
target: LOG_TARGET,
@@ -465,7 +465,7 @@ mod tests {
task::{Context as FuturesContext, Poll},
Future,
};
use polkadot_node_primitives::Collation;
use polkadot_node_primitives::{Collation, CollationResult};
use polkadot_node_subsystem::messages::{
AllMessages, RuntimeApiMessage, RuntimeApiRequest,
};
@@ -496,10 +496,10 @@ mod tests {
struct TestCollator;
impl Future for TestCollator {
type Output = Option<Collation>;
type Output = Option<CollationResult>;
fn poll(self: Pin<&mut Self>, _cx: &mut FuturesContext) -> Poll<Self::Output> {
Poll::Ready(Some(test_collation()))
Poll::Ready(Some(CollationResult { collation: test_collation(), result_sender: None }))
}
}
@@ -755,6 +755,7 @@ mod tests {
AllMessages::CollatorProtocol(CollatorProtocolMessage::DistributeCollation(
CandidateReceipt { descriptor, .. },
_pov,
..
)) => {
// signature generation is non-deterministic, so we can't just assert that the
// expected descriptor is correct. What we can do is validate that the produced