Skip to content

Commit 2f3ade7

Browse files
sw10paantkve
authored andcommitted
network: remove handling of validation protocol versions 1 and 2 (#7449)
## Issue [[#7410] Remove validation protocol versions 1 and 2](#7410) ## What was done? - [X] Remove `ValidationVersion` `V1` and `V2`; - [X] Clean up `ApprovalDistributionMessage`; - [X] Clean up `BitfieldDistributionMessage`; - [X] Clean up `StatementDistributionMessage`; - [X] Add PRdoc. ## What is left to do? - Clean up the `Versioned` enum: - Separate collation from validation (not sure if it's possible, but if it is, it will require significant changes); - Remove definitions of old versions of messages whose handling was removed in this PR (should not be difficult, probably 1-2 days of work). - Remove the `v2` folder from `statement-distribution` since there is no longer a legacy variant (should be easy, will just require updating imports where it is used).
1 parent 7684da5 commit 2f3ade7

File tree

34 files changed

+699
-5713
lines changed

34 files changed

+699
-5713
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polkadot/node/core/approval-voting-parallel/src/lib.rs

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -518,87 +518,6 @@ fn validator_index_for_msg(
518518
Option<Vec<(ValidatorIndex, polkadot_node_network_protocol::ApprovalDistributionMessage)>>,
519519
) {
520520
match msg {
521-
polkadot_node_network_protocol::Versioned::V1(ref message) => match message {
522-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Assignments(msgs) =>
523-
if let Ok(validator) = msgs.iter().map(|(msg, _)| msg.validator).all_equal_value() {
524-
(Some((validator, msg)), None)
525-
} else {
526-
let split = msgs
527-
.iter()
528-
.map(|(msg, claimed_candidates)| {
529-
(
530-
msg.validator,
531-
polkadot_node_network_protocol::Versioned::V1(
532-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Assignments(
533-
vec![(msg.clone(), *claimed_candidates)]
534-
),
535-
),
536-
)
537-
})
538-
.collect_vec();
539-
(None, Some(split))
540-
},
541-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Approvals(msgs) =>
542-
if let Ok(validator) = msgs.iter().map(|msg| msg.validator).all_equal_value() {
543-
(Some((validator, msg)), None)
544-
} else {
545-
let split = msgs
546-
.iter()
547-
.map(|vote| {
548-
(
549-
vote.validator,
550-
polkadot_node_network_protocol::Versioned::V1(
551-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Approvals(
552-
vec![vote.clone()]
553-
),
554-
),
555-
)
556-
})
557-
.collect_vec();
558-
(None, Some(split))
559-
},
560-
},
561-
polkadot_node_network_protocol::Versioned::V2(ref message) => match message {
562-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Assignments(msgs) =>
563-
if let Ok(validator) = msgs.iter().map(|(msg, _)| msg.validator).all_equal_value() {
564-
(Some((validator, msg)), None)
565-
} else {
566-
let split = msgs
567-
.iter()
568-
.map(|(msg, claimed_candidates)| {
569-
(
570-
msg.validator,
571-
polkadot_node_network_protocol::Versioned::V2(
572-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Assignments(
573-
vec![(msg.clone(), *claimed_candidates)]
574-
),
575-
),
576-
)
577-
})
578-
.collect_vec();
579-
(None, Some(split))
580-
},
581-
582-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Approvals(msgs) =>
583-
if let Ok(validator) = msgs.iter().map(|msg| msg.validator).all_equal_value() {
584-
(Some((validator, msg)), None)
585-
} else {
586-
let split = msgs
587-
.iter()
588-
.map(|vote| {
589-
(
590-
vote.validator,
591-
polkadot_node_network_protocol::Versioned::V2(
592-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Approvals(
593-
vec![vote.clone()]
594-
),
595-
),
596-
)
597-
})
598-
.collect_vec();
599-
(None, Some(split))
600-
},
601-
},
602521
polkadot_node_network_protocol::Versioned::V3(ref message) => match message {
603522
polkadot_node_network_protocol::v3::ApprovalDistributionMessage::Assignments(msgs) =>
604523
if let Ok(validator) = msgs.iter().map(|(msg, _)| msg.validator).all_equal_value() {
@@ -639,6 +558,14 @@ fn validator_index_for_msg(
639558
(None, Some(split))
640559
},
641560
},
561+
_ => {
562+
gum::warn!(
563+
target: LOG_TARGET,
564+
"Received approval distribution message with unsupported protocol version",
565+
);
566+
567+
(None, None)
568+
},
642569
}
643570
}
644571

polkadot/node/core/approval-voting-parallel/src/tests.rs

Lines changed: 5 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ use polkadot_node_core_approval_voting::{ApprovalVotingWorkProvider, Config};
3434
use polkadot_node_network_protocol::{peer_set::ValidationVersion, ObservedRole, PeerId, View};
3535
use polkadot_node_primitives::approval::{
3636
time::SystemClock,
37-
v1::{
38-
AssignmentCert, AssignmentCertKind, IndirectAssignmentCert, IndirectSignedApprovalVote,
39-
RELAY_VRF_MODULO_CONTEXT,
40-
},
37+
v1::RELAY_VRF_MODULO_CONTEXT,
4138
v2::{
4239
AssignmentCertKindV2, AssignmentCertV2, CoreBitfield, IndirectAssignmentCertV2,
4340
IndirectSignedApprovalVoteV2,
@@ -65,24 +62,6 @@ pub mod test_constants {
6562
pub(crate) const NUM_COLUMNS: u32 = 1;
6663
}
6764

68-
fn fake_assignment_cert(block_hash: Hash, validator: ValidatorIndex) -> IndirectAssignmentCert {
69-
let ctx = schnorrkel::signing_context(RELAY_VRF_MODULO_CONTEXT);
70-
let msg = b"WhenParachains?";
71-
let mut prng = rand_core::OsRng;
72-
let keypair = schnorrkel::Keypair::generate_with(&mut prng);
73-
let (inout, proof, _) = keypair.vrf_sign(ctx.bytes(msg));
74-
let preout = inout.to_preout();
75-
76-
IndirectAssignmentCert {
77-
block_hash,
78-
validator,
79-
cert: AssignmentCert {
80-
kind: AssignmentCertKind::RelayVRFModulo { sample: 1 },
81-
vrf: VrfSignature { pre_output: VrfPreOutput(preout), proof: VrfProof(proof) },
82-
},
83-
}
84-
}
85-
8665
fn fake_assignment_cert_v2(
8766
block_hash: Hash,
8867
validator: ValidatorIndex,
@@ -869,36 +848,12 @@ fn test_peer_view_is_prioritized_when_unread_messages_in_the_queue() {
869848
// Test validator_index_for_msg with empty messages.
870849
#[test]
871850
fn test_validator_index_with_empty_message() {
872-
let result = validator_index_for_msg(polkadot_node_network_protocol::Versioned::V1(
873-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Assignments(vec![]),
874-
));
875-
876-
assert_eq!(result, (None, Some(vec![])));
877-
878-
let result = validator_index_for_msg(polkadot_node_network_protocol::Versioned::V2(
879-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Assignments(vec![]),
880-
));
881-
882-
assert_eq!(result, (None, Some(vec![])));
883-
884851
let result = validator_index_for_msg(polkadot_node_network_protocol::Versioned::V3(
885852
polkadot_node_network_protocol::v3::ApprovalDistributionMessage::Assignments(vec![]),
886853
));
887854

888855
assert_eq!(result, (None, Some(vec![])));
889856

890-
let result = validator_index_for_msg(polkadot_node_network_protocol::Versioned::V1(
891-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Approvals(vec![]),
892-
));
893-
894-
assert_eq!(result, (None, Some(vec![])));
895-
896-
let result = validator_index_for_msg(polkadot_node_network_protocol::Versioned::V2(
897-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Approvals(vec![]),
898-
));
899-
900-
assert_eq!(result, (None, Some(vec![])));
901-
902857
let result = validator_index_for_msg(polkadot_node_network_protocol::Versioned::V3(
903858
polkadot_node_network_protocol::v3::ApprovalDistributionMessage::Approvals(vec![]),
904859
));
@@ -909,68 +864,6 @@ fn test_validator_index_with_empty_message() {
909864
// Test validator_index_for_msg when all the messages are originating from the same validator.
910865
#[test]
911866
fn test_validator_index_with_all_messages_from_the_same_validator() {
912-
let validator_index = ValidatorIndex(3);
913-
let v1_assignment = polkadot_node_network_protocol::Versioned::V1(
914-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Assignments(vec![
915-
(fake_assignment_cert(H256::random(), validator_index), 1),
916-
(fake_assignment_cert(H256::random(), validator_index), 3),
917-
]),
918-
);
919-
let result = validator_index_for_msg(v1_assignment.clone());
920-
921-
assert_eq!(result, (Some((validator_index, v1_assignment)), None));
922-
923-
let v1_approval = polkadot_node_network_protocol::Versioned::V1(
924-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Approvals(vec![
925-
IndirectSignedApprovalVote {
926-
block_hash: H256::random(),
927-
candidate_index: 1,
928-
validator: validator_index,
929-
signature: dummy_signature(),
930-
},
931-
IndirectSignedApprovalVote {
932-
block_hash: H256::random(),
933-
candidate_index: 1,
934-
validator: validator_index,
935-
signature: dummy_signature(),
936-
},
937-
]),
938-
);
939-
let result = validator_index_for_msg(v1_approval.clone());
940-
941-
assert_eq!(result, (Some((validator_index, v1_approval)), None));
942-
943-
let validator_index = ValidatorIndex(3);
944-
let v2_assignment = polkadot_node_network_protocol::Versioned::V2(
945-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Assignments(vec![
946-
(fake_assignment_cert(H256::random(), validator_index), 1),
947-
(fake_assignment_cert(H256::random(), validator_index), 3),
948-
]),
949-
);
950-
let result = validator_index_for_msg(v2_assignment.clone());
951-
952-
assert_eq!(result, (Some((validator_index, v2_assignment)), None));
953-
954-
let v2_approval = polkadot_node_network_protocol::Versioned::V2(
955-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Approvals(vec![
956-
IndirectSignedApprovalVote {
957-
block_hash: H256::random(),
958-
candidate_index: 1,
959-
validator: validator_index,
960-
signature: dummy_signature(),
961-
},
962-
IndirectSignedApprovalVote {
963-
block_hash: H256::random(),
964-
candidate_index: 1,
965-
validator: validator_index,
966-
signature: dummy_signature(),
967-
},
968-
]),
969-
);
970-
let result = validator_index_for_msg(v2_approval.clone());
971-
972-
assert_eq!(result, (Some((validator_index, v2_approval)), None));
973-
974867
let validator_index = ValidatorIndex(3);
975868
let v3_assignment = polkadot_node_network_protocol::Versioned::V3(
976869
polkadot_node_network_protocol::v3::ApprovalDistributionMessage::Assignments(vec![
@@ -1017,58 +910,6 @@ fn test_validator_index_with_messages_from_different_validators() {
1017910
let first_validator_index = ValidatorIndex(3);
1018911
let second_validator_index = ValidatorIndex(4);
1019912
let assignments = vec![
1020-
(fake_assignment_cert(H256::random(), first_validator_index), 1),
1021-
(fake_assignment_cert(H256::random(), second_validator_index), 3),
1022-
];
1023-
let v1_assignment = polkadot_node_network_protocol::Versioned::V1(
1024-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Assignments(
1025-
assignments.clone(),
1026-
),
1027-
);
1028-
let result = validator_index_for_msg(v1_assignment.clone());
1029-
1030-
assert_matches!(result, (None, Some(_)));
1031-
let messsages_split_by_validator = result.1.unwrap();
1032-
assert_eq!(messsages_split_by_validator.len(), assignments.len());
1033-
for (index, (validator_index, message)) in messsages_split_by_validator.into_iter().enumerate()
1034-
{
1035-
assert_eq!(validator_index, assignments[index].0.validator);
1036-
assert_eq!(
1037-
message,
1038-
polkadot_node_network_protocol::Versioned::V1(
1039-
polkadot_node_network_protocol::v1::ApprovalDistributionMessage::Assignments(
1040-
assignments.get(index).into_iter().cloned().collect(),
1041-
),
1042-
)
1043-
);
1044-
}
1045-
1046-
let v2_assignment = polkadot_node_network_protocol::Versioned::V2(
1047-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Assignments(
1048-
assignments.clone(),
1049-
),
1050-
);
1051-
let result = validator_index_for_msg(v2_assignment.clone());
1052-
1053-
assert_matches!(result, (None, Some(_)));
1054-
let messsages_split_by_validator = result.1.unwrap();
1055-
assert_eq!(messsages_split_by_validator.len(), assignments.len());
1056-
for (index, (validator_index, message)) in messsages_split_by_validator.into_iter().enumerate()
1057-
{
1058-
assert_eq!(validator_index, assignments[index].0.validator);
1059-
assert_eq!(
1060-
message,
1061-
polkadot_node_network_protocol::Versioned::V2(
1062-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Assignments(
1063-
assignments.get(index).into_iter().cloned().collect(),
1064-
),
1065-
)
1066-
);
1067-
}
1068-
1069-
let first_validator_index = ValidatorIndex(3);
1070-
let second_validator_index = ValidatorIndex(4);
1071-
let v2_assignments = vec![
1072913
(
1073914
fake_assignment_cert_v2(H256::random(), first_validator_index, CoreIndex(1).into()),
1074915
1.into(),
@@ -1079,61 +920,24 @@ fn test_validator_index_with_messages_from_different_validators() {
1079920
),
1080921
];
1081922

1082-
let approvals = vec![
1083-
IndirectSignedApprovalVote {
1084-
block_hash: H256::random(),
1085-
candidate_index: 1,
1086-
validator: first_validator_index,
1087-
signature: dummy_signature(),
1088-
},
1089-
IndirectSignedApprovalVote {
1090-
block_hash: H256::random(),
1091-
candidate_index: 2,
1092-
validator: second_validator_index,
1093-
signature: dummy_signature(),
1094-
},
1095-
];
1096-
let v2_approvals = polkadot_node_network_protocol::Versioned::V2(
1097-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Approvals(
1098-
approvals.clone(),
1099-
),
1100-
);
1101-
let result = validator_index_for_msg(v2_approvals.clone());
1102-
1103-
assert_matches!(result, (None, Some(_)));
1104-
let messsages_split_by_validator = result.1.unwrap();
1105-
assert_eq!(messsages_split_by_validator.len(), approvals.len());
1106-
for (index, (validator_index, message)) in messsages_split_by_validator.into_iter().enumerate()
1107-
{
1108-
assert_eq!(validator_index, approvals[index].validator);
1109-
assert_eq!(
1110-
message,
1111-
polkadot_node_network_protocol::Versioned::V2(
1112-
polkadot_node_network_protocol::v2::ApprovalDistributionMessage::Approvals(
1113-
approvals.get(index).into_iter().cloned().collect(),
1114-
),
1115-
)
1116-
);
1117-
}
1118-
1119923
let v3_assignment = polkadot_node_network_protocol::Versioned::V3(
1120924
polkadot_node_network_protocol::v3::ApprovalDistributionMessage::Assignments(
1121-
v2_assignments.clone(),
925+
assignments.clone(),
1122926
),
1123927
);
1124928
let result = validator_index_for_msg(v3_assignment.clone());
1125929

1126930
assert_matches!(result, (None, Some(_)));
1127931
let messsages_split_by_validator = result.1.unwrap();
1128-
assert_eq!(messsages_split_by_validator.len(), v2_assignments.len());
932+
assert_eq!(messsages_split_by_validator.len(), assignments.len());
1129933
for (index, (validator_index, message)) in messsages_split_by_validator.into_iter().enumerate()
1130934
{
1131-
assert_eq!(validator_index, v2_assignments[index].0.validator);
935+
assert_eq!(validator_index, assignments[index].0.validator);
1132936
assert_eq!(
1133937
message,
1134938
polkadot_node_network_protocol::Versioned::V3(
1135939
polkadot_node_network_protocol::v3::ApprovalDistributionMessage::Assignments(
1136-
v2_assignments.get(index).into_iter().cloned().collect(),
940+
assignments.get(index).into_iter().cloned().collect(),
1137941
),
1138942
)
1139943
);

0 commit comments

Comments
 (0)