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

StatementDistributionMessage::get_metadata is a footgun and should be removed #5101

Merged
merged 8 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions node/network/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,6 @@ pub mod v1 {
}

impl StatementDistributionMessage {
/// Get meta data of the given `StatementDistributionMessage`.
pub fn get_metadata(&self) -> StatementMetadata {
match self {
Self::Statement(relay_parent, statement) => StatementMetadata {
relay_parent: *relay_parent,
candidate_hash: statement.unchecked_payload().candidate_hash(),
signed_by: statement.unchecked_validator_index(),
signature: statement.unchecked_signature().clone(),
},
Self::LargeStatement(metadata) => metadata.clone(),
}
}

/// Get fingerprint describing the contained statement uniquely.
pub fn get_fingerprint(&self) -> (CompactStatement, ValidatorIndex) {
match self {
Expand Down
28 changes: 17 additions & 11 deletions node/network/statement-distribution/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ use polkadot_node_network_protocol::{
},
view, ObservedRole,
};
use polkadot_node_primitives::Statement;
use polkadot_node_primitives::{Statement, UncheckedSignedFullStatement};
use polkadot_node_subsystem_test_helpers::mock::make_ferdie_keystore;
use polkadot_primitives::v2::{SessionInfo, ValidationCode};
use polkadot_primitives::v2::{Hash, SessionInfo, ValidationCode};
use polkadot_primitives_test_helpers::{dummy_committed_candidate_receipt, dummy_hash};
use polkadot_subsystem::{
jaeger,
Expand Down Expand Up @@ -1053,9 +1053,7 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
.expect("should be signed")
};

let metadata =
protocol_v1::StatementDistributionMessage::Statement(hash_a, statement.clone().into())
.get_metadata();
let metadata = get_metadata(hash_a, statement.clone().into());

handle
.send(FromOverseer::Communication {
Expand Down Expand Up @@ -1592,9 +1590,7 @@ fn share_prioritizes_backing_group() {
.expect("should be signed")
};

let metadata =
protocol_v1::StatementDistributionMessage::Statement(hash_a, statement.clone().into())
.get_metadata();
let metadata = get_metadata(hash_a, statement.clone().into());

handle
.send(FromOverseer::Communication {
Expand Down Expand Up @@ -1783,9 +1779,7 @@ fn peer_cant_flood_with_large_statements() {
.expect("should be signed")
};

let metadata =
protocol_v1::StatementDistributionMessage::Statement(hash_a, statement.clone().into())
.get_metadata();
let metadata = get_metadata(hash_a, statement.clone().into());

for _ in 0..MAX_LARGE_STATEMENTS_PER_SENDER + 1 {
handle
Expand Down Expand Up @@ -1870,3 +1864,15 @@ fn make_session_info(validators: Vec<Pair>, groups: Vec<Vec<u32>>) -> SessionInf
random_seed: [0u8; 32],
}
}

fn get_metadata(
Doordashcon marked this conversation as resolved.
Show resolved Hide resolved
hash: Hash,
statement: UncheckedSignedFullStatement,
) -> protocol_v1::StatementMetadata {
protocol_v1::StatementMetadata {
relay_parent: hash,
candidate_hash: statement.unchecked_payload().candidate_hash(),
signed_by: statement.unchecked_validator_index(),
signature: statement.unchecked_signature().clone(),
}
}