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
|
/// A structure representing the context of a faulty node. This structure
|
||||||
/// describes which node is faulty (`node_id`) and which faulty behavior
|
/// describes which node is faulty (`node_id`) and which faulty behavior
|
||||||
/// that the node exhibited ('kind').
|
/// that the node exhibited ('kind').
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Fault<N> {
|
pub struct Fault<N> {
|
||||||
pub node_id: N,
|
pub node_id: N,
|
||||||
pub kind: FaultKind,
|
pub kind: FaultKind,
|
||||||
|
|
|
@ -26,7 +26,7 @@ use threshold_crypto as crypto;
|
||||||
|
|
||||||
use hbbft::dynamic_honey_badger::Batch;
|
use hbbft::dynamic_honey_badger::Batch;
|
||||||
use hbbft::util::SubRng;
|
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;
|
use try_some;
|
||||||
|
|
||||||
|
@ -73,6 +73,8 @@ pub struct Node<D: DistAlgorithm> {
|
||||||
is_faulty: bool,
|
is_faulty: bool,
|
||||||
/// Captured algorithm outputs, in order.
|
/// Captured algorithm outputs, in order.
|
||||||
outputs: Vec<D::Output>,
|
outputs: Vec<D::Output>,
|
||||||
|
/// Collected fault log.
|
||||||
|
faults: Vec<Fault<D::NodeId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D> fmt::Debug for Node<D>
|
impl<D> fmt::Debug for Node<D>
|
||||||
|
@ -96,6 +98,7 @@ impl<D: DistAlgorithm> Node<D> {
|
||||||
algorithm,
|
algorithm,
|
||||||
is_faulty,
|
is_faulty,
|
||||||
outputs: Vec::new(),
|
outputs: Vec::new(),
|
||||||
|
faults: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +135,23 @@ impl<D: DistAlgorithm> Node<D> {
|
||||||
pub fn outputs(&self) -> &[D::Output] {
|
pub fn outputs(&self) -> &[D::Output] {
|
||||||
self.outputs.as_slice()
|
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.
|
/// 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
|
nodes
|
||||||
.get_mut(&sender)
|
.get_mut(&sender)
|
||||||
.expect("Trying to process a step with non-existing node ID")
|
.expect("Trying to process a step with non-existing node ID")
|
||||||
.outputs
|
.store_step(step);
|
||||||
.extend(step.output.iter().cloned());
|
// 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
|
message_count
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue