StatementDistributionMessage::get_metadata is a footgun and should be 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>
This commit is contained in:
Doordashcon
2022-03-15 12:52:01 +01:00
committed by GitHub
parent 3a862e2a54
commit b72bd9ef6c
2 changed files with 17 additions and 24 deletions
@@ -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,
@@ -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 {
@@ -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 {
@@ -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
@@ -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(),
}
}