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 authored and GitHub committed 2021-02-14 17:36:04 +01:00
1 parent 1b3d00d9d3
commit 4975521d48
21 files changed
+315 -147

No files matched your search

+28 -5
View File
@@ -528,7 +528,12 @@ impl CandidateBackingJob {
descriptor: candidate.descriptor.clone(),
commitments,
});
self.sign_import_and_distribute_statement(statement, parent_span).await?;
if let Some(stmt) = self.sign_import_and_distribute_statement(
statement,
parent_span,
).await? {
self.issue_candidate_seconded_message(stmt).await?;
}
self.distribute_pov(candidate.descriptor, pov).await?;
}
}
@@ -586,6 +591,15 @@ impl CandidateBackingJob {
Ok(())
}
async fn issue_candidate_seconded_message(
&mut self,
statement: SignedFullStatement,
) -> Result<(), Error> {
self.tx_from.send(AllMessages::from(CandidateSelectionMessage::Seconded(self.parent, statement)).into()).await?;
Ok(())
}
/// Kick off background validation with intent to second.
#[tracing::instrument(level = "trace", skip(self, parent_span, pov), fields(subsystem = LOG_TARGET))]
async fn validate_and_second(
@@ -631,13 +645,14 @@ impl CandidateBackingJob {
&mut self,
statement: Statement,
parent_span: &JaegerSpan,
) -> Result<(), Error> {
) -> Result<Option<SignedFullStatement>, Error> {
if let Some(signed_statement) = self.sign_statement(statement).await {
self.import_statement(&signed_statement, parent_span).await?;
self.distribute_signed_statement(signed_statement).await?;
self.distribute_signed_statement(signed_statement.clone()).await?;
Ok(Some(signed_statement))
} else {
Ok(None)
}
Ok(())
}
/// Check if there have happened any new misbehaviors and issue necessary messages.
@@ -1486,6 +1501,14 @@ mod tests {
}
);
assert_matches!(
virtual_overseer.recv().await,
AllMessages::CandidateSelection(CandidateSelectionMessage::Seconded(hash, statement)) => {
assert_eq!(test_state.relay_parent, hash);
assert_matches!(statement.payload(), Statement::Seconded(_));
}
);
assert_matches!(
virtual_overseer.recv().await,
AllMessages::PoVDistribution(PoVDistributionMessage::DistributePoV(hash, descriptor, pov_received)) => {