removed cloning of FaultLog

This commit is contained in:
Vladimir Komendantskiy 2018-07-16 12:33:00 +01:00
parent 993a164ca9
commit c6a0090859
8 changed files with 21 additions and 12 deletions

View File

@ -138,7 +138,8 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
Broadcast::new(Arc::new(netinfo), 0).expect("failed to instantiate broadcast");
if let Some(v) = value {
broadcast.input(v.clone().into()).expect("propose value");
// FIXME: Use the output.
let _ = broadcast.input(v.clone().into()).expect("propose value");
for msg in broadcast.message_iter() {
tx_from_algo.send(msg).expect("send from algo");
}

View File

@ -502,8 +502,11 @@ impl<NodeUid: Clone + Debug + Ord> Agreement<NodeUid> {
&mut self,
coin_step: CommonCoinStep<NodeUid>,
) -> AgreementResult<FaultLog<NodeUid>> {
let mut fault_log = coin_step.fault_log.clone();
if let Some(coin) = coin_step.output.into_iter().next() {
let Step {
output,
mut fault_log,
} = coin_step;
if let Some(coin) = output.into_iter().next() {
let def_bin_value = self.count_conf().1.definite();
fault_log.extend(self.on_coin(coin, def_bin_value)?);
}

View File

@ -43,6 +43,7 @@
//!
//! ## Example usage
//!
//! FIXME: Fix the test for the new API (Issue #135).
//! ```ignore
//!# extern crate clear_on_drop;
//!# extern crate hbbft;

View File

@ -255,7 +255,6 @@ impl<NodeUid: Clone + Debug + Ord + Rand> CommonSubset<NodeUid> {
self.broadcast_results.insert(proposer_id.clone(), value);
let set_agreement_input = |agreement: &mut Agreement<NodeUid>| {
if agreement.accepts_input() {
// FIXME: Use the result.
agreement.input(true)
} else {
Ok(Step::default())

View File

@ -554,8 +554,11 @@ where
&mut self,
step: CommonSubsetStep<NodeUid>,
) -> HoneyBadgerResult<FaultLog<NodeUid>> {
let mut fault_log = step.fault_log.clone();
for cs_output in step.output {
let Step {
output,
mut fault_log,
} = step;
for cs_output in output {
fault_log.extend(self.send_decryption_shares(cs_output)?);
// TODO: May also check that there is no further output from Common Subset.
}

View File

@ -53,6 +53,7 @@ impl<M, N> TargetedMessage<M, N> {
/// Result of one step of the local state machine of a distributed algorithm. Such a result should
/// be used and never discarded by the client of the algorithm.
#[must_use = "The algorithm step result must be used."]
pub struct Step<N, O>
where
N: Clone,
@ -97,14 +98,12 @@ pub trait DistAlgorithm {
type Error: Debug;
/// Handles an input provided by the user, and returns
#[must_use]
fn input(
&mut self,
input: Self::Input,
) -> Result<Step<Self::NodeUid, Self::Output>, Self::Error>;
/// Handles a message received from node `sender_id`.
#[must_use]
fn handle_message(
&mut self,
sender_id: &Self::NodeUid,

View File

@ -157,9 +157,11 @@ where
sender_id: &NodeUid,
message: Self::Message,
) -> Result<QueueingHoneyBadgerStep<Tx, NodeUid>> {
let step = self.dyn_hb.handle_message(sender_id, message)?;
let mut fault_log = step.fault_log.clone();
for batch in step.output {
let Step {
output,
mut fault_log,
} = self.dyn_hb.handle_message(sender_id, message)?;
for batch in output {
self.queue.remove_all(batch.iter());
self.output.push_back(batch);
}

View File

@ -88,7 +88,8 @@ impl Adversary<Broadcast<NodeUid>> for ProposeAdversary {
pk_set,
));
let mut bc = Broadcast::new(netinfo, id).expect("broadcast instance");
bc.input(b"Fake news".to_vec()).expect("propose");
// FIXME: Use the output.
let _ = bc.input(b"Fake news".to_vec()).expect("propose");
bc.message_iter()
.map(|msg| MessageWithSender::new(id, msg))
.collect()