Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Extract legacy statement distribution to its own module #6026

Merged
Merged
5 changes: 1 addition & 4 deletions node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,10 +1606,7 @@ async fn sign_import_and_distribute_statement<Context>(
if let Some(signed_statement) = sign_statement(&*rp_state, statement, keystore, metrics).await {
import_statement(ctx, rp_state, per_candidate, &signed_statement).await?;

let smsg = StatementDistributionMessage::Share(
rp_state.parent,
StatementWithPVD::drop_pvd_from_signed(signed_statement.clone()),
);
let smsg = StatementDistributionMessage::Share(rp_state.parent, signed_statement.clone());
ctx.send_unbounded_message(smsg);

Ok(Some(signed_statement))
Expand Down
8 changes: 4 additions & 4 deletions node/core/backing/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ fn backing_misbehavior_works() {
signed_statement,
)
) if relay_parent == test_state.relay_parent => {
assert_eq!(*signed_statement.payload(), Statement::Valid(candidate_a_hash));
assert_eq!(*signed_statement.payload(), StatementWithPVD::Valid(candidate_a_hash));
}
);

Expand Down Expand Up @@ -1092,14 +1092,14 @@ fn backing_dont_second_invalid() {
virtual_overseer.recv().await,
AllMessages::CandidateValidation(
CandidateValidationMessage::ValidateFromExhaustive(
_pvd,
pvd,
_validation_code,
candidate_receipt,
_pov,
timeout,
tx,
),
) if _pvd == pvd_b &&
) if pvd == pvd_b &&
_validation_code == validation_code_b &&
*_pov == pov_block_b && &candidate_receipt.descriptor == candidate_b.descriptor() &&
timeout == BACKING_EXECUTION_TIMEOUT &&
Expand Down Expand Up @@ -1135,7 +1135,7 @@ fn backing_dont_second_invalid() {
signed_statement,
)
) if parent_hash == test_state.relay_parent => {
assert_eq!(*signed_statement.payload(), Statement::Seconded(candidate_b));
assert_eq!(*signed_statement.payload(), StatementWithPVD::Seconded(candidate_b, pvd_b.clone()));
}
);

Expand Down
2 changes: 1 addition & 1 deletion node/core/backing/src/tests/prospective_parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ fn concurrent_dependent_candidates() {
let payload = statement.payload();
assert_matches!(
payload.clone(),
Statement::Valid(hash)
StatementWithPVD::Valid(hash)
if hash == candidate_a_hash || hash == candidate_b_hash =>
{
assert!(valid_statements.insert(hash));
Expand Down
2 changes: 1 addition & 1 deletion node/network/collator-protocol/src/collator_side/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ async fn handle_network_msg<Context>(
PeerMessage(remote, Versioned::V1(msg)) => {
handle_incoming_peer_message(ctx, runtime, state, remote, msg).await?;
},
PeerMessage(_, Versioned::VStaging(msg)) => {},
PeerMessage(_, Versioned::VStaging(_msg)) => {},
NewGossipTopology { .. } => {
// impossible!
},
Expand Down
2 changes: 1 addition & 1 deletion node/network/collator-protocol/src/validator_side/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ async fn handle_network_msg<Context>(
PeerMessage(remote, Versioned::V1(msg)) => {
process_incoming_peer_message(ctx, state, remote, msg).await;
},
PeerMessage(_, Versioned::VStaging(msg)) => {},
PeerMessage(_, Versioned::VStaging(_msg)) => {},
}

Ok(())
Expand Down
73 changes: 11 additions & 62 deletions node/network/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ pub mod vstaging {
use parity_scale_codec::{Decode, Encode};

use polkadot_primitives::vstaging::{
CandidateHash, CandidateIndex, CollatorId, CollatorSignature, CompactStatement, Hash,
Id as ParaId, UncheckedSignedAvailabilityBitfield, ValidatorIndex, ValidatorSignature,
CandidateIndex, CollatorId, CollatorSignature, Hash, Id as ParaId,
UncheckedSignedAvailabilityBitfield,
};

use polkadot_node_primitives::{
Expand All @@ -612,67 +612,16 @@ pub mod vstaging {
/// Network messages used by the statement distribution subsystem.
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
pub enum StatementDistributionMessage {
/// A signed full statement under a given relay-parent.
#[codec(index = 0)]
Statement(Hash, UncheckedSignedFullStatement),
/// Seconded statement with large payload (e.g. containing a runtime upgrade).
// TODO [now]: notifications for v2
/// All messages for V1 for compatibility with the statement distribution
/// protocol, for relay-parents that don't support asynchronous backing.
///
/// We only gossip the hash in that case, actual payloads can be fetched from sending node
/// via request/response.
#[codec(index = 1)]
LargeStatement(StatementMetadata),
}

/// Data that makes a statement unique.
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq, Hash)]
pub struct StatementMetadata {
/// Relay parent this statement is relevant under.
pub relay_parent: Hash,
/// Hash of the candidate that got validated.
pub candidate_hash: CandidateHash,
/// Validator that attested the validity.
pub signed_by: ValidatorIndex,
/// Signature of seconding validator.
pub signature: ValidatorSignature,
}

impl StatementDistributionMessage {
/// Get fingerprint describing the contained statement uniquely.
pub fn get_fingerprint(&self) -> (CompactStatement, ValidatorIndex) {
match self {
Self::Statement(_, statement) => (
statement.unchecked_payload().to_compact(),
statement.unchecked_validator_index(),
),
Self::LargeStatement(meta) =>
(CompactStatement::Seconded(meta.candidate_hash), meta.signed_by),
}
}

/// Get the signature from the statement.
pub fn get_signature(&self) -> ValidatorSignature {
match self {
Self::Statement(_, statement) => statement.unchecked_signature().clone(),
Self::LargeStatement(metadata) => metadata.signature.clone(),
}
}

/// Get contained relay parent.
pub fn get_relay_parent(&self) -> Hash {
match self {
Self::Statement(r, _) => *r,
Self::LargeStatement(meta) => meta.relay_parent,
}
}

/// Whether this message contains a large statement.
pub fn is_large_statement(&self) -> bool {
if let Self::LargeStatement(_) = self {
true
} else {
false
}
}
/// These are illegal to send to V1 peers, and illegal to send concerning relay-parents
/// which support asynchronous backing. This backwards compatibility should be
/// considered immediately deprecated and can be removed once the node software
/// is not required to support asynchronous backing anymore.
#[codec(index = 255)]
V1Compatibility(crate::v1::StatementDistributionMessage),
}

/// Network messages used by the approval distribution subsystem.
Expand Down
Loading