mirror of https://github.com/poanetwork/hbbft.git
added fault checking in the net framework
This commit is contained in:
parent
d912e3368e
commit
15bb2488eb
|
@ -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<N> {
|
||||
pub node_id: N,
|
||||
pub kind: FaultKind,
|
||||
|
|
|
@ -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<D: DistAlgorithm> {
|
|||
is_faulty: bool,
|
||||
/// Captured algorithm outputs, in order.
|
||||
outputs: Vec<D::Output>,
|
||||
/// Collected fault log.
|
||||
faults: Vec<Fault<D::NodeId>>,
|
||||
}
|
||||
|
||||
impl<D> fmt::Debug for Node<D>
|
||||
|
@ -96,6 +98,7 @@ impl<D: DistAlgorithm> Node<D> {
|
|||
algorithm,
|
||||
is_faulty,
|
||||
outputs: Vec::new(),
|
||||
faults: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,6 +135,23 @@ impl<D: DistAlgorithm> Node<D> {
|
|||
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<D::NodeId>] {
|
||||
self.faults.as_slice()
|
||||
}
|
||||
|
||||
/// Collects all outputs and faults (not required for network operation) for user convenience.
|
||||
fn store_step(&mut self, step: &DaStep<D>)
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue