From 7f784e785252f2d79d9fc5935cf4960b1ca2c6b3 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Wed, 7 Nov 2018 14:26:14 +0100 Subject: [PATCH] Make Step independent of DistAlgorithm. --- examples/simulation.rs | 8 +- src/binary_agreement/binary_agreement.rs | 46 +++++------ src/binary_agreement/mod.rs | 2 +- src/binary_agreement/sbv_broadcast.rs | 76 +++++++---------- src/broadcast/broadcast.rs | 2 +- src/dynamic_honey_badger/mod.rs | 2 +- src/honey_badger/epoch_state.rs | 2 +- src/honey_badger/honey_badger.rs | 2 +- src/lib.rs | 4 +- src/queueing_honey_badger/mod.rs | 27 +++---- src/sender_queue/dynamic_honey_badger.rs | 10 ++- src/sender_queue/mod.rs | 36 ++++----- src/sender_queue/queueing_honey_badger.rs | 11 +-- src/subset/proposal_state.rs | 52 ++++-------- src/subset/subset.rs | 14 ++-- src/threshold_decrypt.rs | 2 +- src/threshold_sign.rs | 2 +- src/traits.rs | 99 +++++++++-------------- tests/binary_agreement_mitm.rs | 6 +- tests/net/adversary.rs | 6 +- tests/net/mod.rs | 24 +++--- tests/network/mod.rs | 8 +- 22 files changed, 187 insertions(+), 254 deletions(-) diff --git a/examples/simulation.rs b/examples/simulation.rs index 52a297f..bae54e4 100644 --- a/examples/simulation.rs +++ b/examples/simulation.rs @@ -27,7 +27,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::{DistAlgorithm, NetworkInfo, Step, Target}; +use hbbft::{DaStep, DistAlgorithm, NetworkInfo, Step, Target}; const VERSION: &str = env!("CARGO_PKG_VERSION"); const USAGE: &str = " @@ -137,14 +137,14 @@ pub struct TestNode { hw_quality: HwQuality, } -type TestNodeStepResult = Step; +type TestNodeStepResult = DaStep; impl TestNode where D::Message: Serialize + DeserializeOwned, { /// Creates a new test node with the given broadcast instance. - fn new((algo, step): (D, Step), hw_quality: HwQuality) -> TestNode { + fn new((algo, step): (D, DaStep), hw_quality: HwQuality) -> TestNode { let out_queue = step .messages .into_iter() @@ -264,7 +264,7 @@ where hw_quality: HwQuality, ) -> TestNetwork where - F: Fn(NetworkInfo) -> (D, Step), + F: Fn(NetworkInfo) -> (D, DaStep), { let node_ids = (0..(good_num + adv_num)).map(NodeId); let netinfos = NetworkInfo::generate_map(node_ids, &mut rand::thread_rng()) diff --git a/src/binary_agreement/binary_agreement.rs b/src/binary_agreement/binary_agreement.rs index 08ff3be..fcd781b 100644 --- a/src/binary_agreement/binary_agreement.rs +++ b/src/binary_agreement/binary_agreement.rs @@ -78,12 +78,12 @@ impl DistAlgorithm for BinaryAgreement { type Message = Message; type Error = Error; - fn handle_input(&mut self, input: Self::Input) -> Result> { + fn handle_input(&mut self, input: Self::Input) -> Result> { self.propose(input) } /// Receive input from a remote node. - fn handle_message(&mut self, sender_id: &Self::NodeId, msg: Message) -> Result> { + fn handle_message(&mut self, sender_id: &Self::NodeId, msg: Message) -> Result> { self.handle_message(sender_id, msg) } @@ -122,20 +122,20 @@ impl BinaryAgreement { /// output. Otherwise either output is possible. /// /// Note that if `can_propose` returns `false`, it is already too late to affect the outcome. - pub fn propose(&mut self, input: bool) -> Result> { + pub fn propose(&mut self, input: bool) -> Result> { if !self.can_propose() { return Ok(Step::default()); } // Set the initial estimated value to the input value. self.estimated = Some(input); - let sbvb_step = self.sbv_broadcast.handle_input(input)?; + let sbvb_step = self.sbv_broadcast.send_bval(input)?; self.handle_sbvb_step(sbvb_step) } /// Handles a message received from `sender_id`. /// /// This must be called with every message we receive from another node. - pub fn handle_message(&mut self, sender_id: &N, msg: Message) -> Result> { + pub fn handle_message(&mut self, sender_id: &N, msg: Message) -> Result> { let Message { epoch, content } = msg; if self.decision.is_some() || (epoch < self.epoch && content.can_expire()) { // Message is obsolete: We are already in a later epoch or terminated. @@ -161,9 +161,9 @@ impl BinaryAgreement { &mut self, sender_id: &N, content: MessageContent, - ) -> Result> { + ) -> Result> { match content { - MessageContent::SbvBroadcast(msg) => self.handle_sbv_broadcast(sender_id, msg), + MessageContent::SbvBroadcast(msg) => self.handle_sbv_broadcast(sender_id, &msg), MessageContent::Conf(v) => self.handle_conf(sender_id, v), MessageContent::Term(v) => self.handle_term(sender_id, v), MessageContent::Coin(msg) => self.handle_coin(sender_id, *msg), @@ -174,15 +174,15 @@ impl BinaryAgreement { fn handle_sbv_broadcast( &mut self, sender_id: &N, - msg: sbv_broadcast::Message, - ) -> Result> { - let sbvb_step = self.sbv_broadcast.handle_message(sender_id, msg)?; + msg: &sbv_broadcast::Message, + ) -> Result> { + let sbvb_step = self.sbv_broadcast.handle_message(sender_id, &msg)?; self.handle_sbvb_step(sbvb_step) } /// Handles a Synchronized Binary Value Broadcast step. On output, starts the `Conf` round or /// decides. - fn handle_sbvb_step(&mut self, sbvb_step: sbv_broadcast::Step) -> Result> { + fn handle_sbvb_step(&mut self, sbvb_step: sbv_broadcast::Step) -> Result> { let mut step = Step::default(); let output = step.extend_with(sbvb_step, |msg| { MessageContent::SbvBroadcast(msg).with_epoch(self.epoch) @@ -208,7 +208,7 @@ impl BinaryAgreement { /// Handles a `Conf` message. When _N - f_ `Conf` messages with values in `bin_values` have /// been received, updates the epoch or decides. - fn handle_conf(&mut self, sender_id: &N, v: BoolSet) -> Result> { + fn handle_conf(&mut self, sender_id: &N, v: BoolSet) -> Result> { self.received_conf.insert(sender_id.clone(), v); self.try_finish_conf_round() } @@ -216,7 +216,7 @@ impl BinaryAgreement { /// Handles a `Term(v)` message. If we haven't yet decided on a value and there are more than /// _f_ such messages with the same value from different nodes, performs expedite termination: /// decides on `v`, broadcasts `Term(v)` and terminates the instance. - fn handle_term(&mut self, sender_id: &N, b: bool) -> Result> { + fn handle_term(&mut self, sender_id: &N, b: bool) -> Result> { self.received_term[b].insert(sender_id.clone()); // Check for the expedite termination condition. if self.decision.is_some() { @@ -234,7 +234,7 @@ impl BinaryAgreement { /// Handles a `ThresholdSign` message. If there is output, starts the next epoch. The function /// may output a decision value. - fn handle_coin(&mut self, sender_id: &N, msg: threshold_sign::Message) -> Result> { + fn handle_coin(&mut self, sender_id: &N, msg: threshold_sign::Message) -> Result> { let ts_step = match self.coin_state { CoinState::Decided(_) => return Ok(Step::default()), // Coin value is already decided. CoinState::InProgress(ref mut ts) => ts @@ -245,7 +245,7 @@ impl BinaryAgreement { } /// Multicasts a `Conf(values)` message, and handles it. - fn send_conf(&mut self, values: BoolSet) -> Result> { + fn send_conf(&mut self, values: BoolSet) -> Result> { if self.conf_values.is_some() { // Only one `Conf` message is allowed in an epoch. return Ok(Step::default()); @@ -262,11 +262,11 @@ impl BinaryAgreement { } /// Multicasts and handles a message. Does nothing if we are only an observer. - fn send(&mut self, content: MessageContent) -> Result> { + fn send(&mut self, content: MessageContent) -> Result> { if !self.netinfo.is_validator() { return Ok(Step::default()); } - let step: Step = Target::All + let step: Step = Target::All .message(content.clone().with_epoch(self.epoch)) .into(); let our_id = &self.our_id().clone(); @@ -274,7 +274,7 @@ impl BinaryAgreement { } /// Handles a step returned from the `ThresholdSign`. - fn on_coin_step(&mut self, ts_step: threshold_sign::Step) -> Result> { + fn on_coin_step(&mut self, ts_step: threshold_sign::Step) -> Result> { let mut step = Step::default(); let epoch = self.epoch; let to_msg = |c_msg| MessageContent::Coin(Box::new(c_msg)).with_epoch(epoch); @@ -293,7 +293,7 @@ impl BinaryAgreement { /// With two conf values, the next epoch's estimate is the coin value. If there is only one conf /// value and that disagrees with the coin, the conf value is the next epoch's estimate. If /// the unique conf value agrees with the coin, terminates and decides on that value. - fn try_update_epoch(&mut self) -> Result> { + fn try_update_epoch(&mut self) -> Result> { if self.decision.is_some() { // Avoid an infinite regression without making a Binary Agreement step. return Ok(Step::default()); @@ -330,7 +330,7 @@ impl BinaryAgreement { } /// Decides on a value and broadcasts a `Term` message with that value. - fn decide(&mut self, b: bool) -> Step { + fn decide(&mut self, b: bool) -> Step { if self.decision.is_some() { return Step::default(); } @@ -348,7 +348,7 @@ impl BinaryAgreement { } /// Checks whether the _N - f_ `Conf` messages have arrived, and if so, activates the coin. - fn try_finish_conf_round(&mut self) -> Result> { + fn try_finish_conf_round(&mut self) -> Result> { if self.conf_values.is_none() || self.count_conf() < self.netinfo.num_correct() { return Ok(Step::default()); } @@ -368,7 +368,7 @@ impl BinaryAgreement { } /// Increments the epoch, sets the new estimate and handles queued messages. - fn update_epoch(&mut self, b: bool) -> Result> { + fn update_epoch(&mut self, b: bool) -> Result> { self.sbv_broadcast.clear(&self.received_term); self.received_conf.clear(); for (v, id) in &self.received_term { @@ -384,7 +384,7 @@ impl BinaryAgreement { ); self.estimated = Some(b); - let sbvb_step = self.sbv_broadcast.handle_input(b)?; + let sbvb_step = self.sbv_broadcast.send_bval(b)?; let mut step = self.handle_sbvb_step(sbvb_step)?; let queued_msgs = self .incoming_queue diff --git a/src/binary_agreement/mod.rs b/src/binary_agreement/mod.rs index 953c6b8..a504cfd 100644 --- a/src/binary_agreement/mod.rs +++ b/src/binary_agreement/mod.rs @@ -103,7 +103,7 @@ impl From for Error { /// An Binary Agreement result. pub type Result = ::std::result::Result; -pub type Step = ::Step>; +pub type Step = ::Step; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] pub enum MessageContent { diff --git a/src/binary_agreement/sbv_broadcast.rs b/src/binary_agreement/sbv_broadcast.rs index 9ba1413..188bf43 100644 --- a/src/binary_agreement/sbv_broadcast.rs +++ b/src/binary_agreement/sbv_broadcast.rs @@ -16,11 +16,11 @@ use serde_derive::{Deserialize, Serialize}; use super::bool_multimap::BoolMultimap; use super::bool_set::{self, BoolSet}; -use super::{Error, Result}; +use super::Result; use fault_log::{Fault, FaultKind}; -use {DistAlgorithm, NetworkInfo, NodeIdT, Target}; +use {NetworkInfo, NodeIdT, Target}; -pub type Step = ::Step>; +pub type Step = ::Step; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] pub enum Message { @@ -59,33 +59,6 @@ pub struct SbvBroadcast { terminated: bool, } -impl DistAlgorithm for SbvBroadcast { - type NodeId = N; - type Input = bool; - type Output = BoolSet; - type Message = Message; - type Error = Error; - - fn handle_input(&mut self, input: Self::Input) -> Result> { - self.send_bval(input) - } - - fn handle_message(&mut self, sender_id: &Self::NodeId, msg: Self::Message) -> Result> { - match msg { - Message::BVal(b) => self.handle_bval(sender_id, b), - Message::Aux(b) => self.handle_aux(sender_id, b), - } - } - - fn terminated(&self) -> bool { - self.terminated - } - - fn our_id(&self) -> &Self::NodeId { - self.netinfo.our_id() - } -} - impl SbvBroadcast { pub fn new(netinfo: Arc>) -> Self { SbvBroadcast { @@ -108,6 +81,27 @@ impl SbvBroadcast { self.terminated = false; } + pub fn handle_message(&mut self, sender_id: &N, msg: &Message) -> Result> { + match msg { + Message::BVal(b) => self.handle_bval(sender_id, *b), + Message::Aux(b) => self.handle_aux(sender_id, *b), + } + } + + /// Returns the current `bin_values`: the set of `b` for which _2 f + 1_ `BVal`s were received. + pub fn bin_values(&self) -> BoolSet { + self.bin_values + } + + /// Multicasts a `BVal(b)` message, and handles it. + pub fn send_bval(&mut self, b: bool) -> Result> { + // Record the value `b` as sent. If it was already there, don't send it again. + if !self.sent_bval.insert(b) { + return Ok(Step::default()); + } + self.send(&Message::BVal(b)) + } + /// Handles a `BVal(b)` message. /// /// Upon receiving _f + 1_ `BVal(b)`, multicasts `BVal(b)`. Upon receiving _2 f + 1_ `BVal(b)`, @@ -126,7 +120,7 @@ impl SbvBroadcast { self.bin_values.insert(b); if self.bin_values != bool_set::BOTH { - step.extend(self.send(Message::Aux(b))?) // First entry: send `Aux(b)`. + step.extend(self.send(&Message::Aux(b))?) // First entry: send `Aux(b)`. } else { step.extend(self.try_output()?); // Otherwise just check for `Conf` condition. } @@ -139,28 +133,14 @@ impl SbvBroadcast { Ok(step) } - /// Returns the current `bin_values`: the set of `b` for which _2 f + 1_ `BVal`s were received. - pub fn bin_values(&self) -> BoolSet { - self.bin_values - } - /// Multicasts and handles a message. Does nothing if we are only an observer. - fn send(&mut self, msg: Message) -> Result> { + fn send(&mut self, msg: &Message) -> Result> { if !self.netinfo.is_validator() { return self.try_output(); } let step: Step<_> = Target::All.message(msg.clone()).into(); - let our_id = &self.our_id().clone(); - Ok(step.join(self.handle_message(our_id, msg)?)) - } - - /// Multicasts a `BVal(b)` message, and handles it. - fn send_bval(&mut self, b: bool) -> Result> { - // Record the value `b` as sent. If it was already there, don't send it again. - if !self.sent_bval.insert(b) { - return Ok(Step::default()); - } - self.send(Message::BVal(b)) + let our_id = &self.netinfo.our_id().clone(); + Ok(step.join(self.handle_message(our_id, &msg)?)) } /// Handles an `Aux` message. diff --git a/src/broadcast/broadcast.rs b/src/broadcast/broadcast.rs index 3f658f0..4e90689 100644 --- a/src/broadcast/broadcast.rs +++ b/src/broadcast/broadcast.rs @@ -37,7 +37,7 @@ pub struct Broadcast { readys: BTreeMap>, } -pub type Step = ::Step>; +pub type Step = ::DaStep>; impl DistAlgorithm for Broadcast { type NodeId = N; diff --git a/src/dynamic_honey_badger/mod.rs b/src/dynamic_honey_badger/mod.rs index 28101b5..50c1bb4 100644 --- a/src/dynamic_honey_badger/mod.rs +++ b/src/dynamic_honey_badger/mod.rs @@ -91,7 +91,7 @@ pub use self::change::{Change, ChangeState, NodeChange}; pub use self::dynamic_honey_badger::DynamicHoneyBadger; pub use self::error::{Error, ErrorKind, Result}; -pub type Step = ::Step>; +pub type Step = ::DaStep>; /// The user input for `DynamicHoneyBadger`. #[derive(Clone, Debug)] diff --git a/src/honey_badger/epoch_state.rs b/src/honey_badger/epoch_state.rs index 768d3ed..469954f 100644 --- a/src/honey_badger/epoch_state.rs +++ b/src/honey_badger/epoch_state.rs @@ -19,7 +19,7 @@ use subset::{self as cs, Subset, SubsetOutput}; use threshold_decrypt::{self as td, ThresholdDecrypt}; use {Contribution, DistAlgorithm, NetworkInfo, NodeIdT}; -type CsStep = cs::Step; +type CsStep = cs::Step; /// The status of an encrypted contribution. #[derive(Debug)] diff --git a/src/honey_badger/honey_badger.rs b/src/honey_badger/honey_badger.rs index b1004bf..c513ca2 100644 --- a/src/honey_badger/honey_badger.rs +++ b/src/honey_badger/honey_badger.rs @@ -53,7 +53,7 @@ impl Epoched for HoneyBadger { } } -pub type Step = ::Step>; +pub type Step = ::DaStep>; impl DistAlgorithm for HoneyBadger where diff --git a/src/lib.rs b/src/lib.rs index 672b9b1..3fee244 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,4 +153,6 @@ pub use crypto::pairing; pub use fault_log::{Fault, FaultKind, FaultLog}; pub use messaging::{SourcedMessage, Target, TargetedMessage}; pub use network_info::NetworkInfo; -pub use traits::{Contribution, DistAlgorithm, Epoched, Message, NodeIdT, SessionIdT, Step}; +pub use traits::{ + Contribution, DaStep, DistAlgorithm, Epoched, Message, NodeIdT, SessionIdT, Step, +}; diff --git a/src/queueing_honey_badger/mod.rs b/src/queueing_honey_badger/mod.rs index 806a174..126e5f0 100644 --- a/src/queueing_honey_badger/mod.rs +++ b/src/queueing_honey_badger/mod.rs @@ -105,7 +105,7 @@ pub struct QueueingHoneyBadgerBuilder { _phantom: PhantomData, } -pub type QueueingHoneyBadgerWithStep = (QueueingHoneyBadger, Step); +pub type QueueingHoneyBadgerWithStep = (QueueingHoneyBadger, Step); impl QueueingHoneyBadgerBuilder where @@ -187,7 +187,7 @@ pub struct QueueingHoneyBadger { rng: Box, } -pub type Step = ::Step>; +pub type Step = ::Step, Batch, N>; impl DistAlgorithm for QueueingHoneyBadger where @@ -201,7 +201,7 @@ where type Message = Message; type Error = Error; - fn handle_input(&mut self, input: Self::Input) -> Result> { + fn handle_input(&mut self, input: Self::Input) -> Result> { // User transactions are forwarded to `HoneyBadger` right away. Internal messages are // in addition signed and broadcast. match input { @@ -210,7 +210,7 @@ where } } - fn handle_message(&mut self, sender_id: &N, message: Self::Message) -> Result> { + fn handle_message(&mut self, sender_id: &N, message: Self::Message) -> Result> { self.handle_message(sender_id, message) } @@ -243,7 +243,7 @@ where /// If no proposal has yet been made for the current epoch, this may trigger one. In this case, /// a nonempty step will returned, with the corresponding messages. (Or, if we are the only /// validator, even with the completed batch as an output.) - pub fn push_transaction(&mut self, tx: T) -> Result> { + pub fn push_transaction(&mut self, tx: T) -> Result> { self.queue.extend(iter::once(tx)); self.propose() } @@ -252,12 +252,11 @@ where /// /// This stores a pending vote for the change. It will be included in some future batch, and /// once enough validators have been voted for the same change, it will take effect. - pub fn vote_for(&mut self, change: Change) -> Result> { + pub fn vote_for(&mut self, change: Change) -> Result> { Ok(self .dyn_hb .handle_input(Input::Change(change)) .map_err(ErrorKind::Input)? - .convert() .join(self.propose()?)) } @@ -265,7 +264,7 @@ where /// /// This stores a pending vote for the change. It will be included in some future batch, and /// once enough validators have been voted for the same change, it will take effect. - pub fn vote_to_add(&mut self, node_id: N, pub_key: PublicKey) -> Result> { + pub fn vote_to_add(&mut self, node_id: N, pub_key: PublicKey) -> Result> { self.vote_for(Change::NodeChange(NodeChange::Add(node_id, pub_key))) } @@ -273,19 +272,18 @@ where /// /// This stores a pending vote for the change. It will be included in some future batch, and /// once enough validators have been voted for the same change, it will take effect. - pub fn vote_to_remove(&mut self, node_id: N) -> Result> { + pub fn vote_to_remove(&mut self, node_id: N) -> Result> { self.vote_for(Change::NodeChange(NodeChange::Remove(node_id))) } /// Handles a message received from `sender_id`. /// /// This must be called with every message we receive from another node. - pub fn handle_message(&mut self, sender_id: &N, message: Message) -> Result> { + pub fn handle_message(&mut self, sender_id: &N, message: Message) -> Result> { let step = self .dyn_hb .handle_message(sender_id, message) - .map_err(ErrorKind::HandleMessage)? - .convert::(); + .map_err(ErrorKind::HandleMessage)?; for batch in &step.output { self.queue.remove_multiple(batch.iter()); } @@ -308,7 +306,7 @@ where } /// Initiates the next epoch by proposing a batch from the queue. - fn propose(&mut self) -> Result> { + fn propose(&mut self) -> Result> { let mut step = Step::default(); while self.can_propose() { let amount = cmp::max(1, self.batch_size / self.dyn_hb.netinfo().num_nodes()); @@ -316,8 +314,7 @@ where step.extend( self.dyn_hb .handle_input(Input::User(proposal)) - .map_err(ErrorKind::Propose)? - .convert(), + .map_err(ErrorKind::Propose)?, ); } Ok(step) diff --git a/src/sender_queue/dynamic_honey_badger.rs b/src/sender_queue/dynamic_honey_badger.rs index 67af96a..9fbc426 100644 --- a/src/sender_queue/dynamic_honey_badger.rs +++ b/src/sender_queue/dynamic_honey_badger.rs @@ -1,17 +1,19 @@ //! Convenience methods for a `SenderQueue` wrapping a `DynamicHoneyBadger`. +use std::result; + use crypto::PublicKey; use rand::Rand; use serde::{de::DeserializeOwned, Serialize}; use super::{ SenderQueue, SenderQueueableDistAlgorithm, SenderQueueableEpoch, SenderQueueableMessage, - SenderQueueableOutput, Step, + SenderQueueableOutput, }; -use {Contribution, Epoched, NodeIdT}; +use {Contribution, DaStep, Epoched, NodeIdT}; use dynamic_honey_badger::{ - Batch, Change, ChangeState, DynamicHoneyBadger, Epoch, Message, NodeChange, + Batch, Change, ChangeState, DynamicHoneyBadger, Epoch, Error as DhbError, Message, NodeChange, }; impl SenderQueueableOutput> for Batch @@ -90,7 +92,7 @@ where } } -type Result = super::Result>, DynamicHoneyBadger>; +type Result = result::Result>>, DhbError>; impl SenderQueue> where diff --git a/src/sender_queue/mod.rs b/src/sender_queue/mod.rs index b2dd2bc..d1e9e0f 100644 --- a/src/sender_queue/mod.rs +++ b/src/sender_queue/mod.rs @@ -17,7 +17,7 @@ use std::fmt::Debug; use rand::Rand; use serde::{de::DeserializeOwned, Serialize}; -use {DistAlgorithm, Epoched, NodeIdT, Target}; +use {DaStep, DistAlgorithm, Epoched, NodeIdT, Target}; pub use self::message::Message; @@ -103,9 +103,7 @@ where peer_epochs: BTreeMap::LinEpoch>, } -pub type Step = ::Step>; - -pub type Result = ::std::result::Result::Error>; +pub type Step = ::DaStep>; impl DistAlgorithm for SenderQueue where @@ -121,7 +119,7 @@ where type Message = Message; type Error = D::Error; - fn handle_input(&mut self, input: Self::Input) -> Result, D> { + fn handle_input(&mut self, input: Self::Input) -> Result, D::Error> { self.handle_input(input) } @@ -129,7 +127,7 @@ where &mut self, sender_id: &D::NodeId, message: Self::Message, - ) -> Result, D> { + ) -> Result, D::Error> { self.handle_message(sender_id, message) } @@ -158,7 +156,7 @@ where SenderQueueBuilder::new(algo, peer_ids) } - pub fn handle_input(&mut self, input: D::Input) -> Result, D> { + pub fn handle_input(&mut self, input: D::Input) -> Result, D::Error> { self.apply(|algo| algo.handle_input(input)) } @@ -166,7 +164,7 @@ where &mut self, sender_id: &D::NodeId, message: Message, - ) -> Result, D> { + ) -> Result, D::Error> { match message { Message::EpochStarted(lin_epoch) => Ok(self.handle_epoch_started(sender_id, lin_epoch)), Message::Algo(msg) => self.handle_message_content(sender_id, msg), @@ -175,9 +173,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. - pub fn apply(&mut self, f: F) -> Result, D> + pub fn apply(&mut self, f: F) -> Result, D::Error> where - F: FnOnce(&mut D) -> Result<::Step, D>, + F: FnOnce(&mut D) -> Result, D::Error>, { let mut step = f(&mut self.algo)?; let mut sender_queue_step = self.update_lin_epoch(&step); @@ -191,7 +189,7 @@ where &mut self, sender_id: &D::NodeId, lin_epoch: ::LinEpoch, - ) -> Step { + ) -> DaStep { self.peer_epochs .entry(sender_id.clone()) .and_modify(|e| { @@ -225,7 +223,7 @@ where &mut self, sender_id: &D::NodeId, epoch: ::Epoch, - ) -> Step { + ) -> DaStep { // Send any HB messages for the HB epoch. let mut ready_messages = self .outgoing_queue @@ -239,7 +237,7 @@ where .unwrap_or_default(), ); } - Step::from( + Step::::from( ready_messages .into_iter() .map(|msg| Target::Node(sender_id.clone()).message(Message::Algo(msg))), @@ -251,12 +249,12 @@ where &mut self, sender_id: &D::NodeId, content: D::Message, - ) -> Result, D> { + ) -> Result, D::Error> { self.apply(|algo| algo.handle_message(sender_id, content)) } /// Updates the current Honey Badger epoch. - fn update_lin_epoch(&mut self, step: &::Step) -> Step { + fn update_lin_epoch(&mut self, step: &DaStep) -> DaStep { // Look up `DynamicHoneyBadger` epoch updates and collect any added peers. let new_epoch = step.output.iter().fold(self.lin_epoch, |lin_epoch, batch| { let max_epoch = lin_epoch.max(batch.next_epoch()); @@ -276,7 +274,7 @@ where .message(Message::EpochStarted(self.lin_epoch)) .into() } else { - Step::default() + Step::::default() } } @@ -284,7 +282,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 ::Step) { + fn defer_messages(&mut self, step: &mut DaStep) { 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) { @@ -355,7 +353,7 @@ where self } - pub fn build(self, our_id: D::NodeId) -> (SenderQueue, Step) { + pub fn build(self, our_id: D::NodeId) -> (SenderQueue, DaStep>) { let lin_epoch = ::LinEpoch::default(); let sq = SenderQueue { algo: self.algo, @@ -364,7 +362,7 @@ where outgoing_queue: self.outgoing_queue, peer_epochs: self.peer_epochs, }; - let step: Step = Target::All.message(Message::EpochStarted(lin_epoch)).into(); + let step = Target::All.message(Message::EpochStarted(lin_epoch)).into(); (sq, step) } } diff --git a/src/sender_queue/queueing_honey_badger.rs b/src/sender_queue/queueing_honey_badger.rs index 05e6203..0363ec8 100644 --- a/src/sender_queue/queueing_honey_badger.rs +++ b/src/sender_queue/queueing_honey_badger.rs @@ -1,13 +1,15 @@ //! Convenience methods for a `SenderQueue` wrapping a `QueueingHoneyBadger`. +use std::result; + use crypto::PublicKey; use rand::Rand; use serde::{de::DeserializeOwned, Serialize}; -use super::{SenderQueue, SenderQueueableDistAlgorithm, Step}; -use queueing_honey_badger::{Change, QueueingHoneyBadger}; +use super::{SenderQueue, SenderQueueableDistAlgorithm}; +use queueing_honey_badger::{Change, Error as QhbError, QueueingHoneyBadger}; use transaction_queue::TransactionQueue; -use {Contribution, NodeIdT}; +use {Contribution, DaStep, NodeIdT}; impl SenderQueueableDistAlgorithm for QueueingHoneyBadger where @@ -20,8 +22,7 @@ where } } -type Result = - super::Result>, QueueingHoneyBadger>; +type Result = result::Result>>, QhbError>; impl SenderQueue> where diff --git a/src/subset/proposal_state.rs b/src/subset/proposal_state.rs index 628f9cf..a5ebd7a 100644 --- a/src/subset/proposal_state.rs +++ b/src/subset/proposal_state.rs @@ -6,13 +6,13 @@ use super::{Error, MessageContent, Result}; use binary_agreement; use broadcast::{self, Broadcast}; use rand::Rand; -use {DistAlgorithm, NetworkInfo, NodeIdT, SessionIdT}; +use {NetworkInfo, NodeIdT, SessionIdT}; type BaInstance = binary_agreement::BinaryAgreement>; -type ValueAndStep = (Option>, Step); -type BaResult = binary_agreement::Result>>; +type ValueAndStep = (Option>, Step); +type BaResult = binary_agreement::Result>; -pub type Step = ::Step>; +pub type Step = ::Step, N>; /// The state of a proposal's broadcast and agreement process. #[derive(Debug)] @@ -28,30 +28,6 @@ pub enum ProposalState { Complete(bool), } -impl DistAlgorithm for ProposalState { - type NodeId = N; - type Input = Vec; - type Output = Vec; - type Message = MessageContent; - type Error = Error; - - fn handle_input(&mut self, input: Self::Input) -> Result> { - self.propose(input) - } - - fn handle_message(&mut self, sender_id: &N, message: MessageContent) -> Result> { - self.handle_message(sender_id, message) - } - - fn terminated(&self) -> bool { - self.complete() - } - - fn our_id(&self) -> &Self::NodeId { - unreachable!() // We don't actually need `DistAlgorithm`, just `Step`. - } -} - impl ProposalState { /// Creates a new `ProposalState::Ongoing`, with a fresh broadcast and agreement instance. pub fn new(netinfo: Arc>, ba_id: BaSessionId, prop_id: N) -> Result { @@ -89,12 +65,12 @@ impl ProposalState { } /// Makes a proposal by broadcasting a value. - pub fn propose(&mut self, value: Vec) -> Result> { + pub fn propose(&mut self, value: Vec) -> Result> { self.transition(|state| state.handle_broadcast(|bc| bc.broadcast(value))) } /// Handles a message received from `sender_id`. - pub fn handle_message(&mut self, sender_id: &N, msg: MessageContent) -> Result> { + pub fn handle_message(&mut self, sender_id: &N, msg: MessageContent) -> Result> { self.transition(|state| match msg { MessageContent::Agreement(ba_msg) => { state.handle_agreement(|ba| ba.handle_message(sender_id, ba_msg)) @@ -106,12 +82,12 @@ impl ProposalState { } /// Votes for rejecting the proposal, if still possible. - pub fn vote_false(&mut self) -> Result> { + pub fn vote_false(&mut self) -> Result> { self.transition(|state| state.handle_agreement(|ba| ba.propose(false))) } /// Applies `f` to the `Broadcast` instance, and updates the state according to the outcome. - fn handle_broadcast(self, f: F) -> (Self, Result>) + fn handle_broadcast(self, f: F) -> (Self, Result>) where F: FnOnce(&mut Broadcast) -> broadcast::Result>, { @@ -137,9 +113,9 @@ impl ProposalState { /// Applies `f` to the `BinaryAgreement` instance, and updates the state according to the /// outcome. - fn handle_agreement(self, f: F) -> (Self, Result>) + fn handle_agreement(self, f: F) -> (Self, Result>) where - F: FnOnce(&mut BaInstance) -> BaResult, + F: FnOnce(&mut BaInstance) -> BaResult, { use self::ProposalState::*; match self { @@ -160,7 +136,7 @@ impl ProposalState { } /// Converts a `Broadcast` result and returns the output, if there was one. - fn convert_bc(result: broadcast::Result>) -> Result> { + fn convert_bc(result: broadcast::Result>) -> Result> { let bc_step = result.map_err(Error::HandleBroadcast)?; let mut step = Step::default(); let opt_value = step.extend_with(bc_step, MessageContent::Broadcast).pop(); @@ -168,7 +144,7 @@ impl ProposalState { } /// Converts a `BinaryAgreement` step and returns the output, if there was one. - fn convert_ba(result: BaResult) -> Result<(Option, Step)> { + fn convert_ba(result: BaResult) -> Result<(Option, Step)> { let ba_step = result.map_err(Error::HandleAgreement)?; let mut step = Step::default(); let opt_decision = step.extend_with(ba_step, MessageContent::Agreement).pop(); @@ -176,9 +152,9 @@ impl ProposalState { } /// Applies the given transition to `self`. - fn transition(&mut self, f: F) -> Result> + fn transition(&mut self, f: F) -> Result> where - F: FnOnce(Self) -> (Self, Result>), + F: FnOnce(Self) -> (Self, Result>), { // Temporary value: We need to take ownership of the state to make it transition. let (new_state, result) = f(mem::replace(self, ProposalState::Complete(false))); diff --git a/src/subset/subset.rs b/src/subset/subset.rs index de2373a..fbcc24a 100644 --- a/src/subset/subset.rs +++ b/src/subset/subset.rs @@ -12,7 +12,7 @@ use super::{Error, Message, MessageContent, Result}; use rand::Rand; use {util, DistAlgorithm, NetworkInfo, NodeIdT, SessionIdT}; -pub type Step = ::Step>; +pub type Step = ::Step, SubsetOutput, N>; #[derive(Derivative, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derivative(Debug)] @@ -44,11 +44,11 @@ impl DistAlgorithm for Subset { type Message = Message; type Error = Error; - fn handle_input(&mut self, input: Self::Input) -> Result> { + fn handle_input(&mut self, input: Self::Input) -> Result> { self.propose(input) } - fn handle_message(&mut self, sender_id: &N, message: Message) -> Result> { + fn handle_message(&mut self, sender_id: &N, message: Message) -> Result> { self.handle_message(sender_id, message) } @@ -90,7 +90,7 @@ impl Subset { /// Proposes a value for the subset. /// /// Returns an error if we already made a proposal. - pub fn propose(&mut self, value: Vec) -> Result> { + pub fn propose(&mut self, value: Vec) -> Result> { if !self.netinfo.is_validator() { return Ok(Step::default()); } @@ -107,7 +107,7 @@ impl Subset { /// Handles a message received from `sender_id`. /// /// This must be called with every message we receive from another node. - pub fn handle_message(&mut self, sender_id: &N, msg: Message) -> Result> { + pub fn handle_message(&mut self, sender_id: &N, msg: Message) -> Result> { let prop_step = self .proposal_states .get_mut(&msg.proposer_id) @@ -123,7 +123,7 @@ impl Subset { self.proposal_states.values().filter(received).count() } - fn convert_step(proposer_id: &N, prop_step: ProposalStep) -> Step { + fn convert_step(proposer_id: &N, prop_step: ProposalStep) -> Step { let from_p_msg = |p_msg: MessageContent| p_msg.with(proposer_id.clone()); let mut step = Step::default(); if let Some(value) = step.extend_with(prop_step, from_p_msg).pop() { @@ -141,7 +141,7 @@ impl Subset { /// Checks the voting and termination conditions: If enough proposals have been accepted, votes /// "no" for the remaining ones. If all proposals have been decided, outputs `Done`. - fn try_output(&mut self) -> Result> { + fn try_output(&mut self) -> Result> { if self.decided || self.count_accepted() < self.netinfo.num_correct() { return Ok(Step::default()); } diff --git a/src/threshold_decrypt.rs b/src/threshold_decrypt.rs index 372cd4a..7d218e5 100644 --- a/src/threshold_decrypt.rs +++ b/src/threshold_decrypt.rs @@ -80,7 +80,7 @@ pub struct ThresholdDecrypt { terminated: bool, } -pub type Step = ::Step>; +pub type Step = ::DaStep>; impl DistAlgorithm for ThresholdDecrypt { type NodeId = N; diff --git a/src/threshold_sign.rs b/src/threshold_sign.rs index 00d9c0e..4cefb33 100644 --- a/src/threshold_sign.rs +++ b/src/threshold_sign.rs @@ -75,7 +75,7 @@ pub struct ThresholdSign { terminated: bool, } -pub type Step = ::Step>; +pub type Step = ::DaStep>; impl DistAlgorithm for ThresholdSign { type NodeId = N; diff --git a/src/traits.rs b/src/traits.rs index f61ca84..f8884ac 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -57,22 +57,14 @@ impl EpochT for E where E: Copy + Message + Default + Eq + Ord + Serialize + /// catch it, instead of potentially stalling the algorithm. #[must_use = "The algorithm step result must be used."] #[derive(Debug)] -pub struct Step -where - D: DistAlgorithm, - ::NodeId: NodeIdT, -{ - pub output: Vec, - pub fault_log: FaultLog, - pub messages: Vec>, +pub struct Step { + pub output: Vec, + pub fault_log: FaultLog, + pub messages: Vec>, } -impl Default for Step -where - D: DistAlgorithm, - ::NodeId: NodeIdT, -{ - fn default() -> Step { +impl Default for Step { + fn default() -> Self { Step { output: Vec::default(), fault_log: FaultLog::default(), @@ -81,15 +73,12 @@ where } } -impl Step -where - ::NodeId: NodeIdT, -{ +impl Step { /// Creates a new `Step` from the given collections. pub fn new( - output: Vec, - fault_log: FaultLog, - messages: Vec>, + output: Vec, + fault_log: FaultLog, + messages: Vec>, ) -> Self { Step { output, @@ -99,18 +88,17 @@ where } /// Returns the same step, with the given additional output. - pub fn with_output>>(mut self, output: T) -> Self { + pub fn with_output>>(mut self, output: T) -> Self { self.output.extend(output.into()); self } /// Converts `self` into a step of another type, given conversion methods for output and /// messages. - pub fn map(self, f_out: FO, f_msg: FM) -> Step + pub fn map(self, f_out: FO, f_msg: FM) -> Step where - D2: DistAlgorithm, - FO: Fn(D::Output) -> D2::Output, - FM: Fn(D::Message) -> D2::Message, + FO: Fn(O) -> O2, + FM: Fn(M) -> M2, { Step { output: self.output.into_iter().map(f_out).collect(), @@ -120,10 +108,9 @@ where } /// Extends `self` with `other`s messages and fault logs, and returns `other.output`. - pub fn extend_with(&mut self, other: Step, f_msg: FM) -> Vec + pub fn extend_with(&mut self, other: Step, f_msg: FM) -> Vec where - D2: DistAlgorithm, - FM: Fn(D2::Message) -> D::Message, + FM: Fn(M2) -> M, { self.fault_log.extend(other.fault_log); let msgs = other.messages.into_iter().map(|tm| tm.map(&f_msg)); @@ -144,27 +131,14 @@ where self } - /// Converts this step into an equivalent step for a different `DistAlgorithm`. - // This cannot be a `From` impl, because it would conflict with `impl From for T`. - pub fn convert(self) -> Step - where - D2: DistAlgorithm, - { - Step { - output: self.output, - fault_log: self.fault_log, - messages: self.messages, - } - } - /// Returns `true` if there are no messages, faults or outputs. pub fn is_empty(&self) -> bool { self.output.is_empty() && self.fault_log.is_empty() && self.messages.is_empty() } } -impl From> for Step { - fn from(fault_log: FaultLog) -> Self { +impl From> for Step { + fn from(fault_log: FaultLog) -> Self { Step { fault_log, ..Step::default() @@ -172,8 +146,8 @@ impl From> for Step { } } -impl From> for Step { - fn from(fault: Fault) -> Self { +impl From> for Step { + fn from(fault: Fault) -> Self { Step { fault_log: fault.into(), ..Step::default() @@ -181,8 +155,8 @@ impl From> for Step { } } -impl From> for Step { - fn from(msg: TargetedMessage) -> Self { +impl From> for Step { + fn from(msg: TargetedMessage) -> Self { Step { messages: once(msg).collect(), ..Step::default() @@ -190,10 +164,9 @@ impl From> for Step } } -impl From for Step +impl From for Step where - D: DistAlgorithm, - I: IntoIterator>, + I: IntoIterator>, { fn from(msgs: I) -> Self { Step { @@ -233,26 +206,28 @@ impl Epoched for TargetedMessage { } } -impl<'i, D> Step +/// An alias for the type of `Step` returned by `D`'s methods. +pub type DaStep = + Step<::Message, ::Output, ::NodeId>; + +impl<'i, M, O, N> Step where - D: DistAlgorithm, - ::NodeId: NodeIdT + Rand, - ::Message: - 'i + Clone + SenderQueueableMessage + Serialize + DeserializeOwned, + N: NodeIdT + Rand, + M: 'i + Clone + SenderQueueableMessage + Serialize + DeserializeOwned, { /// Removes and returns any messages that are not yet accepted by remote nodes according to the /// mapping `remote_epochs`. This way the returned messages are postponed until later, and the /// remaining messages can be sent to remote nodes without delay. pub fn defer_messages( &mut self, - peer_epochs: &'i BTreeMap::LinEpoch>, + peer_epochs: &'i BTreeMap::LinEpoch>, max_future_epochs: u64, - ) -> Vec<(D::NodeId, D::Message)> + ) -> Vec<(N, M)> where - ::NodeId: 'i, + N: 'i, { let messages = &mut self.messages; - let mut deferred_msgs: Vec<(D::NodeId, D::Message)> = Vec::new(); + let mut deferred_msgs: Vec<(N, M)> = Vec::new(); let mut passed_msgs: Vec<_> = Vec::new(); for msg in messages.drain(..) { match msg.target.clone() { @@ -306,7 +281,7 @@ pub trait DistAlgorithm: Send + Sync { type Error: Fail; /// Handles an input provided by the user, and returns - fn handle_input(&mut self, input: Self::Input) -> Result, Self::Error> + fn handle_input(&mut self, input: Self::Input) -> Result, Self::Error> where Self: Sized; @@ -315,7 +290,7 @@ pub trait DistAlgorithm: Send + Sync { &mut self, sender_id: &Self::NodeId, message: Self::Message, - ) -> Result, Self::Error> + ) -> Result, Self::Error> where Self: Sized; diff --git a/tests/binary_agreement_mitm.rs b/tests/binary_agreement_mitm.rs index 10caa34..7eb651c 100644 --- a/tests/binary_agreement_mitm.rs +++ b/tests/binary_agreement_mitm.rs @@ -16,7 +16,7 @@ use std::sync::{Arc, Mutex}; use hbbft::binary_agreement::{BinaryAgreement, MessageContent, SbvMessage}; use hbbft::threshold_sign::ThresholdSign; -use hbbft::{DistAlgorithm, NetworkInfo, Step}; +use hbbft::{DaStep, DistAlgorithm, NetworkInfo}; use net::adversary::{NetMutHandle, QueuePosition}; use net::err::CrankError; @@ -415,7 +415,7 @@ impl Adversary for AbaCommonCoinAdversary { &mut self, _: NetMutHandle, msg: NetMessage, - ) -> 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 { @@ -430,7 +430,7 @@ impl Adversary for AbaCommonCoinAdversary { self.coin_state = new_coin_state; } } - Ok(Step::default()) + Ok(DaStep::::default()) } } diff --git a/tests/net/adversary.rs b/tests/net/adversary.rs index cdf04de..39530d0 100644 --- a/tests/net/adversary.rs +++ b/tests/net/adversary.rs @@ -38,7 +38,7 @@ use std::{cmp, fmt}; use rand::Rng; -use hbbft::{DistAlgorithm, Step}; +use hbbft::{DaStep, DistAlgorithm}; use net::{CrankError, NetMessage, Node, VirtualNet}; @@ -143,7 +143,7 @@ where } /// Normally dispatch a message - pub fn dispatch_message(&mut self, msg: NetMessage) -> Result, CrankError> { + pub fn dispatch_message(&mut self, msg: NetMessage) -> Result, CrankError> { self.0.dispatch_message(msg) } @@ -336,7 +336,7 @@ where &mut self, mut net: NetMutHandle, msg: NetMessage, - ) -> Result, CrankError> { + ) -> Result, CrankError> { net.dispatch_message(msg) } } diff --git a/tests/net/mod.rs b/tests/net/mod.rs index 7ae54f2..7ac233c 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, DistAlgorithm, NetworkInfo, NodeIdT, Step}; +use hbbft::{self, Contribution, DaStep, DistAlgorithm, NetworkInfo, NodeIdT, Step}; use try_some; @@ -197,7 +197,7 @@ pub type NetMessage = fn process_step<'a, D>( nodes: &'a mut collections::BTreeMap>, sender: D::NodeId, - step: &Step, + step: &DaStep, dest: &mut collections::VecDeque>, ) -> usize where @@ -307,7 +307,7 @@ where /// Number of faulty nodes in the network. num_faulty: usize, /// Dist-algorithm constructor function. - cons: Option) -> (D, Step)>>, + cons: Option) -> (D, DaStep)>>, /// Network adversary. adversary: Option>>, /// Trace-enabling flag. `None` means use environment. @@ -463,7 +463,7 @@ where #[inline] pub fn using_step(mut self, cons: F) -> Self where - F: Fn(NewNodeInfo) -> (D, Step) + 'static, + F: Fn(NewNodeInfo) -> (D, DaStep) + 'static, { self.cons = Some(Box::new(cons)); self @@ -729,7 +729,7 @@ where cons: F, ) -> Result where - F: Fn(NewNodeInfo) -> (D, Step), + F: Fn(NewNodeInfo) -> (D, DaStep), I: IntoIterator, R: rand::Rng, { @@ -789,7 +789,7 @@ where /// /// Retrieves the receiving node for a `msg` and hands over the payload. #[inline] - pub fn dispatch_message(&mut self, msg: NetMessage) -> Result, CrankError> { + pub fn dispatch_message(&mut self, msg: NetMessage) -> Result, CrankError> { let node = self .nodes .get_mut(&msg.to) @@ -816,7 +816,7 @@ where /// /// Panics if `id` does not name a valid node. #[inline] - pub fn send_input(&mut self, id: D::NodeId, input: D::Input) -> Result, D::Error> { + pub fn send_input(&mut self, id: D::NodeId, input: D::Input) -> Result, D::Error> { let step = self .nodes .get_mut(&id) @@ -842,7 +842,7 @@ where /// If a successful `Step` was generated, all of its messages are queued on the network and the /// `Step` is returned. #[inline] - pub fn crank(&mut self) -> Option), CrankError>> { + pub fn crank(&mut self) -> Option), CrankError>> { // Check limits. if let Some(limit) = self.crank_limit { if self.crank_count >= limit { @@ -893,7 +893,7 @@ where .ok_or_else(|| CrankError::NodeDisappeared(msg.to.clone())) ).is_faulty(); - let step: Step<_> = if is_faulty { + let step: Step<_, _, _> = if is_faulty { // The swap-dance is painful here, as we are creating an `opt_step` just to avoid // borrow issues. let mut adv = self.adversary.take(); @@ -932,7 +932,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) -> (D::NodeId, Step) { + pub fn crank_expect(&mut self) -> (D::NodeId, DaStep) { self.crank() .expect("crank: network queue empty") .expect("crank: node failed to process step") @@ -956,7 +956,7 @@ where pub fn broadcast_input<'a>( &'a mut self, input: &'a D::Input, - ) -> Result)>, D::Error> { + ) -> Result)>, D::Error> { // Note: The tricky lifetime annotation basically says that the input value given must // live as long as the iterator returned lives (because it is cloned on every step, // with steps only evaluated each time `next()` is called. For the same reason the @@ -1050,7 +1050,7 @@ where D::Message: Clone, D::Output: Clone, { - type Item = Result<(D::NodeId, Step), CrankError>; + type Item = Result<(D::NodeId, DaStep), CrankError>; #[inline] fn next(&mut self) -> Option { diff --git a/tests/network/mod.rs b/tests/network/mod.rs index bf1254f..bc2960a 100644 --- a/tests/network/mod.rs +++ b/tests/network/mod.rs @@ -10,7 +10,9 @@ use rand_derive::Rand; use serde_derive::{Deserialize, Serialize}; use hbbft::dynamic_honey_badger::Batch; -use hbbft::{Contribution, DistAlgorithm, Fault, NetworkInfo, Step, Target, TargetedMessage}; +use hbbft::{ + Contribution, DaStep, DistAlgorithm, Fault, NetworkInfo, Step, Target, TargetedMessage, +}; /// A node identifier. In the tests, nodes are simply numbered. #[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, Serialize, Deserialize, Rand)] @@ -59,7 +61,7 @@ impl TestNode { } /// Creates a new test node with the given broadcast instance. - fn new((algo, step): (D, Step)) -> TestNode { + fn new((algo, step): (D, DaStep)) -> TestNode { TestNode { id: algo.our_id().clone(), algo, @@ -403,7 +405,7 @@ where new_algo: F, ) -> TestNetwork where - F: Fn(Arc>) -> (D, Step), + F: Fn(Arc>) -> (D, DaStep), G: Fn(BTreeMap>>) -> A, { let mut rng = rand::thread_rng();