From 362587fed55a4d8828e135f7bfeaf9bbfdc31c68 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Tue, 8 Jan 2019 09:30:37 +0100 Subject: [PATCH] Rename DistAlgorithm to ConsensusProtocol. --- examples/network/node.rs | 2 +- examples/simulation.rs | 20 +++--- src/binary_agreement/binary_agreement.rs | 6 +- src/broadcast/broadcast.rs | 6 +- .../dynamic_honey_badger.rs | 4 +- src/dynamic_honey_badger/mod.rs | 2 +- src/fault_log.rs | 2 +- src/honey_badger/honey_badger.rs | 6 +- src/lib.rs | 2 +- src/queueing_honey_badger/mod.rs | 4 +- src/sender_queue/dynamic_honey_badger.rs | 8 +-- src/sender_queue/honey_badger.rs | 4 +- src/sender_queue/mod.rs | 58 ++++++++-------- src/sender_queue/queueing_honey_badger.rs | 8 +-- src/subset/subset.rs | 4 +- src/threshold_decrypt.rs | 6 +- src/threshold_sign.rs | 6 +- src/traits.rs | 22 +++--- tests/README.md | 2 +- tests/binary_agreement.rs | 2 +- tests/binary_agreement_mitm.rs | 6 +- tests/broadcast.rs | 2 +- tests/honey_badger.rs | 4 +- tests/net/adversary.rs | 34 +++++----- tests/net/err.rs | 20 +++--- tests/net/mod.rs | 68 +++++++++---------- tests/network/mod.rs | 40 +++++------ 27 files changed, 174 insertions(+), 174 deletions(-) diff --git a/examples/network/node.rs b/examples/network/node.rs index 8922c2e7..5e71324e 100644 --- a/examples/network/node.rs +++ b/examples/network/node.rs @@ -46,7 +46,7 @@ use crate::network::messaging::Messaging; use crate::network::{commst, connection}; use hbbft::broadcast::{Broadcast, Message}; use hbbft::crypto::{poly::Poly, SecretKey, SecretKeySet}; -use hbbft::{DistAlgorithm, NetworkInfo, SourcedMessage}; +use hbbft::{ConsensusProtocol, NetworkInfo, SourcedMessage}; /// This is a structure to start a consensus node. pub struct Node { diff --git a/examples/simulation.rs b/examples/simulation.rs index 21ea313e..fea1e9a8 100644 --- a/examples/simulation.rs +++ b/examples/simulation.rs @@ -15,7 +15,7 @@ use signifix::{metric, TryFrom}; use hbbft::dynamic_honey_badger::DynamicHoneyBadger; use hbbft::queueing_honey_badger::{Batch, QueueingHoneyBadger}; use hbbft::sender_queue::{Message, SenderQueue}; -use hbbft::{DaStep, DistAlgorithm, NetworkInfo, Step, Target}; +use hbbft::{ConsensusProtocol, CpStep, NetworkInfo, Step, Target}; const VERSION: &str = env!("CARGO_PKG_VERSION"); const USAGE: &str = " @@ -60,14 +60,14 @@ type Transaction = Vec; /// A serialized message with a sender and the timestamp of arrival. #[derive(Eq, PartialEq, Debug)] -struct TimestampedMessage { +struct TimestampedMessage { time: Duration, sender_id: D::NodeId, target: Target, message: Vec, } -impl Clone for TimestampedMessage +impl Clone for TimestampedMessage where D::Message: Clone, { @@ -95,7 +95,7 @@ pub struct HwQuality { } /// A "node" running an instance of the algorithm `D`. -pub struct TestNode { +pub struct TestNode { /// This node's own ID. id: D::NodeId, /// The instance of the broadcast algorithm. @@ -118,14 +118,14 @@ pub struct TestNode { hw_quality: HwQuality, } -type TestNodeStepResult = DaStep; +type TestNodeStepResult = CpStep; -impl TestNode +impl TestNode where D::Message: Serialize + DeserializeOwned, { /// Creates a new test node with the given broadcast instance. - fn new((algo, step): (D, DaStep), hw_quality: HwQuality) -> TestNode { + fn new((algo, step): (D, CpStep), hw_quality: HwQuality) -> TestNode { let out_queue = step .messages .into_iter() @@ -231,11 +231,11 @@ where } /// A collection of `TestNode`s representing a network. -pub struct TestNetwork { +pub struct TestNetwork { nodes: BTreeMap>, } -impl> TestNetwork +impl> TestNetwork where D::Message: Serialize + DeserializeOwned + Clone, { @@ -248,7 +248,7 @@ where rng: &mut R, ) -> TestNetwork where - F: Fn(NetworkInfo, &mut R) -> (D, DaStep), + F: Fn(NetworkInfo, &mut R) -> (D, CpStep), { let node_ids = (0..(good_num + adv_num)).map(NodeId); let netinfos = diff --git a/src/binary_agreement/binary_agreement.rs b/src/binary_agreement/binary_agreement.rs index 77c1e61d..d4168f40 100644 --- a/src/binary_agreement/binary_agreement.rs +++ b/src/binary_agreement/binary_agreement.rs @@ -13,7 +13,7 @@ use super::sbv_broadcast::{self, Message as SbvMessage, SbvBroadcast}; use super::{Error, FaultKind, Message, MessageContent, Result, Step}; use crate::fault_log::Fault; use crate::threshold_sign::{self, Message as TsMessage, ThresholdSign}; -use crate::{DistAlgorithm, NetworkInfo, NodeIdT, SessionIdT, Target}; +use crate::{ConsensusProtocol, NetworkInfo, NodeIdT, SessionIdT, Target}; /// The state of the current epoch's coin. In some epochs this is fixed, in others it starts /// with in `InProgress`. @@ -158,7 +158,7 @@ pub struct BinaryAgreement { /// The estimate of the decision value in the current epoch. estimated: Option, /// A permanent, latching copy of the output value. This copy is required because `output` can - /// be consumed using `DistAlgorithm::next_output` immediately after the instance finishing to + /// be consumed using `ConsensusProtocol::next_output` immediately after the instance finishing to /// handle a message, in which case it would otherwise be unknown whether the output value was /// ever there at all. While the output value will still be required in a later epoch to decide /// the termination state. @@ -171,7 +171,7 @@ pub struct BinaryAgreement { coin_state: CoinState, } -impl DistAlgorithm for BinaryAgreement { +impl ConsensusProtocol for BinaryAgreement { type NodeId = N; type Input = bool; type Output = bool; diff --git a/src/broadcast/broadcast.rs b/src/broadcast/broadcast.rs index f171fdee..3ed9c14b 100644 --- a/src/broadcast/broadcast.rs +++ b/src/broadcast/broadcast.rs @@ -13,7 +13,7 @@ use super::merkle::{Digest, MerkleTree, Proof}; use super::message::HexProof; use super::{Error, FaultKind, Message, Result}; use crate::fault_log::Fault; -use crate::{DistAlgorithm, NetworkInfo, NodeIdT, Target}; +use crate::{ConsensusProtocol, NetworkInfo, NodeIdT, Target}; type RseResult = result::Result; @@ -41,9 +41,9 @@ pub struct Broadcast { } /// A `Broadcast` step, containing at most one output. -pub type Step = crate::DaStep>; +pub type Step = crate::CpStep>; -impl DistAlgorithm for Broadcast { +impl ConsensusProtocol for Broadcast { type NodeId = N; type Input = Vec; type Output = Self::Input; diff --git a/src/dynamic_honey_badger/dynamic_honey_badger.rs b/src/dynamic_honey_badger/dynamic_honey_badger.rs index 2978c3d6..4dbd64de 100644 --- a/src/dynamic_honey_badger/dynamic_honey_badger.rs +++ b/src/dynamic_honey_badger/dynamic_honey_badger.rs @@ -20,7 +20,7 @@ use crate::honey_badger::{self, HoneyBadger, Message as HbMessage}; use crate::sync_key_gen::{Ack, AckOutcome, Part, PartOutcome, SyncKeyGen}; use crate::util; -use crate::{Contribution, DistAlgorithm, Epoched, NetworkInfo, NodeIdT, Target}; +use crate::{ConsensusProtocol, Contribution, Epoched, NetworkInfo, NodeIdT, Target}; /// A Honey Badger instance that can handle adding and removing nodes. #[derive(Derivative)] @@ -42,7 +42,7 @@ pub struct DynamicHoneyBadger { pub(super) key_gen_state: Option>, } -impl DistAlgorithm for DynamicHoneyBadger +impl ConsensusProtocol for DynamicHoneyBadger where C: Contribution + Serialize + DeserializeOwned, N: NodeIdT + Serialize + DeserializeOwned, diff --git a/src/dynamic_honey_badger/mod.rs b/src/dynamic_honey_badger/mod.rs index 458df2f8..4ec1927e 100644 --- a/src/dynamic_honey_badger/mod.rs +++ b/src/dynamic_honey_badger/mod.rs @@ -89,7 +89,7 @@ pub use self::dynamic_honey_badger::DynamicHoneyBadger; pub use self::error::{Error, FaultKind, Result}; /// A `DynamicHoneyBadger` step, possibly containing multiple outputs. -pub type Step = crate::DaStep>; +pub type Step = crate::CpStep>; /// The user input for `DynamicHoneyBadger`. #[derive(Clone, Debug)] diff --git a/src/fault_log.rs b/src/fault_log.rs index 2f8c1a06..7d7a4b83 100644 --- a/src/fault_log.rs +++ b/src/fault_log.rs @@ -2,7 +2,7 @@ //! algorithm. //! //! Each algorithm can propogate their faulty node logs upwards to a calling algorithm via -//! `DistAlgorihm`'s `.handle_input()` and `.handle_message()` trait methods. +//! `ConsensusProtocol`'s `.handle_input()` and `.handle_message()` trait methods. pub use failure::Fail; diff --git a/src/honey_badger/honey_badger.rs b/src/honey_badger/honey_badger.rs index 24a78cd3..6bf52702 100644 --- a/src/honey_badger/honey_badger.rs +++ b/src/honey_badger/honey_badger.rs @@ -9,7 +9,7 @@ use serde_derive::{Deserialize, Serialize}; use super::epoch_state::EpochState; use super::{Batch, Error, FaultKind, HoneyBadgerBuilder, Message, Result}; -use crate::{Contribution, DistAlgorithm, Fault, NetworkInfo, NodeIdT}; +use crate::{ConsensusProtocol, Contribution, Fault, NetworkInfo, NodeIdT}; use super::Params; @@ -33,9 +33,9 @@ pub struct HoneyBadger { } /// A `HoneyBadger` step, possibly containing multiple outputs. -pub type Step = crate::DaStep>; +pub type Step = crate::CpStep>; -impl DistAlgorithm for HoneyBadger +impl ConsensusProtocol for HoneyBadger where C: Contribution + Serialize + DeserializeOwned, N: NodeIdT, diff --git a/src/lib.rs b/src/lib.rs index 7d3d8dee..ff4539fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -144,5 +144,5 @@ pub use crate::fault_log::{Fault, FaultLog}; pub use crate::messaging::{SourcedMessage, Target, TargetedMessage}; pub use crate::network_info::NetworkInfo; pub use crate::traits::{ - Contribution, DaStep, DistAlgorithm, Epoched, Message, NodeIdT, SessionIdT, Step, + ConsensusProtocol, Contribution, CpStep, Epoched, Message, NodeIdT, SessionIdT, Step, }; diff --git a/src/queueing_honey_badger/mod.rs b/src/queueing_honey_badger/mod.rs index a46c7d26..38561aa8 100644 --- a/src/queueing_honey_badger/mod.rs +++ b/src/queueing_honey_badger/mod.rs @@ -36,7 +36,7 @@ use crate::dynamic_honey_badger::{ self, Batch as DhbBatch, DynamicHoneyBadger, FaultKind, JoinPlan, Message, Step as DhbStep, }; use crate::transaction_queue::TransactionQueue; -use crate::{Contribution, DistAlgorithm, NetworkInfo, NodeIdT}; +use crate::{ConsensusProtocol, Contribution, NetworkInfo, NodeIdT}; pub use crate::dynamic_honey_badger::{Change, ChangeState, Input}; @@ -164,7 +164,7 @@ pub struct QueueingHoneyBadger { /// A `QueueingHoneyBadger` step, possibly containing multiple outputs. pub type Step = crate::Step, Batch, N, FaultKind>; -impl DistAlgorithm for QueueingHoneyBadger +impl ConsensusProtocol for QueueingHoneyBadger where T: Contribution + Serialize + DeserializeOwned + Clone, N: NodeIdT + Serialize + DeserializeOwned, diff --git a/src/sender_queue/dynamic_honey_badger.rs b/src/sender_queue/dynamic_honey_badger.rs index e14602f6..c2670e5b 100644 --- a/src/sender_queue/dynamic_honey_badger.rs +++ b/src/sender_queue/dynamic_honey_badger.rs @@ -8,10 +8,10 @@ use rand::Rng; use serde::{de::DeserializeOwned, Serialize}; use super::{ - Error, Message, SenderQueue, SenderQueueableDistAlgorithm, SenderQueueableMessage, + Error, Message, SenderQueue, SenderQueueableConsensusProtocol, SenderQueueableMessage, SenderQueueableOutput, }; -use crate::{Contribution, DaStep, NodeIdT}; +use crate::{Contribution, CpStep, NodeIdT}; use crate::dynamic_honey_badger::{ Batch, Change, ChangeState, DynamicHoneyBadger, Error as DhbError, JoinPlan, @@ -76,7 +76,7 @@ impl SenderQueueableMessage for DhbMessage { } } -impl SenderQueueableDistAlgorithm for DynamicHoneyBadger +impl SenderQueueableConsensusProtocol for DynamicHoneyBadger where C: Contribution + Serialize + DeserializeOwned, N: NodeIdT + Serialize + DeserializeOwned, @@ -86,7 +86,7 @@ where } } -type Result = result::Result>>, Error>; +type Result = result::Result>>, Error>; impl SenderQueue> where diff --git a/src/sender_queue/honey_badger.rs b/src/sender_queue/honey_badger.rs index e319072d..cf20d150 100644 --- a/src/sender_queue/honey_badger.rs +++ b/src/sender_queue/honey_badger.rs @@ -2,7 +2,7 @@ use std::collections::BTreeSet; use serde::{de::DeserializeOwned, Serialize}; -use super::{SenderQueueableDistAlgorithm, SenderQueueableMessage, SenderQueueableOutput}; +use super::{SenderQueueableConsensusProtocol, SenderQueueableMessage, SenderQueueableOutput}; use crate::honey_badger::{Batch, HoneyBadger, Message}; use crate::{Contribution, Epoched, NodeIdT}; @@ -48,7 +48,7 @@ where } } -impl SenderQueueableDistAlgorithm for HoneyBadger +impl SenderQueueableConsensusProtocol for HoneyBadger where C: Contribution + Serialize + DeserializeOwned, N: NodeIdT, diff --git a/src/sender_queue/mod.rs b/src/sender_queue/mod.rs index 8a7fca04..5f1ad959 100644 --- a/src/sender_queue/mod.rs +++ b/src/sender_queue/mod.rs @@ -1,6 +1,6 @@ //! # Sender queue //! -//! A sender queue allows a `DistAlgorithm` that outputs `Epoched` messages to buffer those outgoing +//! A sender queue allows a `ConsensusProtocol` that outputs `Epoched` messages to buffer those outgoing //! messages based on their epochs. A message is sent to its recipient only when the recipient's //! epoch matches the epoch of the message. Thus no queueing is required for incoming messages since //! any incoming messages with non-matching epochs can be safely discarded. @@ -18,7 +18,7 @@ use std::fmt::Debug; use log::debug; use crate::traits::EpochT; -use crate::{DaStep, DistAlgorithm, Epoched, NodeIdT, Target}; +use crate::{ConsensusProtocol, CpStep, Epoched, NodeIdT, Target}; pub use self::error::Error; pub use self::message::Message; @@ -61,20 +61,20 @@ where fn output_epoch(&self) -> E; } -/// A `DistAlgorithm` that can be wrapped by a sender queue. -pub trait SenderQueueableDistAlgorithm: Epoched + DistAlgorithm { - /// The maximum number of subsequent future epochs that the `DistAlgorithm` is allowed to handle +/// A `ConsensusProtocol` that can be wrapped by a sender queue. +pub trait SenderQueueableConsensusProtocol: Epoched + ConsensusProtocol { + /// The maximum number of subsequent future epochs that the `ConsensusProtocol` is allowed to handle /// messages for. fn max_future_epochs(&self) -> u64; } /// A map with outgoing messages, per epoch and per target node. pub type OutgoingQueue = BTreeMap< - ::NodeId, - BTreeMap<::Epoch, Vec<::Message>>, + ::NodeId, + BTreeMap<::Epoch, Vec<::Message>>, >; -/// An instance of `DistAlgorithm` wrapped with a queue of outgoing messages, that is, a sender +/// An instance of `ConsensusProtocol` wrapped with a queue of outgoing messages, that is, a sender /// queue. This wrapping ensures that the messages sent to remote instances lead to progress of the /// entire consensus network. In particular, messages to lagging remote nodes are queued and sent /// only when those nodes' epochs match the queued messages' epochs. Thus all nodes can handle @@ -83,9 +83,9 @@ pub type OutgoingQueue = BTreeMap< #[derive(Debug)] pub struct SenderQueue where - D: SenderQueueableDistAlgorithm, + D: SenderQueueableConsensusProtocol, { - /// The managed `DistAlgorithm` instance. + /// The managed `ConsensusProtocol` instance. algo: D, /// Our node ID. our_id: D::NodeId, @@ -114,11 +114,11 @@ where } /// A `SenderQueue` step. The output corresponds to the wrapped algorithm. -pub type Step = crate::DaStep>; +pub type Step = crate::CpStep>; -impl DistAlgorithm for SenderQueue +impl ConsensusProtocol for SenderQueue where - D: SenderQueueableDistAlgorithm + Debug, + D: SenderQueueableConsensusProtocol + Debug, D::Message: Clone + SenderQueueableMessage, D::NodeId: NodeIdT, D::Output: SenderQueueableOutput, @@ -134,7 +134,7 @@ where &mut self, input: Self::Input, rng: &mut R, - ) -> Result, Error> { + ) -> Result, Error> { self.handle_input(input, rng) } @@ -143,7 +143,7 @@ where sender_id: &D::NodeId, message: Self::Message, rng: &mut R, - ) -> Result, Error> { + ) -> Result, Error> { self.handle_message(sender_id, message, rng) } @@ -158,7 +158,7 @@ where impl SenderQueue where - D: SenderQueueableDistAlgorithm + Debug, + D: SenderQueueableConsensusProtocol + Debug, D::Message: Clone + SenderQueueableMessage, D::NodeId: NodeIdT, D::Output: SenderQueueableOutput, @@ -177,7 +177,7 @@ where &mut self, input: D::Input, rng: &mut R, - ) -> Result, Error> { + ) -> Result, Error> { if self.is_removed { return Ok(Step::::default()); } @@ -192,7 +192,7 @@ where sender_id: &D::NodeId, message: Message, rng: &mut R, - ) -> Result, Error> { + ) -> Result, Error> { if self.is_removed { return Ok(Step::::default()); } @@ -214,9 +214,9 @@ where /// Applies `f` to the wrapped algorithm and converts the step in the result to a sender queue /// step, deferring or dropping messages, where necessary. - fn apply(&mut self, f: F) -> Result, Error> + fn apply(&mut self, f: F) -> Result, Error> where - F: FnOnce(&mut D) -> Result, D::Error>, + F: FnOnce(&mut D) -> Result, D::Error>, { let mut step = f(&mut self.algo).map_err(Error::Apply)?; let mut sender_queue_step = self.update_epoch(&step); @@ -226,7 +226,7 @@ where } /// Handles an epoch start announcement. - fn handle_epoch_started(&mut self, sender_id: &D::NodeId, epoch: D::Epoch) -> DaStep { + fn handle_epoch_started(&mut self, sender_id: &D::NodeId, epoch: D::Epoch) -> CpStep { self.peer_epochs .entry(sender_id.clone()) .and_modify(|e| { @@ -243,9 +243,9 @@ where } /// Processes an announcement of a new epoch update received from a remote node. - fn process_new_epoch(&mut self, sender_id: &D::NodeId, epoch: D::Epoch) -> DaStep { + fn process_new_epoch(&mut self, sender_id: &D::NodeId, epoch: D::Epoch) -> CpStep { let queue = match self.outgoing_queue.get_mut(sender_id) { - None => return DaStep::::default(), + None => return CpStep::::default(), Some(queue) => queue, }; let earlier_keys: Vec<_> = queue @@ -268,12 +268,12 @@ where sender_id: &D::NodeId, content: D::Message, rng: &mut R, - ) -> Result, Error> { + ) -> Result, Error> { self.apply(|algo| algo.handle_message(sender_id, content, rng)) } /// Updates the current Honey Badger epoch. - fn update_epoch(&mut self, step: &DaStep) -> DaStep { + fn update_epoch(&mut self, step: &CpStep) -> CpStep { if step.output.is_empty() { return Step::::default(); } @@ -327,7 +327,7 @@ where /// decomposing a `Target::All` message into `Target::Node` messages and sending some of the /// resulting messages while placing onto the queue those remaining messages whose recipient is /// currently at an earlier epoch. - fn defer_messages(&mut self, step: &mut DaStep) { + fn defer_messages(&mut self, step: &mut CpStep) { let max_future_epochs = self.algo.max_future_epochs(); // Append the deferred messages onto the queues. for (id, message) in step.defer_messages(&self.peer_epochs, max_future_epochs) { @@ -397,7 +397,7 @@ where /// instance of `SenderQueue`. pub struct SenderQueueBuilder where - D: SenderQueueableDistAlgorithm, + D: SenderQueueableConsensusProtocol, { algo: D, peer_epochs: BTreeMap, @@ -405,7 +405,7 @@ where impl SenderQueueBuilder where - D: SenderQueueableDistAlgorithm + Debug, + D: SenderQueueableConsensusProtocol + Debug, D::Message: Clone + SenderQueueableMessage, D::NodeId: NodeIdT, D::Output: SenderQueueableOutput, @@ -428,7 +428,7 @@ where } /// Creates a new sender queue and returns the `Step` with the initial message. - pub fn build(self, our_id: D::NodeId) -> (SenderQueue, DaStep>) { + pub fn build(self, our_id: D::NodeId) -> (SenderQueue, CpStep>) { let epoch = self.algo.epoch(); let sq = SenderQueue { algo: self.algo, diff --git a/src/sender_queue/queueing_honey_badger.rs b/src/sender_queue/queueing_honey_badger.rs index 9a8e3ae8..8d915ad8 100644 --- a/src/sender_queue/queueing_honey_badger.rs +++ b/src/sender_queue/queueing_honey_badger.rs @@ -7,10 +7,10 @@ use rand::distributions::{Distribution, Standard}; use rand::Rng; use serde::{de::DeserializeOwned, Serialize}; -use super::{Error, SenderQueue, SenderQueueableDistAlgorithm}; +use super::{Error, SenderQueue, SenderQueueableConsensusProtocol}; use crate::queueing_honey_badger::{Change, Error as QhbError, QueueingHoneyBadger}; use crate::transaction_queue::TransactionQueue; -use crate::{Contribution, DaStep, Epoched, NodeIdT}; +use crate::{Contribution, CpStep, Epoched, NodeIdT}; impl Epoched for QueueingHoneyBadger where @@ -26,7 +26,7 @@ where } } -impl SenderQueueableDistAlgorithm for QueueingHoneyBadger +impl SenderQueueableConsensusProtocol for QueueingHoneyBadger where T: Contribution + Serialize + DeserializeOwned + Clone, N: NodeIdT + Serialize + DeserializeOwned, @@ -39,7 +39,7 @@ where } type Result = - result::Result>>, Error>; + result::Result>>, Error>; impl SenderQueue> where diff --git a/src/subset/subset.rs b/src/subset/subset.rs index 5c0fe04d..e2d02936 100644 --- a/src/subset/subset.rs +++ b/src/subset/subset.rs @@ -9,7 +9,7 @@ use serde_derive::Serialize; use super::proposal_state::{ProposalState, Step as ProposalStep}; use super::{Error, FaultKind, Message, MessageContent, Result}; -use crate::{util, DistAlgorithm, NetworkInfo, NodeIdT, SessionIdT}; +use crate::{util, ConsensusProtocol, NetworkInfo, NodeIdT, SessionIdT}; use rand::Rng; /// A `Subset` step, possibly containing several outputs. @@ -41,7 +41,7 @@ pub struct Subset { decided: bool, } -impl DistAlgorithm for Subset { +impl ConsensusProtocol for Subset { type NodeId = N; type Input = Vec; type Output = SubsetOutput; diff --git a/src/threshold_decrypt.rs b/src/threshold_decrypt.rs index e25f9d32..8aac0651 100644 --- a/src/threshold_decrypt.rs +++ b/src/threshold_decrypt.rs @@ -21,7 +21,7 @@ use rand_derive::Rand; use serde_derive::{Deserialize, Serialize}; use crate::fault_log::{self, Fault}; -use crate::{DistAlgorithm, NetworkInfo, NodeIdT, Target}; +use crate::{ConsensusProtocol, NetworkInfo, NodeIdT, Target}; /// A threshold decryption error. #[derive(Clone, Eq, PartialEq, Debug, Fail)] @@ -80,9 +80,9 @@ pub struct ThresholdDecrypt { } /// A `ThresholdDecrypt` step. It will contain at most one output. -pub type Step = crate::DaStep>; +pub type Step = crate::CpStep>; -impl DistAlgorithm for ThresholdDecrypt { +impl ConsensusProtocol for ThresholdDecrypt { type NodeId = N; type Input = (); type Output = Vec; diff --git a/src/threshold_sign.rs b/src/threshold_sign.rs index 7a1016fa..19b3861e 100644 --- a/src/threshold_sign.rs +++ b/src/threshold_sign.rs @@ -27,7 +27,7 @@ use rand_derive::Rand; use serde_derive::{Deserialize, Serialize}; use crate::fault_log::{Fault, FaultLog}; -use crate::{DistAlgorithm, NetworkInfo, NodeIdT, Target}; +use crate::{ConsensusProtocol, NetworkInfo, NodeIdT, Target}; /// A threshold signing error. #[derive(Clone, Eq, PartialEq, Debug, Fail)] @@ -89,9 +89,9 @@ pub struct ThresholdSign { } /// A step returned from `ThresholdSign`. It contains at most one output. -pub type Step = crate::DaStep>; +pub type Step = crate::CpStep>; -impl DistAlgorithm for ThresholdSign { +impl ConsensusProtocol for ThresholdSign { type NodeId = N; type Input = (); type Output = Signature; diff --git a/src/traits.rs b/src/traits.rs index 4de86f7b..b434fb99 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,4 +1,4 @@ -//! Common supertraits for distributed algorithms. +//! Common supertraits for consensus protocols. use std::collections::BTreeMap; use std::fmt::{Debug, Display}; @@ -21,7 +21,7 @@ impl Contribution for C where C: Eq + Debug + Hash + Send + Sync {} pub trait NodeIdT: Eq + Ord + Clone + Debug + Hash + Send + Sync {} impl NodeIdT for N where N: Eq + Ord + Clone + Debug + Hash + Send + Sync {} -/// A distributed algorithm fault. +/// A consensus protocol fault. pub trait FaultT: Clone + Debug + Fail + PartialEq {} impl FaultT for N where N: Clone + Debug + Fail + PartialEq {} @@ -230,11 +230,11 @@ pub trait Epoched { } /// An alias for the type of `Step` returned by `D`'s methods. -pub type DaStep = Step< - ::Message, - ::Output, - ::NodeId, - ::FaultKind, +pub type CpStep = Step< + ::Message, + ::Output, + ::NodeId, + ::FaultKind, >; impl<'i, M, O, N, F> Step @@ -290,11 +290,11 @@ where } } -/// A distributed algorithm that defines a message flow. +/// A consensus protocol that defines a message flow. /// /// Many algorithms require an RNG which must be supplied on each call. It is up to the caller to /// ensure that this random number generator is cryptographically secure. -pub trait DistAlgorithm: Send + Sync { +pub trait ConsensusProtocol: Send + Sync { /// Unique node identifier. type NodeId: NodeIdT; /// The input provided by the user. @@ -314,7 +314,7 @@ pub trait DistAlgorithm: Send + Sync { &mut self, input: Self::Input, rng: &mut R, - ) -> Result, Self::Error> + ) -> Result, Self::Error> where Self: Sized; @@ -324,7 +324,7 @@ pub trait DistAlgorithm: Send + Sync { sender_id: &Self::NodeId, message: Self::Message, rng: &mut R, - ) -> Result, Self::Error> + ) -> Result, Self::Error> where Self: Sized; diff --git a/tests/README.md b/tests/README.md index ccc7421f..2cf40de6 100644 --- a/tests/README.md +++ b/tests/README.md @@ -10,7 +10,7 @@ The new implementation offers many advantages, such as better abstractions for a ## VirtualNet -Core of most tests is the `net::VirtualNet` struct, which simulates a network of nodes all running an instance of a distributed algorithm. Messages sent by these nodes are queued by the network and dispatched each time the network is advancing one iteration, commonly referred to as being "cranked". Each time the network is cranked, a buffered message is delivered to its destination node and processed. +Core of most tests is the `net::VirtualNet` struct, which simulates a network of nodes all running an instance of a consensus protocol. Messages sent by these nodes are queued by the network and dispatched each time the network is advancing one iteration, commonly referred to as being "cranked". Each time the network is cranked, a buffered message is delivered to its destination node and processed. Virtual networks can also host an adversary that can affect faulty nodes (which are tracked automatically) or reorder queued messages. diff --git a/tests/binary_agreement.rs b/tests/binary_agreement.rs index 51bfbe54..0192930c 100644 --- a/tests/binary_agreement.rs +++ b/tests/binary_agreement.rs @@ -24,7 +24,7 @@ use proptest::{prelude::ProptestConfig, prop_compose, proptest, proptest_helper} use rand::{Rng, SeedableRng}; use hbbft::binary_agreement::BinaryAgreement; -use hbbft::DistAlgorithm; +use hbbft::ConsensusProtocol; use crate::net::adversary::{Adversary, ReorderingAdversary}; use crate::net::proptest::{gen_seed, NetworkDimension, TestRng, TestRngSeed}; diff --git a/tests/binary_agreement_mitm.rs b/tests/binary_agreement_mitm.rs index c0f70094..ff8e72f0 100644 --- a/tests/binary_agreement_mitm.rs +++ b/tests/binary_agreement_mitm.rs @@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex}; use hbbft::binary_agreement::{BinaryAgreement, MessageContent, SbvMessage}; use hbbft::threshold_sign::ThresholdSign; -use hbbft::{DaStep, DistAlgorithm, NetworkInfo}; +use hbbft::{ConsensusProtocol, CpStep, NetworkInfo}; use proptest::{proptest, proptest_helper}; use rand::{Rng, SeedableRng}; @@ -417,7 +417,7 @@ impl Adversary for AbaCommonCoinAdversary { _: NetMutHandle, msg: NetMessage, _rng: &mut R, - ) -> Result, CrankError> { + ) -> Result, CrankError> { if let MessageContent::Coin(ref coin_msg) = msg.payload().content { let mut new_coin_state = None; if let CoinState::InProgress(ref mut coin) = self.coin_state { @@ -432,7 +432,7 @@ impl Adversary for AbaCommonCoinAdversary { self.coin_state = new_coin_state; } } - Ok(DaStep::::default()) + Ok(CpStep::::default()) } } diff --git a/tests/broadcast.rs b/tests/broadcast.rs index 8d11ed60..5642b22c 100644 --- a/tests/broadcast.rs +++ b/tests/broadcast.rs @@ -15,7 +15,7 @@ use crate::network::{ TestNetwork, TestNode, }; use hbbft::broadcast::{Broadcast, Message}; -use hbbft::{util, DistAlgorithm, NetworkInfo, Target, TargetedMessage}; +use hbbft::{util, ConsensusProtocol, NetworkInfo, Target, TargetedMessage}; /// An adversary that inputs an alternate value. struct ProposeAdversary { diff --git a/tests/honey_badger.rs b/tests/honey_badger.rs index fc8660c7..c99d2573 100644 --- a/tests/honey_badger.rs +++ b/tests/honey_badger.rs @@ -14,7 +14,7 @@ use rand::{seq::SliceRandom, Rng}; use hbbft::honey_badger::{Batch, EncryptionSchedule, HoneyBadger, MessageContent}; use hbbft::sender_queue::{self, SenderQueue, Step}; use hbbft::transaction_queue::TransactionQueue; -use hbbft::{threshold_decrypt, util, DistAlgorithm, NetworkInfo, Target, TargetedMessage}; +use hbbft::{threshold_decrypt, util, ConsensusProtocol, NetworkInfo, Target, TargetedMessage}; use crate::network::{ Adversary, MessageScheduler, MessageWithSender, NodeId, RandomAdversary, SilentAdversary, @@ -58,7 +58,7 @@ impl Adversary for FaultyShareAdversary { fn push_message( &mut self, sender_id: NodeId, - msg: TargetedMessage<::Message, NodeId>, + msg: TargetedMessage<::Message, NodeId>, ) { let NodeId(sender_id) = sender_id; if sender_id < self.num_good { diff --git a/tests/net/adversary.rs b/tests/net/adversary.rs index f380494c..79c6fdbf 100644 --- a/tests/net/adversary.rs +++ b/tests/net/adversary.rs @@ -4,7 +4,7 @@ //! node. These functions are handled through callbacks, implemented individually by each adversary. //! //! This module contains algorithm-agnostic adversaries, which should work for (or rather, against) -//! any `DistAlgorithm`. Specific adversaries tailored to individual algorithms are implemented +//! any `ConsensusProtocol`. Specific adversaries tailored to individual algorithms are implemented //! alongside their other test cases. //! //! ## Adversary model @@ -38,7 +38,7 @@ use std::collections::VecDeque; use rand::Rng; -use hbbft::{DaStep, DistAlgorithm}; +use hbbft::{ConsensusProtocol, CpStep}; use crate::net::{CrankError, NetMessage, Node, VirtualNet}; @@ -48,14 +48,14 @@ use crate::net::{CrankError, NetMessage, Node, VirtualNet}; #[derive(Debug)] pub struct NetHandle<'a, D: 'a, A>(&'a VirtualNet) where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, A: Adversary; impl<'a, D: 'a, A> NetHandle<'a, D, A> where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, A: Adversary, @@ -114,14 +114,14 @@ pub enum QueuePosition { #[derive(Debug)] pub struct NetMutHandle<'a, D: 'a, A>(&'a mut VirtualNet) where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, A: Adversary; impl<'a, D, A> NetMutHandle<'a, D, A> where - D: DistAlgorithm, + D: ConsensusProtocol, A: Adversary, D::NodeId: Clone, D::Message: Clone, @@ -157,7 +157,7 @@ where &mut self, msg: NetMessage, rng: &mut R, - ) -> Result, CrankError> { + ) -> Result, CrankError> { self.0.dispatch_message(msg, rng) } @@ -227,7 +227,7 @@ where // Downgrade-conversion. impl<'a, D, A> From> for NetHandle<'a, D, A> where - D: DistAlgorithm, + D: ConsensusProtocol, A: Adversary, D::Message: Clone, D::Output: Clone, @@ -242,11 +242,11 @@ where #[derive(Debug)] pub struct NodeHandle<'a, D: 'a>(&'a Node) where - D: DistAlgorithm; + D: ConsensusProtocol; impl<'a, D> NodeHandle<'a, D> where - D: DistAlgorithm, + D: ConsensusProtocol, { /// Construct a new immutable node handle. #[inline] @@ -286,11 +286,11 @@ where #[derive(Debug)] pub struct NodeMutHandle<'a, D: 'a>(&'a mut Node) where - D: DistAlgorithm; + D: ConsensusProtocol; impl<'a, D: 'a> NodeMutHandle<'a, D> where - D: DistAlgorithm, + D: ConsensusProtocol, { /// Construct a new mutable node handle. fn new(inner: &'a mut Node) -> Self { @@ -323,7 +323,7 @@ where pub trait Adversary where Self: Sized, - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, { @@ -355,7 +355,7 @@ where mut net: NetMutHandle, msg: NetMessage, rng: &mut R, - ) -> Result, CrankError> { + ) -> Result, CrankError> { net.dispatch_message(msg, rng) } } @@ -377,7 +377,7 @@ impl NullAdversary { impl Adversary for NullAdversary where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, { @@ -402,7 +402,7 @@ impl NodeOrderAdversary { impl Adversary for NodeOrderAdversary where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, { @@ -429,7 +429,7 @@ impl ReorderingAdversary { impl Adversary for ReorderingAdversary where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, { diff --git a/tests/net/err.rs b/tests/net/err.rs index 4f5a5158..418c5094 100644 --- a/tests/net/err.rs +++ b/tests/net/err.rs @@ -6,7 +6,7 @@ use std::time; use failure; use threshold_crypto as crypto; -use hbbft::DistAlgorithm; +use hbbft::ConsensusProtocol; use super::NetMessage; @@ -15,14 +15,14 @@ use super::NetMessage; /// Errors resulting from processing a single message ("cranking"). pub enum CrankError where - D: DistAlgorithm, + D: ConsensusProtocol, { - /// The algorithm run by the node produced a `DistAlgorithm::Error` while processing input. + /// The algorithm run by the node produced a `ConsensusProtocol::Error` while processing input. HandleInput(D::Error), - /// The algorithm run by the node produced a `DistAlgorithm::Error` while processing input to + /// The algorithm run by the node produced a `ConsensusProtocol::Error` while processing input to /// all nodes. HandleInputAll(D::Error), - /// The algorithm run by the node produced a `DistAlgorithm::Error` while processing a message. + /// The algorithm run by the node produced a `ConsensusProtocol::Error` while processing a message. HandleMessage { /// Network message that triggered the error. msg: NetMessage, @@ -40,7 +40,7 @@ where MessageLimitExceeded(usize), /// The execution time limit has been reached or exceeded. TimeLimitHit(time::Duration), - /// A `Fault` was reported by a correct node in a step of a `DistAlgorithm`. + /// A `Fault` was reported by a correct node in a step of a `ConsensusProtocol`. Fault { /// The ID of the node that reported the fault. reported_by: D::NodeId, @@ -55,7 +55,7 @@ where // Note: Deriving [Debug](std::fmt::Debug), [Fail](failure::Fail) and through that, // [Debug](std::fmt::Debug) automatically does not work due to the wrongly required trait -// bound of `D: DistAlgorithm` implementing the respective Trait. For this reason, these +// bound of `D: ConsensusProtocol` implementing the respective Trait. For this reason, these // three traits are implemented manually. // // More details at @@ -64,7 +64,7 @@ where // * impl Display for CrankError where - D: DistAlgorithm, + D: ConsensusProtocol, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -120,7 +120,7 @@ where impl Debug for CrankError where - D: DistAlgorithm, + D: ConsensusProtocol, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -168,7 +168,7 @@ where impl failure::Fail for CrankError where - D: DistAlgorithm + 'static, + D: ConsensusProtocol + 'static, { fn cause(&self) -> Option<&failure::Fail> { match self { diff --git a/tests/net/mod.rs b/tests/net/mod.rs index 5292303b..03ab2c33 100644 --- a/tests/net/mod.rs +++ b/tests/net/mod.rs @@ -27,7 +27,7 @@ use rand::{self, Rng}; use hbbft::dynamic_honey_badger::Batch; use hbbft::sender_queue::SenderQueueableOutput; -use hbbft::{self, Contribution, DaStep, DistAlgorithm, Fault, NetworkInfo, NodeIdT, Step}; +use hbbft::{self, ConsensusProtocol, Contribution, CpStep, Fault, NetworkInfo, NodeIdT, Step}; use crate::try_some; @@ -67,7 +67,7 @@ fn open_trace() -> Result, io::Error> { } /// A node in the test network. -pub struct Node { +pub struct Node { /// Algorithm instance of node. algorithm: D, /// Whether or not the node is faulty. @@ -80,7 +80,7 @@ pub struct Node { impl fmt::Debug for Node where - D: DistAlgorithm, + D: ConsensusProtocol, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Node") @@ -91,7 +91,7 @@ where } } -impl Node { +impl Node { /// Create a new node. #[inline] fn new(algorithm: D, is_faulty: bool) -> Self { @@ -146,7 +146,7 @@ impl Node { } /// Collects all outputs and faults (not required for network operation) for user convenience. - fn store_step(&mut self, step: &DaStep) + fn store_step(&mut self, step: &CpStep) where D::Output: Clone, { @@ -195,11 +195,11 @@ impl NetworkMessage { } /// Mapping from node IDs to actual node instances. -pub type NodeMap = BTreeMap<::NodeId, Node>; +pub type NodeMap = BTreeMap<::NodeId, Node>; -/// A virtual network message tied to a distributed algorithm. +/// A virtual network message tied to a consensus protocol. pub type NetMessage = - NetworkMessage<::Message, ::NodeId>; + NetworkMessage<::Message, ::NodeId>; /// Process a step. /// @@ -218,12 +218,12 @@ pub type NetMessage = fn process_step<'a, D>( nodes: &'a mut BTreeMap>, stepped_id: D::NodeId, - step: &DaStep, + step: &CpStep, dest: &mut VecDeque>, error_on_fault: bool, ) -> Result> where - D: DistAlgorithm + 'a, + D: ConsensusProtocol + 'a, D::Message: Clone, D::Output: Clone, { @@ -291,7 +291,7 @@ where #[derive(Debug)] pub struct NewNodeInfo where - D: DistAlgorithm, + D: ConsensusProtocol, { /// The node ID for the new node. pub id: D::NodeId, @@ -310,14 +310,14 @@ where /// otherwise the construction will fail and panic. pub struct NetBuilder where - D: DistAlgorithm, + D: ConsensusProtocol, { /// Iterator used to create node ids. node_ids: I, /// Number of faulty nodes in the network. num_faulty: usize, /// Dist-algorithm constructor function. - cons: Option) -> (D, DaStep)>>, + cons: Option) -> (D, CpStep)>>, /// Network adversary. adversary: Option, /// Trace-enabling flag. `None` means use environment. @@ -335,7 +335,7 @@ where impl fmt::Debug for NetBuilder where - D: DistAlgorithm, + D: ConsensusProtocol, A: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -355,7 +355,7 @@ where impl NetBuilder where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, I: IntoIterator, @@ -469,7 +469,7 @@ where #[inline] pub fn using_step(mut self, cons: F) -> Self where - F: Fn(NewNodeInfo) -> (D, DaStep) + 'static, + F: Fn(NewNodeInfo) -> (D, CpStep) + 'static, { self.cons = Some(Box::new(cons)); self @@ -498,7 +498,7 @@ where pub fn build( self, rng: &mut R, - ) -> Result<(VirtualNet, Vec<(D::NodeId, DaStep)>), CrankError> { + ) -> Result<(VirtualNet, Vec<(D::NodeId, CpStep)>), CrankError> { // The time limit can be overriden through environment variables: let override_time_limit = env::var("HBBFT_NO_TIME_LIMIT") // We fail early, to avoid tricking the user into thinking that they have set the time @@ -556,14 +556,14 @@ where /// /// Virtual networks host a number of nodes that are marked either correct or faulty. Each time a /// node emits a `Step`, the contained messages are queued for delivery, which happens whenever -/// `crank()` is called. Additionally, inputs (see `DistAlgorithm::Input`) can be sent to any node. +/// `crank()` is called. Additionally, inputs (see `ConsensusProtocol::Input`) can be sent to any node. /// /// An adversary can be hooked into the network to affect the order of message delivery or the /// behaviour of faulty nodes. #[derive(Debug)] pub struct VirtualNet where - D: DistAlgorithm, + D: ConsensusProtocol, A: Adversary, D::Message: Clone, D::Output: Clone, @@ -599,7 +599,7 @@ where impl VirtualNet where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, A: Adversary, @@ -724,7 +724,7 @@ where impl VirtualNet where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, A: Adversary, @@ -733,7 +733,7 @@ where /// /// Creates a new network from `node_ids`, with the first `faulty` nodes marked faulty. To /// construct nodes, the `cons` function is passed the ID and the generated `NetworkInfo` and - /// expected to return a (`DistAlgorithm`, `Step`) tuple. + /// expected to return a (`ConsensusProtocol`, `Step`) tuple. /// /// All messages from the resulting step are queued for delivery. The function outputs the /// initial steps of the nodes in the constructed network for testing purposes. @@ -750,9 +750,9 @@ where mut rng: R, cons: F, error_on_fault: bool, - ) -> Result<(Self, Vec<(D::NodeId, DaStep)>), CrankError> + ) -> Result<(Self, Vec<(D::NodeId, CpStep)>), CrankError> where - F: Fn(NewNodeInfo) -> (D, DaStep), + F: Fn(NewNodeInfo) -> (D, CpStep), I: IntoIterator, R: rand::Rng, { @@ -824,7 +824,7 @@ where &mut self, msg: NetMessage, rng: &mut R, - ) -> Result, CrankError> { + ) -> Result, CrankError> { let node = self .nodes .get_mut(&msg.to) @@ -856,7 +856,7 @@ where id: D::NodeId, input: D::Input, rng: &mut R, - ) -> Result, CrankError> { + ) -> Result, CrankError> { let step = self .nodes .get_mut(&id) @@ -871,7 +871,7 @@ where /// Processes a step of a given node. The results of the processing are stored internally in the /// test network. #[must_use = "The result of processing a step must be used."] - pub fn process_step(&mut self, id: D::NodeId, step: &DaStep) -> Result<(), CrankError> { + pub fn process_step(&mut self, id: D::NodeId, step: &CpStep) -> Result<(), CrankError> { self.message_count = self.message_count.saturating_add(process_step( &mut self.nodes, id, @@ -893,7 +893,7 @@ where pub fn crank( &mut self, rng: &mut R, - ) -> Option), CrankError>> { + ) -> Option), CrankError>> { // Check limits. if let Some(limit) = self.crank_limit { if self.crank_count >= limit { @@ -984,7 +984,7 @@ where /// /// Shortcut for cranking the network, expecting both progress to be made as well as processing /// to proceed. - pub fn crank_expect(&mut self, rng: &mut R) -> (D::NodeId, DaStep) { + pub fn crank_expect(&mut self, rng: &mut R) -> (D::NodeId, CpStep) { self.crank(rng) .expect("crank: network queue empty") .expect("crank: node failed to process step") @@ -993,7 +993,7 @@ where impl VirtualNet where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Input: Clone, D::Output: Clone, @@ -1010,7 +1010,7 @@ where &'a mut self, input: &'a D::Input, rng: &mut R, - ) -> Result)>, CrankError> { + ) -> Result)>, CrankError> { let steps: Vec<_> = self .nodes .values_mut() @@ -1035,7 +1035,7 @@ where impl VirtualNet where - D: DistAlgorithm>, + D: ConsensusProtocol>, D::Message: Clone, A: Adversary, C: Contribution + Clone, @@ -1093,7 +1093,7 @@ where impl ops::Index for VirtualNet where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, A: Adversary, @@ -1108,7 +1108,7 @@ where impl ops::IndexMut for VirtualNet where - D: DistAlgorithm, + D: ConsensusProtocol, D::Message: Clone, D::Output: Clone, A: Adversary, diff --git a/tests/network/mod.rs b/tests/network/mod.rs index 740b12c3..38bbe676 100644 --- a/tests/network/mod.rs +++ b/tests/network/mod.rs @@ -12,7 +12,7 @@ use serde_derive::{Deserialize, Serialize}; use hbbft::dynamic_honey_badger::Batch; use hbbft::sender_queue::SenderQueueableOutput; use hbbft::{ - Contribution, DaStep, DistAlgorithm, Fault, NetworkInfo, Step, Target, TargetedMessage, + ConsensusProtocol, Contribution, CpStep, Fault, NetworkInfo, Step, Target, TargetedMessage, }; /// A node identifier. In the tests, nodes are simply numbered. @@ -20,7 +20,7 @@ use hbbft::{ pub struct NodeId(pub usize); /// A "node" running an instance of the algorithm `D`. -pub struct TestNode { +pub struct TestNode { /// This node's own ID. pub id: D::NodeId, /// The instance of the broadcast algorithm. @@ -35,7 +35,7 @@ pub struct TestNode { faults: Vec>, } -impl TestNode { +impl TestNode { /// Returns the list of outputs received by this node. pub fn outputs(&self) -> &[D::Output] { &self.outputs @@ -68,7 +68,7 @@ impl TestNode { } /// Creates a new test node with the given broadcast instance. - fn new((algo, step): (D, DaStep)) -> TestNode { + fn new((algo, step): (D, CpStep)) -> TestNode { TestNode { id: algo.our_id().clone(), algo, @@ -110,7 +110,7 @@ pub enum MessageScheduler { impl MessageScheduler { /// Chooses a node to be the next one to handle a message. - pub fn pick_node( + pub fn pick_node( &self, nodes: &BTreeMap>, ) -> D::NodeId { @@ -132,16 +132,16 @@ impl MessageScheduler { } /// A message combined with a sender. -pub struct MessageWithSender { +pub struct MessageWithSender { /// The sender of the message. - pub sender: ::NodeId, + pub sender: ::NodeId, /// The targeted message (recipient and message body). - pub tm: TargetedMessage<::Message, ::NodeId>, + pub tm: TargetedMessage<::Message, ::NodeId>, } // The Debug implementation cannot be derived automatically, possibly due to a compiler bug. For // this reason, it is implemented manually here. -impl fmt::Debug for MessageWithSender { +impl fmt::Debug for MessageWithSender { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, @@ -151,7 +151,7 @@ impl fmt::Debug for MessageWithSender { } } -impl MessageWithSender { +impl MessageWithSender { /// Creates a new message with a sender. pub fn new( sender: D::NodeId, @@ -164,7 +164,7 @@ impl MessageWithSender { /// An adversary that can control a set of nodes and pick the next good node to receive a message. /// /// See `TestNetwork::step()` for a more detailed description of its capabilities. -pub trait Adversary { +pub trait Adversary { /// Chooses a node to be the next one to handle a message. /// /// Starvation is illegal, i.e. in every iteration a node that has pending incoming messages @@ -200,7 +200,7 @@ impl SilentAdversary { } } -impl Adversary for SilentAdversary { +impl Adversary for SilentAdversary { fn pick_node(&self, nodes: &BTreeMap>) -> D::NodeId { self.scheduler.pick_node(nodes) } @@ -234,7 +234,7 @@ fn test_randomly() { /// The adversary will randomly take a message that is sent to one of its nodes and re-send it to /// a different node. Additionally, it will inject unrelated messages at random. #[allow(unused)] // not used in all tests -pub struct RandomAdversary { +pub struct RandomAdversary { /// The underlying scheduler used scheduler: MessageScheduler, @@ -254,7 +254,7 @@ pub struct RandomAdversary { p_inject: f32, } -impl RandomAdversary { +impl RandomAdversary { /// Creates a new random adversary instance. #[allow(unused)] pub fn new(p_replay: f32, p_inject: f32, generator: F) -> RandomAdversary { @@ -276,7 +276,7 @@ impl RandomAdversary { } } -impl TargetedMessage> Adversary +impl TargetedMessage> Adversary for RandomAdversary { fn init( @@ -361,7 +361,7 @@ impl TargetedMessage> Advers /// A collection of `TestNode`s representing a network. /// -/// Each `TestNetwork` type is tied to a specific adversary and a distributed algorithm. It consists +/// Each `TestNetwork` type is tied to a specific adversary and a consensus protocol. It consists /// of a set of nodes, some of which are controlled by the adversary and some of which may be /// observer nodes, as well as a set of threshold-cryptography public keys. /// @@ -372,14 +372,14 @@ impl TargetedMessage> Advers /// 2. Send arbitrary messages to any node originating from one of the nodes they control. /// /// See the `step` function for details on actual operation of the network. -pub struct TestNetwork, D: DistAlgorithm> { +pub struct TestNetwork, D: ConsensusProtocol> { pub nodes: BTreeMap>, pub observer: TestNode, pub adv_nodes: BTreeMap>>, adversary: A, } -impl, D: DistAlgorithm> TestNetwork +impl, D: ConsensusProtocol> TestNetwork where D::Message: Clone, { @@ -410,7 +410,7 @@ where new_algo: F, ) -> TestNetwork where - F: Fn(Arc>) -> (D, DaStep), + F: Fn(Arc>) -> (D, CpStep), G: Fn(BTreeMap>>) -> A, { let mut rng = rand::thread_rng(); @@ -605,7 +605,7 @@ where impl, C, D> TestNetwork where - D: DistAlgorithm, NodeId = NodeId>, + D: ConsensusProtocol, NodeId = NodeId>, C: Contribution + Clone, { /// Verifies that all nodes' outputs agree, given a correct "full" node that output all