hbbft/tests/queueing_honey_badger.rs

309 lines
12 KiB
Rust
Raw Normal View History

#![deny(unused_must_use)]
//! Network tests for Queueing Honey Badger.
use std::collections::BTreeSet;
use std::sync::Arc;
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
use hbbft::dynamic_honey_badger::{DynamicHoneyBadger, JoinPlan};
use hbbft::queueing_honey_badger::{Change, ChangeState, Input, QueueingHoneyBadger};
2018-10-25 08:07:52 -07:00
use hbbft::sender_queue::{Message, SenderQueue, Step};
use hbbft::util;
use hbbft_testing::adversary::{Adversary, NodeOrderAdversary, ReorderingAdversary};
use hbbft_testing::proptest::{gen_seed, TestRng, TestRngSeed};
use hbbft_testing::{NetBuilder, NewNodeInfo, Node, VirtualNet};
use log::info;
use proptest::{prelude::ProptestConfig, proptest};
use rand::{Rng, SeedableRng};
type NodeId = u16;
type QHB = QueueingHoneyBadger<usize, NodeId, Vec<usize>>;
type SQ = SenderQueue<QHB>;
// Send the second half of the transactions to the specified node.
fn input_second_half<A>(
net: &mut VirtualNet<SQ, A>,
id: NodeId,
num_txs: usize,
mut rng: &mut TestRng,
) where
A: Adversary<SQ>,
{
for tx in (num_txs / 2)..num_txs {
let _ = net.send_input(id, Input::User(tx), &mut rng);
}
}
/// Proposes `num_txs` values and expects nodes to output and order them.
fn test_queueing_honey_badger<A>(mut net: VirtualNet<SQ, A>, num_txs: usize, mut rng: &mut TestRng)
where
A: Adversary<SQ>,
{
// Make two copies of all public keys.
let pub_keys_add = net
.correct_nodes()
.next()
.expect("At least one correct node needs to exist")
.algorithm()
.algo()
.dyn_hb()
.public_keys()
.clone();
let mut pub_keys_rm = pub_keys_add.clone();
// Get the first correct node id as candidate for removal/re-adding.
let first_correct_node = *net.correct_nodes().next().unwrap().id();
// Remove the first correct node, which is to be removed.
Arc::make_mut(&mut pub_keys_rm).remove(&first_correct_node);
// Broadcast public keys of all nodes except for the node to be removed.
let _ = net.broadcast_input(
&Input::Change(Change::NodeChange(pub_keys_rm.clone())),
&mut rng,
);
// Broadcast the first half of the transactions.
for tx in 0..(num_txs / 2) {
let _ = net.broadcast_input(&Input::User(tx), &mut rng);
}
// Closure for checking the output of a node for ChangeSet completion containing
// all nodes but the removed node.
let has_remove = |node: &Node<SQ>| {
node.outputs().iter().any(|batch| match batch.change() {
ChangeState::Complete(Change::NodeChange(pub_keys)) => pub_keys == &pub_keys_rm,
_ => false,
2018-10-23 22:18:18 -07:00
})
};
// Closure for checking the output of a node for ChangeSet completion containing
// all nodes, including the previously removed node.
let has_add = |node: &Node<SQ>| {
node.outputs().iter().any(|batch| match batch.change() {
ChangeState::Complete(Change::NodeChange(pub_keys)) => pub_keys == &pub_keys_add,
_ => false,
})
};
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
// Returns `true` if the node has not output all changes or transactions yet.
let node_busy = |node: &Node<SQ>| {
!has_remove(node) || !has_add(node) || !node.algorithm().algo().queue().is_empty()
};
// All nodes await removal.
let mut awaiting_removal: BTreeSet<_> = net.correct_nodes().map(|node| *node.id()).collect();
// All nodes but the removed node await addition.
let mut awaiting_addition: BTreeSet<_> = net
.correct_nodes()
.map(|node| *node.id())
.filter(|id| *id != first_correct_node)
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
.collect();
// All, including the previously removed node, await the second half of transactions.
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
let mut awaiting_second_half: BTreeSet<_> = awaiting_removal.clone();
// Whether the first correct node was rejoined as a validator.
let mut rejoined_first_correct = false;
// The removed first correct node which is to be restarted as soon as all remaining
// validators agreed to add it back.
let mut saved_first_correct: Option<Node<SQ>> = None;
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
// Handle messages in random order until all nodes have output all transactions.
while net.correct_nodes().any(node_busy) {
let stepped_id = net.crank_expect(&mut rng).0;
if awaiting_removal.contains(&stepped_id) && has_remove(&net.get(stepped_id).unwrap()) {
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
awaiting_removal.remove(&stepped_id);
info!(
"{:?} has finished waiting for node removal; still waiting: {:?}",
stepped_id, awaiting_removal
);
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
if awaiting_removal.is_empty() {
info!("Removing first correct node from the test network");
saved_first_correct = net.remove_node(&first_correct_node);
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
}
// Vote to add the first correct node back.
if stepped_id != first_correct_node {
let _ = net.send_input(
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
stepped_id,
Input::Change(Change::NodeChange(pub_keys_add.clone())),
rng,
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
);
info!(
"Input the vote to add the first correct node into {:?} with netinfo {:?}",
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
stepped_id,
net.get(stepped_id).unwrap().algorithm().algo().netinfo()
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
);
}
}
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
if awaiting_removal.is_empty() && awaiting_addition.contains(&stepped_id) {
// If the stepped node started voting to add the first correct node back,
// take a note of that and rejoin it.
if let Some(join_plan) =
net.get(stepped_id)
.unwrap()
.outputs()
.iter()
.find_map(|batch| match batch.change() {
ChangeState::InProgress(Change::NodeChange(pub_keys))
if pub_keys == &pub_keys_add =>
{
batch.join_plan()
}
_ => None,
})
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
{
awaiting_addition.remove(&stepped_id);
info!(
"{:?} has finished waiting for node addition; still waiting: {:?}",
stepped_id, awaiting_addition
);
if awaiting_addition.is_empty() && !rejoined_first_correct {
let node = saved_first_correct
.take()
.expect("first correct node wasn't saved");
let step = restart_node_for_add(&mut net, node, join_plan, &mut rng);
net.process_step(first_correct_node, &step)
.expect("processing a step failed");
rejoined_first_correct = true;
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
}
}
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
}
if rejoined_first_correct && awaiting_second_half.contains(&stepped_id) {
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
// Input the second half of user transactions into the stepped node.
input_second_half(&mut net, stepped_id, num_txs, &mut rng);
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
awaiting_second_half.remove(&stepped_id);
}
}
let node_1 = net
.correct_nodes()
.nth(1)
.expect("second correct node is missing");
net.verify_batches(node_1);
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
}
/// Restarts specified node on the test network for adding it back as a validator.
fn restart_node_for_add<R, A>(
net: &mut VirtualNet<SQ, A>,
mut node: Node<SQ>,
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
join_plan: JoinPlan<NodeId>,
mut rng: &mut R,
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
) -> Step<QueueingHoneyBadger<usize, NodeId, Vec<usize>>>
where
R: rand::Rng,
A: Adversary<SQ>,
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
{
let our_id = *node.id();
println!("Restarting node {} with {:?}", node.id(), join_plan);
// TODO: When an observer node is added to the network, it should also be added to peer_ids.
let peer_ids: Vec<_> = net
.nodes()
.map(Node::id)
.filter(|id| *id != node.id())
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
.cloned()
.collect();
let secret_key = node.algorithm().algo().dyn_hb().secret_key().clone();
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
let (qhb, qhb_step) =
QueueingHoneyBadger::builder_joining(our_id, secret_key, join_plan, &mut rng)
2018-12-11 03:59:54 -08:00
.and_then(|builder| builder.batch_size(3).build(&mut rng))
.expect("failed to rebuild the node with a join plan");
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
let (sq, mut sq_step) = SenderQueue::builder(qhb, peer_ids.into_iter()).build(our_id);
*node.algorithm_mut() = sq;
2018-12-18 07:17:46 -08:00
sq_step.extend(qhb_step.map(|output| output, |fault| fault, Message::from));
net.insert_node(node);
Remove peers from sender queue (#352) * impl. old validator removal from sender queue peer list * provided current validators for sender queue peer removal * renamed validators as nodes in the sender queue * Revert "renamed validators as nodes in the sender queue" This reverts commit 78e1e1569d5f624c469bf752a5bf874b434a61d2. * cleaned up the SQ builder and moved removal of old validators to triggers * computing participant transitions from batches in the sender queue * added a missing comment * removing old validators as soon as all messages are delivered up to the last epoch * review comments * rejoined Node 0 in the old DHB test * DHB test uses the first step of the DHB algorithm on the restarted node * changed test batch verification to account for node 0 removal * updated net_dynamic_hb test to cope with the removal of node 0 * relaxed verification of batches to only check inclusion of node 0 transactions * corrected test state transitions in DHB and QHB tests * added a builder function for a joining QHB * rejoin the pivot node instead of node 0 * changed VirtualNet::verify_batches to take a full node as an argument * corrected a variable name * correction: use the pivot node ID instead of indices * corrected the pivot node ID * simplified a find * simplified a conditional statement * corrected the inference of expected output in verify_batches * WIP on DHB and QHB tests; VirtualNet::verify_batches made more general * readded node 0 in the DHB test when InProgress change is output * allowed node 0 to miss a few batches while it is removed in the QHB test * edition and rebase fixes * refactored the use of process_step * added VirtualNet functionality of node insertion and removal * restarting the pivot node after all validators add it as peer * clippy lints in net_dynamic_hb * added observer in the QHB test; removed the DHB TestNetwork test * fixed rng usage in the QHB test * check output length when verifying batches; comment correction
2018-12-17 05:27:46 -08:00
sq_step
}
// Allow passing `netinfo` by value. `TestNetwork` expects this function signature.
#[allow(clippy::needless_pass_by_value)]
fn new_queueing_hb(node_info: NewNodeInfo<SQ>, seed: TestRngSeed) -> (SQ, Step<QHB>) {
let mut rng: TestRng = TestRng::from_seed(seed);
let peer_ids = node_info.netinfo.other_ids().cloned();
let netinfo = node_info.netinfo.clone();
let dhb =
DynamicHoneyBadger::builder().build(netinfo, node_info.secret_key, node_info.pub_keys);
OsRng / external RNG Refactoring (#357) * Use `OsRng` in place of `thread_rng`. This changes the defaults of any builder by instantiating an `OsRng` instead of a `thread_rng`, the former being much more secure than the latter. Additionally, all the unit tests that still instantiate RNGs manually used `OsRng`s as well; while there is no actual need for this level of security in tests, the performance overhead is very small and random number generation complexity has such a small impact on these tests that the convenience of being able to ban `thread_rng` from the codebase altogether, setting a good example and avoid issues when refactoring later greatly outweigh the negatives. * Instead of storing random number generators in the various consensus algorithm instances, pass them in from the outside whenever they are needed. This changes a large amount of interfaces (and in this commit is only partially done, since `DistAlgorithm` needs to be fundamentally altered as well. It also obsoletes parts of the `util` module. * Added an `R: Rng` type parameter to both methods of `DistAlgorithm`, forcing callers to pass in their own Rngs. * Fixed documentation grammar and spelling in some of the altered interfaces due to RNG refactoring. * Move `rng` argument to the end of the argument for most functions. Also includes a reformatting due to Rust 1.30. * Updated tests, accomodate `rng`-API changes. * Fixed remaining compilation issues with new RNG code. * Fix illegal `self` import outside curly braces. * Cleaned up comments and fixed broken definition of `broadcast_input`. * Updated existing test cases to properly work with static dispatch randomness. * Do not use boxed `Rng`s for key generation in test networks. * Use the passed-in `Rng` in `ReorderingAdversary`, instead of storing a boxed one. * Fixed clippy lints after refactoring. * Removed some no-longer necessary manual `fmt::Debug` implementations in test framework. * Use `OsRng` even in tests in `binary_agreement_mitm`. * Use a proper deterministic RNG in tests `binary_agreement_mitm`. * Refactor `examples/simulation.rs` by not using `ThreadRng`, passing generic `Rng` parameters throughout and using a type alias instead of a newtype as the `Transaction`. * Remove `thread_rng` use from `examples/node.rs`. * Explicitly construct `InternalContrib` in `DynamicHoneyBadger::propose`. * Fixed typo in description of `DistAlgorithm` trait.
2018-12-14 04:51:09 -08:00
let (qhb, qhb_step) = QueueingHoneyBadger::builder(dhb)
.batch_size(3)
.build(&mut rng)
.expect("failed to build QueueingHoneyBadger");
let our_id = *node_info.netinfo.our_id();
2018-10-25 08:07:52 -07:00
let (sq, mut step) = SenderQueue::builder(qhb, peer_ids).build(our_id);
2018-12-18 07:17:46 -08:00
let output = step.extend_with(qhb_step, |fault| fault, Message::from);
assert!(output.is_empty());
2018-10-25 08:07:52 -07:00
(sq, step)
}
fn test_queueing_honey_badger_different_sizes<A, F>(
new_adversary: F,
num_txs: usize,
seed: TestRngSeed,
) where
A: Adversary<SQ>,
F: Fn() -> A,
{
// This returns an error in all but the first test.
let _ = env_logger::try_init();
let mut rng: TestRng = TestRng::from_seed(seed);
2020-03-11 03:53:31 -07:00
let sizes = vec![2, 3, 5, rng.gen_range(6, 10)];
for size in sizes {
// The test is removing one correct node, so we allow fewer faulty ones.
let num_adv_nodes = util::max_faulty(size - 1);
let num_good_nodes = size - num_adv_nodes;
info!(
"Network size: {} good nodes, {} faulty nodes",
num_good_nodes, num_adv_nodes
);
let (net, _) = NetBuilder::new(0..size as u16)
.num_faulty(num_adv_nodes)
.message_limit(20_000 * size)
.no_time_limit()
.adversary(new_adversary())
.using_step(move |node_info: NewNodeInfo<_>| {
// Note: The "seed" variable is implicitly copied by the move closure.
// The "Copy" trait is *not* implemented for TestRng, which additionally
// needs to be mutable, while we are in a function which captures immutably.
// To avoid convoluted clone/borrow constructs we pass a TestRngSeed
// rather than a TestRng instance.
new_queueing_hb(node_info, seed)
})
.build(&mut rng)
.expect("Could not construct test network.");
test_queueing_honey_badger(net, num_txs, &mut rng);
}
}
proptest! {
#![proptest_config(ProptestConfig {
cases: 1, .. ProptestConfig::default()
})]
#[test]
#[allow(clippy::unnecessary_operation)]
fn test_queueing_honey_badger_random_delivery_silent(seed in gen_seed()) {
do_test_queueing_honey_badger_random_delivery_silent(seed)
}
#[test]
#[allow(clippy::unnecessary_operation)]
fn test_queueing_honey_badger_first_delivery_silent(seed in gen_seed()) {
do_test_queueing_honey_badger_first_delivery_silent(seed)
}
}
fn do_test_queueing_honey_badger_random_delivery_silent(seed: TestRngSeed) {
test_queueing_honey_badger_different_sizes(ReorderingAdversary::new, 30, seed);
}
fn do_test_queueing_honey_badger_first_delivery_silent(seed: TestRngSeed) {
test_queueing_honey_badger_different_sizes(NodeOrderAdversary::new, 30, seed);
}