diff --git a/src/fault_log.rs b/src/fault_log.rs index 050b558..1473fa9 100644 --- a/src/fault_log.rs +++ b/src/fault_log.rs @@ -82,7 +82,7 @@ pub enum FaultKind { /// A structure representing the context of a faulty node. This structure /// describes which node is faulty (`node_id`) and which faulty behavior /// that the node exhibited ('kind'). -#[derive(Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub struct Fault { pub node_id: N, pub kind: FaultKind, diff --git a/tests/net/mod.rs b/tests/net/mod.rs index 7ac233c..b101a8d 100644 --- a/tests/net/mod.rs +++ b/tests/net/mod.rs @@ -26,7 +26,7 @@ use threshold_crypto as crypto; use hbbft::dynamic_honey_badger::Batch; use hbbft::util::SubRng; -use hbbft::{self, Contribution, DaStep, DistAlgorithm, NetworkInfo, NodeIdT, Step}; +use hbbft::{self, Contribution, DaStep, DistAlgorithm, Fault, NetworkInfo, NodeIdT, Step}; use try_some; @@ -73,6 +73,8 @@ pub struct Node { is_faulty: bool, /// Captured algorithm outputs, in order. outputs: Vec, + /// Collected fault log. + faults: Vec>, } impl fmt::Debug for Node @@ -96,6 +98,7 @@ impl Node { algorithm, is_faulty, outputs: Vec::new(), + faults: Vec::new(), } } @@ -132,6 +135,23 @@ impl Node { pub fn outputs(&self) -> &[D::Output] { self.outputs.as_slice() } + + /// List faults so far. + /// + /// All faults are collected for reference purposes. + #[inline] + pub fn faults(&self) -> &[Fault] { + self.faults.as_slice() + } + + /// Collects all outputs and faults (not required for network operation) for user convenience. + fn store_step(&mut self, step: &DaStep) + where + D::Output: Clone, + { + self.outputs.extend(step.output.iter().cloned()); + self.faults.extend(step.fault_log.0.iter().cloned()); + } } /// A network message on the virtual network. @@ -244,12 +264,16 @@ where } } - // Collect all outputs (not required for network operation) as a convenience for the user. nodes .get_mut(&sender) .expect("Trying to process a step with non-existing node ID") - .outputs - .extend(step.output.iter().cloned()); + .store_step(step); + // Verify that no correct node is reported as faulty. + for fault in &step.fault_log.0 { + if nodes.contains_key(&fault.node_id) { + panic!("Unexpected fault: {:?}", fault); + } + } message_count }