Added a test for expected participants when receiving a batch from a correct node (#355)

* test expected participants when receiving a batch from a correct node

* restrict the batch participant check to correct participants

* check only for the absence of unexpected batch participants

* check the minimum number of contributors for each batch

* corrected the minimum number of batch contributions

* removed an irrelevant FIXME

* added an equivalence check for batches output in the same epoch

* comment correction
This commit is contained in:
Vladimir Komendantskiy 2018-12-11 07:28:27 +00:00 committed by GitHub
parent 99d01bf428
commit f297d84514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 1 deletions

View File

@ -165,11 +165,50 @@ fn do_drop_and_readd(cfg: TestConfig) {
.correct_nodes()
.map(|n| (*n.id(), (0..10).collect()))
.collect();
let mut received_batches: collections::BTreeMap<u64, _> = collections::BTreeMap::new();
// Run the network:
loop {
let (node_id, step) = net.crank_expect();
if !net[node_id].is_faulty() {
for batch in &step.output {
// Check that correct nodes don't output different batches for the same epoch.
if let Some(b) = received_batches.insert(batch.epoch(), batch.clone()) {
assert!(
batch.public_eq(&b),
"A batch of node {} doesn't match a previous batch for the same epoch {}",
node_id,
batch.epoch()
);
}
let expected_participants: Vec<_> = if awaiting_removal.contains(&node_id) {
// The node hasn't removed the pivot node yet.
pub_keys_add.keys()
} else if awaiting_addition.contains(&node_id) {
// The node has removed the pivot node but hasn't added it back yet.
pub_keys_rm.keys()
} else {
// The node has added the pivot node back.
pub_keys_add.keys()
}.collect();
assert!(
batch.contributions().count() * 3 > expected_participants.len() * 2,
"The batch contains less than N - f contributions: {:?}",
batch
);
// Verify that only contributions from expected participants can be present in the
// batch.
let batch_participants: Vec<_> = batch.contributions().map(|(id, _)| id).collect();
assert!(
batch_participants
.iter()
.all(|id| expected_participants.contains(id)),
"The batch at node {} contains a contribution from an unexpected participant: {:?}",
node_id,
batch
);
}
}
for change in step.output.iter().map(|output| output.change()) {
match change {
ChangeState::Complete(Change::NodeChange(ref pub_keys))