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

Commit

Permalink
StatementDistributionMessage::get_metadata is a footgun and should be…
Browse files Browse the repository at this point in the history
… removed (#5101)

* remove get_metadata method

* cargo fmt

* add get_metadata function in test

* cargo fmt

* Update node/network/statement-distribution/src/tests.rs

Co-authored-by: Robert Habermeier <rphmeier@gmail.com>

* update

* update

Co-authored-by: Robert Habermeier <rphmeier@gmail.com>
  • Loading branch information
Doordashcon and rphmeier authored Mar 15, 2022
1 parent 00e7262 commit e888a68
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
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 = derive_metadata_assuming_seconded(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 = derive_metadata_assuming_seconded(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 = derive_metadata_assuming_seconded(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 derive_metadata_assuming_seconded(
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(),
}
}

0 comments on commit e888a68

Please sign in to comment.