Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename DistAlgorithm to ConsensusProtocol. #377

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/network/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
Expand Down
20 changes: 10 additions & 10 deletions examples/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "
Expand Down Expand Up @@ -60,14 +60,14 @@ type Transaction = Vec<u8>;

/// A serialized message with a sender and the timestamp of arrival.
#[derive(Eq, PartialEq, Debug)]
struct TimestampedMessage<D: DistAlgorithm> {
struct TimestampedMessage<D: ConsensusProtocol> {
time: Duration,
sender_id: D::NodeId,
target: Target<D::NodeId>,
message: Vec<u8>,
}

impl<D: DistAlgorithm> Clone for TimestampedMessage<D>
impl<D: ConsensusProtocol> Clone for TimestampedMessage<D>
where
D::Message: Clone,
{
Expand Down Expand Up @@ -95,7 +95,7 @@ pub struct HwQuality {
}

/// A "node" running an instance of the algorithm `D`.
pub struct TestNode<D: DistAlgorithm> {
pub struct TestNode<D: ConsensusProtocol> {
/// This node's own ID.
id: D::NodeId,
/// The instance of the broadcast algorithm.
Expand All @@ -118,14 +118,14 @@ pub struct TestNode<D: DistAlgorithm> {
hw_quality: HwQuality,
}

type TestNodeStepResult<D> = DaStep<D>;
type TestNodeStepResult<D> = CpStep<D>;

impl<D: DistAlgorithm> TestNode<D>
impl<D: ConsensusProtocol> TestNode<D>
where
D::Message: Serialize + DeserializeOwned,
{
/// Creates a new test node with the given broadcast instance.
fn new((algo, step): (D, DaStep<D>), hw_quality: HwQuality) -> TestNode<D> {
fn new((algo, step): (D, CpStep<D>), hw_quality: HwQuality) -> TestNode<D> {
let out_queue = step
.messages
.into_iter()
Expand Down Expand Up @@ -231,11 +231,11 @@ where
}

/// A collection of `TestNode`s representing a network.
pub struct TestNetwork<D: DistAlgorithm> {
pub struct TestNetwork<D: ConsensusProtocol> {
nodes: BTreeMap<D::NodeId, TestNode<D>>,
}

impl<D: DistAlgorithm<NodeId = NodeId>> TestNetwork<D>
impl<D: ConsensusProtocol<NodeId = NodeId>> TestNetwork<D>
where
D::Message: Serialize + DeserializeOwned + Clone,
{
Expand All @@ -248,7 +248,7 @@ where
rng: &mut R,
) -> TestNetwork<D>
where
F: Fn(NetworkInfo<NodeId>, &mut R) -> (D, DaStep<D>),
F: Fn(NetworkInfo<NodeId>, &mut R) -> (D, CpStep<D>),
{
let node_ids = (0..(good_num + adv_num)).map(NodeId);
let netinfos =
Expand Down
6 changes: 3 additions & 3 deletions src/binary_agreement/binary_agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -158,7 +158,7 @@ pub struct BinaryAgreement<N, S> {
/// The estimate of the decision value in the current epoch.
estimated: Option<bool>,
/// 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.
Expand All @@ -171,7 +171,7 @@ pub struct BinaryAgreement<N, S> {
coin_state: CoinState<N>,
}

impl<N: NodeIdT, S: SessionIdT> DistAlgorithm for BinaryAgreement<N, S> {
impl<N: NodeIdT, S: SessionIdT> ConsensusProtocol for BinaryAgreement<N, S> {
type NodeId = N;
type Input = bool;
type Output = bool;
Expand Down
6 changes: 3 additions & 3 deletions src/broadcast/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = result::Result<T, rse::Error>;

Expand Down Expand Up @@ -41,9 +41,9 @@ pub struct Broadcast<N> {
}

/// A `Broadcast` step, containing at most one output.
pub type Step<N> = crate::DaStep<Broadcast<N>>;
pub type Step<N> = crate::CpStep<Broadcast<N>>;

impl<N: NodeIdT> DistAlgorithm for Broadcast<N> {
impl<N: NodeIdT> ConsensusProtocol for Broadcast<N> {
type NodeId = N;
type Input = Vec<u8>;
type Output = Self::Input;
Expand Down
4 changes: 2 additions & 2 deletions src/dynamic_honey_badger/dynamic_honey_badger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -42,7 +42,7 @@ pub struct DynamicHoneyBadger<C, N: Ord> {
pub(super) key_gen_state: Option<KeyGenState<N>>,
}

impl<C, N> DistAlgorithm for DynamicHoneyBadger<C, N>
impl<C, N> ConsensusProtocol for DynamicHoneyBadger<C, N>
where
C: Contribution + Serialize + DeserializeOwned,
N: NodeIdT + Serialize + DeserializeOwned,
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic_honey_badger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C, N> = crate::DaStep<DynamicHoneyBadger<C, N>>;
pub type Step<C, N> = crate::CpStep<DynamicHoneyBadger<C, N>>;

/// The user input for `DynamicHoneyBadger`.
#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/fault_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/honey_badger/honey_badger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,9 +33,9 @@ pub struct HoneyBadger<C, N> {
}

/// A `HoneyBadger` step, possibly containing multiple outputs.
pub type Step<C, N> = crate::DaStep<HoneyBadger<C, N>>;
pub type Step<C, N> = crate::CpStep<HoneyBadger<C, N>>;

impl<C, N> DistAlgorithm for HoneyBadger<C, N>
impl<C, N> ConsensusProtocol for HoneyBadger<C, N>
where
C: Contribution + Serialize + DeserializeOwned,
N: NodeIdT,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
4 changes: 2 additions & 2 deletions src/queueing_honey_badger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -164,7 +164,7 @@ pub struct QueueingHoneyBadger<T, N: Ord, Q> {
/// A `QueueingHoneyBadger` step, possibly containing multiple outputs.
pub type Step<T, N> = crate::Step<Message<N>, Batch<T, N>, N, FaultKind>;

impl<T, N, Q> DistAlgorithm for QueueingHoneyBadger<T, N, Q>
impl<T, N, Q> ConsensusProtocol for QueueingHoneyBadger<T, N, Q>
where
T: Contribution + Serialize + DeserializeOwned + Clone,
N: NodeIdT + Serialize + DeserializeOwned,
Expand Down
8 changes: 4 additions & 4 deletions src/sender_queue/dynamic_honey_badger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -76,7 +76,7 @@ impl<N: Ord> SenderQueueableMessage for DhbMessage<N> {
}
}

impl<C, N> SenderQueueableDistAlgorithm for DynamicHoneyBadger<C, N>
impl<C, N> SenderQueueableConsensusProtocol for DynamicHoneyBadger<C, N>
where
C: Contribution + Serialize + DeserializeOwned,
N: NodeIdT + Serialize + DeserializeOwned,
Expand All @@ -86,7 +86,7 @@ where
}
}

type Result<C, N> = result::Result<DaStep<SenderQueue<DynamicHoneyBadger<C, N>>>, Error<DhbError>>;
type Result<C, N> = result::Result<CpStep<SenderQueue<DynamicHoneyBadger<C, N>>>, Error<DhbError>>;

impl<C, N> SenderQueue<DynamicHoneyBadger<C, N>>
where
Expand Down
4 changes: 2 additions & 2 deletions src/sender_queue/honey_badger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -48,7 +48,7 @@ where
}
}

impl<C, N> SenderQueueableDistAlgorithm for HoneyBadger<C, N>
impl<C, N> SenderQueueableConsensusProtocol for HoneyBadger<C, N>
where
C: Contribution + Serialize + DeserializeOwned,
N: NodeIdT,
Expand Down
Loading