Unverified Commit 5d462ca2 authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Return `relay_parent` as result of collation seconded signal as well (#3577)

* Return `relay_parent` as result of collation seconded signal as well

Before we only returned the seconded statement. However, to verify the
statement in a future proof way, we also need the relay parent that was
used as a context to sign the statement.

* FMT
parent 2792b74d
Pipeline #151345 passed with stages
in 40 minutes and 53 seconds
...@@ -32,7 +32,7 @@ use polkadot_node_network_protocol::{ ...@@ -32,7 +32,7 @@ use polkadot_node_network_protocol::{
}, },
v1 as protocol_v1, OurView, PeerId, UnifiedReputationChange as Rep, View, v1 as protocol_v1, OurView, PeerId, UnifiedReputationChange as Rep, View,
}; };
use polkadot_node_primitives::{PoV, SignedFullStatement, Statement}; use polkadot_node_primitives::{CollationSecondedSignal, PoV, Statement};
use polkadot_node_subsystem_util::{ use polkadot_node_subsystem_util::{
metrics::{self, prometheus}, metrics::{self, prometheus},
runtime::{get_availability_cores, get_group_rotation_info, RuntimeInfo}, runtime::{get_availability_cores, get_group_rotation_info, RuntimeInfo},
...@@ -266,7 +266,7 @@ struct State { ...@@ -266,7 +266,7 @@ struct State {
collations: HashMap<Hash, Collation>, collations: HashMap<Hash, Collation>,
/// The result senders per collation. /// The result senders per collation.
collation_result_senders: HashMap<CandidateHash, oneshot::Sender<SignedFullStatement>>, collation_result_senders: HashMap<CandidateHash, oneshot::Sender<CollationSecondedSignal>>,
/// Our validator groups per active leaf. /// Our validator groups per active leaf.
our_validators_groups: HashMap<Hash, ValidatorGroup>, our_validators_groups: HashMap<Hash, ValidatorGroup>,
...@@ -336,7 +336,7 @@ async fn distribute_collation<Context>( ...@@ -336,7 +336,7 @@ async fn distribute_collation<Context>(
id: ParaId, id: ParaId,
receipt: CandidateReceipt, receipt: CandidateReceipt,
pov: PoV, pov: PoV,
result_sender: Option<oneshot::Sender<SignedFullStatement>>, result_sender: Option<oneshot::Sender<CollationSecondedSignal>>,
) -> Result<()> ) -> Result<()>
where where
Context: SubsystemContext<Message = CollatorProtocolMessage>, Context: SubsystemContext<Message = CollatorProtocolMessage>,
...@@ -866,7 +866,7 @@ where ...@@ -866,7 +866,7 @@ where
?origin, ?origin,
"received a `CollationSeconded`", "received a `CollationSeconded`",
); );
let _ = sender.send(statement); let _ = sender.send(CollationSecondedSignal { statement, relay_parent });
} }
} }
}, },
......
...@@ -215,6 +215,17 @@ pub struct Collation<BlockNumber = polkadot_primitives::v1::BlockNumber> { ...@@ -215,6 +215,17 @@ pub struct Collation<BlockNumber = polkadot_primitives::v1::BlockNumber> {
pub hrmp_watermark: BlockNumber, pub hrmp_watermark: BlockNumber,
} }
/// Signal that is being returned back when a collation was seconded by a validator.
#[derive(Debug)]
pub struct CollationSecondedSignal {
/// The hash of the relay chain block that was used as context to sign [`Self::statement`].
pub relay_parent: Hash,
/// The statement about seconding the collation.
///
/// Anything else than [`Statement::Seconded`](Statement::Seconded) is forbidden here.
pub statement: SignedFullStatement,
}
/// Result of the [`CollatorFn`] invocation. /// Result of the [`CollatorFn`] invocation.
pub struct CollationResult { pub struct CollationResult {
/// The collation that was build. /// The collation that was build.
...@@ -224,14 +235,14 @@ pub struct CollationResult { ...@@ -224,14 +235,14 @@ pub struct CollationResult {
/// There is no guarantee that this sender is informed ever about any result, it is completely okay to just drop it. /// There is no guarantee that this sender is informed ever about any result, it is completely okay to just drop it.
/// However, if it is called, it should be called with the signed statement of a parachain validator seconding the /// However, if it is called, it should be called with the signed statement of a parachain validator seconding the
/// collation. /// collation.
pub result_sender: Option<futures::channel::oneshot::Sender<SignedFullStatement>>, pub result_sender: Option<futures::channel::oneshot::Sender<CollationSecondedSignal>>,
} }
impl CollationResult { impl CollationResult {
/// Convert into the inner values. /// Convert into the inner values.
pub fn into_inner( pub fn into_inner(
self, self,
) -> (Collation, Option<futures::channel::oneshot::Sender<SignedFullStatement>>) { ) -> (Collation, Option<futures::channel::oneshot::Sender<CollationSecondedSignal>>) {
(self.collation, self.result_sender) (self.collation, self.result_sender)
} }
} }
......
...@@ -35,8 +35,8 @@ use polkadot_node_network_protocol::{ ...@@ -35,8 +35,8 @@ use polkadot_node_network_protocol::{
use polkadot_node_primitives::{ use polkadot_node_primitives::{
approval::{BlockApprovalMeta, IndirectAssignmentCert, IndirectSignedApprovalVote}, approval::{BlockApprovalMeta, IndirectAssignmentCert, IndirectSignedApprovalVote},
AvailableData, BabeEpoch, BlockWeight, CandidateVotes, CollationGenerationConfig, AvailableData, BabeEpoch, BlockWeight, CandidateVotes, CollationGenerationConfig,
DisputeMessage, ErasureChunk, PoV, SignedDisputeStatement, SignedFullStatement, CollationSecondedSignal, DisputeMessage, ErasureChunk, PoV, SignedDisputeStatement,
ValidationResult, SignedFullStatement, ValidationResult,
}; };
use polkadot_primitives::v1::{ use polkadot_primitives::v1::{
AuthorityDiscoveryId, BackedCandidate, BlockNumber, CandidateDescriptor, CandidateEvent, AuthorityDiscoveryId, BackedCandidate, BlockNumber, CandidateDescriptor, CandidateEvent,
...@@ -158,7 +158,7 @@ pub enum CollatorProtocolMessage { ...@@ -158,7 +158,7 @@ pub enum CollatorProtocolMessage {
/// ///
/// The result sender should be informed when at least one parachain validator seconded the collation. It is also /// 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. /// completely okay to just drop the sender.
DistributeCollation(CandidateReceipt, PoV, Option<oneshot::Sender<SignedFullStatement>>), DistributeCollation(CandidateReceipt, PoV, Option<oneshot::Sender<CollationSecondedSignal>>),
/// Report a collator as having provided an invalid collation. This should lead to disconnect /// Report a collator as having provided an invalid collation. This should lead to disconnect
/// and blacklist of the collator. /// and blacklist of the collator.
ReportCollator(CollatorId), ReportCollator(CollatorId),
......
...@@ -20,7 +20,7 @@ use futures::channel::oneshot; ...@@ -20,7 +20,7 @@ use futures::channel::oneshot;
use futures_timer::Delay; use futures_timer::Delay;
use parity_scale_codec::{Decode, Encode}; use parity_scale_codec::{Decode, Encode};
use polkadot_node_primitives::{ use polkadot_node_primitives::{
Collation, CollationResult, CollatorFn, PoV, SignedFullStatement, Statement, Collation, CollationResult, CollationSecondedSignal, CollatorFn, PoV, Statement,
}; };
use polkadot_primitives::v1::{CollatorId, CollatorPair}; use polkadot_primitives::v1::{CollatorId, CollatorPair};
use sp_core::{traits::SpawnNamed, Pair}; use sp_core::{traits::SpawnNamed, Pair};
...@@ -182,19 +182,19 @@ impl Collator { ...@@ -182,19 +182,19 @@ impl Collator {
let compressed_pov = polkadot_node_primitives::maybe_compress_pov(pov); let compressed_pov = polkadot_node_primitives::maybe_compress_pov(pov);
let (result_sender, recv) = oneshot::channel::<SignedFullStatement>(); let (result_sender, recv) = oneshot::channel::<CollationSecondedSignal>();
let seconded_collations = seconded_collations.clone(); let seconded_collations = seconded_collations.clone();
spawner.spawn( spawner.spawn(
"adder-collator-seconded", "adder-collator-seconded",
async move { async move {
if let Ok(res) = recv.await { if let Ok(res) = recv.await {
if !matches!( if !matches!(
res.payload(), res.statement.payload(),
Statement::Seconded(s) if s.descriptor.pov_hash == compressed_pov.hash(), Statement::Seconded(s) if s.descriptor.pov_hash == compressed_pov.hash(),
) { ) {
log::error!( log::error!(
"Seconded statement should match our collation: {:?}", "Seconded statement should match our collation: {:?}",
res.payload() res.statement.payload()
); );
std::process::exit(-1); std::process::exit(-1);
} }
......
...@@ -387,7 +387,7 @@ enum CollatorProtocolMessage { ...@@ -387,7 +387,7 @@ enum CollatorProtocolMessage {
/// ///
/// The result sender should be informed when at least one parachain validator seconded the collation. It is also /// 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. /// completely okay to just drop the sender.
DistributeCollation(CandidateReceipt, PoV, Option<oneshot::Sender<SignedFullStatement>>), DistributeCollation(CandidateReceipt, PoV, Option<oneshot::Sender<CollationSecondedSignal>>),
/// Fetch a collation under the given relay-parent for the given ParaId. /// Fetch a collation under the given relay-parent for the given ParaId.
FetchCollation(Hash, ParaId, ResponseChannel<(CandidateReceipt, PoV)>), FetchCollation(Hash, ParaId, ResponseChannel<(CandidateReceipt, PoV)>),
/// Report a collator as having provided an invalid collation. This should lead to disconnect /// Report a collator as having provided an invalid collation. This should lead to disconnect
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment