Make sure we don't send messages multiple times in the availability distribution subsystem (#2015)

This commit is contained in:
Bastian Köcher
2020-11-26 16:13:44 +01:00
committed by GitHub
parent 119eb34fa8
commit e761c99852
3 changed files with 145 additions and 60 deletions
@@ -314,7 +314,7 @@ fn helper_integrity() {
let candidate = TestCandidateBuilder {
para_id: test_state.chain_ids[0],
relay_parent: test_state.relay_parent,
pov_hash: pov_hash,
pov_hash,
erasure_root: make_erasure_root(&test_state, pov_block.clone()),
..Default::default()
}
@@ -395,7 +395,7 @@ fn reputation_verification() {
}
.build(),
TestCandidateBuilder {
para_id: test_state.chain_ids[0],
para_id: test_state.chain_ids[1],
relay_parent: test_state.relay_parent,
pov_hash: pov_hash_b,
erasure_root: make_erasure_root(&test_state, pov_block_b.clone()),
@@ -643,10 +643,8 @@ fn reputation_verification() {
)
) => {
let index = candidates2.iter().enumerate().find(|x| { x.1.hash() == candidate_hash }).map(|x| x.0).unwrap();
expected = dbg!(candidates2.swap_remove(index).hash());
tx.send(
i == 0
).unwrap();
expected = candidates2.swap_remove(index).hash();
tx.send(i == 0).unwrap();
}
);
@@ -762,6 +760,23 @@ fn reputation_verification() {
)
.await;
assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendValidationMessage(
peers,
protocol_v1::ValidationProtocol::AvailabilityDistribution(
protocol_v1::AvailabilityDistributionMessage::Chunk(hash, chunk),
),
)
) => {
assert_eq!(1, peers.len());
assert_eq!(peers[0], peer_a);
assert_eq!(candidates[0].hash(), hash);
assert_eq!(valid.erasure_chunk, chunk);
}
);
assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::NetworkBridge(
@@ -861,7 +876,7 @@ fn reputation_verification() {
{
// send another message
let valid2: AvailabilityGossipMessage = make_valid_availability_gossip(
let valid2 = make_valid_availability_gossip(
&test_state,
candidates[2].hash(),
1,
@@ -890,6 +905,102 @@ fn reputation_verification() {
}
);
}
{
// send another message
let valid = make_valid_availability_gossip(
&test_state,
candidates[1].hash(),
2,
pov_block_b.clone(),
);
// Make peer a and b listen on `current`
overseer_send(
&mut virtual_overseer,
AvailabilityDistributionMessage::NetworkBridgeUpdateV1(
NetworkBridgeEvent::PeerViewChange(peer_a.clone(), view![current]),
),
)
.await;
overseer_send(
&mut virtual_overseer,
AvailabilityDistributionMessage::NetworkBridgeUpdateV1(
NetworkBridgeEvent::PeerViewChange(peer_b.clone(), view![current]),
),
)
.await;
overseer_send(
&mut virtual_overseer,
AvailabilityDistributionMessage::NetworkBridgeUpdateV1(
NetworkBridgeEvent::PeerMessage(
peer_a.clone(),
chunk_protocol_message(valid.clone()),
),
),
)
.await;
assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(
peer,
rep
)
) => {
assert_eq!(peer, peer_a);
assert_eq!(rep, BENEFIT_VALID_MESSAGE_FIRST);
}
);
assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendValidationMessage(
peers,
protocol_v1::ValidationProtocol::AvailabilityDistribution(
protocol_v1::AvailabilityDistributionMessage::Chunk(hash, chunk),
),
)
) => {
assert_eq!(1, peers.len());
assert_eq!(peers[0], peer_b);
assert_eq!(candidates[1].hash(), hash);
assert_eq!(valid.erasure_chunk, chunk);
}
);
// Let B send the same message
overseer_send(
&mut virtual_overseer,
AvailabilityDistributionMessage::NetworkBridgeUpdateV1(
NetworkBridgeEvent::PeerMessage(
peer_b.clone(),
chunk_protocol_message(valid.clone()),
),
),
)
.await;
assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(
peer,
rep
)
) => {
assert_eq!(peer, peer_b);
assert_eq!(rep, BENEFIT_VALID_MESSAGE);
}
);
// There shouldn't be any other message.
assert!(virtual_overseer.recv().timeout(TIMEOUT).await.is_none());
}
});
}