mirror of https://github.com/poanetwork/hbbft.git
Switch to 2018 edition idioms (#359)
* Switch to 2018 edition idioms * Fix build with Rust 2018. * Remove unnecessary cloning, make `max_faulty` const. * Remove unneeded `extern crate` statements.
This commit is contained in:
parent
c1c7ffff49
commit
7fb172cda2
|
@ -1,6 +1,6 @@
|
|||
language: rust
|
||||
rust:
|
||||
- 1.30.0
|
||||
- 1.31.0
|
||||
cache:
|
||||
cargo: true
|
||||
timeout: 1200
|
||||
|
|
|
@ -15,6 +15,7 @@ license = "MIT/Apache-2.0"
|
|||
readme = "README.md"
|
||||
repository = "https://github.com/poanetwork/hbbft"
|
||||
description = "The Honey Badger of Byzantine Fault Tolerant Consensus Protocols"
|
||||
edition = "2018"
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "poanetwork/hbbft" }
|
||||
|
|
|
@ -1,14 +1,5 @@
|
|||
//! Example of a consensus node that uses the `hbbft::node::Node` struct for
|
||||
//! running the distributed consensus state machine.
|
||||
extern crate bincode;
|
||||
extern crate crossbeam;
|
||||
extern crate crossbeam_channel;
|
||||
extern crate docopt;
|
||||
extern crate env_logger;
|
||||
extern crate hbbft;
|
||||
extern crate log;
|
||||
extern crate serde;
|
||||
extern crate threshold_crypto as crypto;
|
||||
|
||||
mod network;
|
||||
|
||||
|
@ -18,7 +9,7 @@ use std::vec::Vec;
|
|||
|
||||
use docopt::Docopt;
|
||||
|
||||
use network::node::Node;
|
||||
use crate::network::node::Node;
|
||||
|
||||
const VERSION: &str = "0.1.0";
|
||||
const USAGE: &str = "
|
||||
|
|
|
@ -78,7 +78,8 @@ impl<'a, M: Serialize + DeserializeOwned + Send + 'a> CommsTask<'a, M> {
|
|||
tx.send(SourcedMessage {
|
||||
source: node_index,
|
||||
message,
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
Err(err) => {
|
||||
if let bincode::ErrorKind::Io(ref io_err) = *err {
|
||||
|
|
|
@ -41,6 +41,7 @@ pub fn make(
|
|||
TcpStream::connect(address).expect("failed to connect")
|
||||
};
|
||||
Connection::new(tcp_conn, there_str.to_string())
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
(here_str, connections)
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
//! The following code could be run on host 192.168.1.1:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! extern crate hbbft;
|
||||
//!
|
||||
//! use hbbft::node::Node;
|
||||
//! use std::net::SocketAddr;
|
||||
//! use std::vec::Vec;
|
||||
|
@ -42,14 +40,13 @@ use std::sync::Arc;
|
|||
use std::{iter, process, thread, time};
|
||||
|
||||
use crossbeam;
|
||||
use crypto::poly::Poly;
|
||||
use crypto::{SecretKey, SecretKeySet};
|
||||
use log::{debug, error};
|
||||
|
||||
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 network::messaging::Messaging;
|
||||
use network::{commst, connection};
|
||||
|
||||
/// This is a structure to start a consensus node.
|
||||
pub struct Node<T> {
|
||||
|
@ -172,7 +169,8 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
|
|||
// FIXME: handle error
|
||||
c.stream.try_clone().unwrap(),
|
||||
node_index,
|
||||
).run()
|
||||
)
|
||||
.run()
|
||||
{
|
||||
Ok(_) => debug!("Comms task {} succeeded", node_index),
|
||||
Err(e) => error!("Comms task {}: {:?}", node_index, e),
|
||||
|
@ -192,7 +190,8 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
|
|||
.send(())
|
||||
.map_err(|e| {
|
||||
error!("{}", e);
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
process::exit(0);
|
||||
}) // end of thread scope
|
||||
|
|
|
@ -1,15 +1,3 @@
|
|||
extern crate bincode;
|
||||
extern crate colored;
|
||||
extern crate docopt;
|
||||
extern crate env_logger;
|
||||
extern crate hbbft;
|
||||
extern crate itertools;
|
||||
extern crate rand;
|
||||
extern crate rand_derive;
|
||||
extern crate serde;
|
||||
extern crate serde_derive;
|
||||
extern crate signifix;
|
||||
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{cmp, u64};
|
||||
|
@ -156,7 +144,8 @@ where
|
|||
target: msg.target,
|
||||
message: ser_msg,
|
||||
}
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
let outputs = step
|
||||
.output
|
||||
.into_iter()
|
||||
|
@ -203,7 +192,8 @@ where
|
|||
.map(|msg| {
|
||||
let ser_msg = bincode::serialize(&msg.message).expect("serialize");
|
||||
(msg.target, ser_msg)
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
self.time += start.elapsed() * self.hw_quality.cpu_factor / 100;
|
||||
let time = self.time;
|
||||
self.outputs
|
||||
|
|
|
@ -2,17 +2,17 @@ use std::collections::BTreeMap;
|
|||
use std::sync::Arc;
|
||||
use std::{fmt, result};
|
||||
|
||||
use crate::crypto::SignatureShare;
|
||||
use bincode;
|
||||
use crypto::SignatureShare;
|
||||
use log::debug;
|
||||
|
||||
use super::bool_multimap::BoolMultimap;
|
||||
use super::bool_set::{self, BoolSet};
|
||||
use super::sbv_broadcast::{self, Message as SbvMessage, SbvBroadcast};
|
||||
use super::{Error, Message, MessageContent, Result, Step};
|
||||
use fault_log::{Fault, FaultKind};
|
||||
use threshold_sign::{self, Message as TsMessage, ThresholdSign};
|
||||
use {DistAlgorithm, NetworkInfo, NodeIdT, SessionIdT, Target};
|
||||
use crate::fault_log::{Fault, FaultKind};
|
||||
use crate::threshold_sign::{self, Message as TsMessage, ThresholdSign};
|
||||
use crate::{DistAlgorithm, 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`.
|
||||
|
|
|
@ -75,7 +75,7 @@ use rand_derive::Rand;
|
|||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use self::bool_set::BoolSet;
|
||||
use threshold_sign;
|
||||
use crate::threshold_sign;
|
||||
|
||||
pub use self::binary_agreement::BinaryAgreement;
|
||||
pub use self::sbv_broadcast::Message as SbvMessage;
|
||||
|
@ -105,7 +105,7 @@ impl From<bincode::Error> for Error {
|
|||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
/// A `BinaryAgreement` step, containing at most one output.
|
||||
pub type Step<N> = ::Step<Message, bool, N>;
|
||||
pub type Step<N> = crate::Step<Message, bool, N>;
|
||||
|
||||
/// The content of a message belonging to a particular `BinaryAgreement` epoch.
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
|
|
|
@ -17,10 +17,10 @@ use serde_derive::{Deserialize, Serialize};
|
|||
use super::bool_multimap::BoolMultimap;
|
||||
use super::bool_set::{self, BoolSet};
|
||||
use super::Result;
|
||||
use fault_log::{Fault, FaultKind};
|
||||
use {NetworkInfo, NodeIdT, Target};
|
||||
use crate::fault_log::{Fault, FaultKind};
|
||||
use crate::{NetworkInfo, NodeIdT, Target};
|
||||
|
||||
pub type Step<N> = ::Step<Message, BoolSet, N>;
|
||||
pub type Step<N> = crate::Step<Message, BoolSet, N>;
|
||||
|
||||
/// A message belonging to the Synchronized Binary Value Broadcast phase of a `BinaryAgreement`
|
||||
/// epoch.
|
||||
|
|
|
@ -11,8 +11,8 @@ use reed_solomon_erasure::ReedSolomon;
|
|||
use super::merkle::{Digest, MerkleTree, Proof};
|
||||
use super::message::HexProof;
|
||||
use super::{Error, Message, Result};
|
||||
use fault_log::{Fault, FaultKind};
|
||||
use {DistAlgorithm, NetworkInfo, NodeIdT, Target};
|
||||
use crate::fault_log::{Fault, FaultKind};
|
||||
use crate::{DistAlgorithm, NetworkInfo, NodeIdT, Target};
|
||||
|
||||
/// Broadcast algorithm instance.
|
||||
#[derive(Debug)]
|
||||
|
@ -38,7 +38,7 @@ pub struct Broadcast<N> {
|
|||
}
|
||||
|
||||
/// A `Broadcast` step, containing at most one output.
|
||||
pub type Step<N> = ::DaStep<Broadcast<N>>;
|
||||
pub type Step<N> = crate::DaStep<Broadcast<N>>;
|
||||
|
||||
impl<N: NodeIdT> DistAlgorithm for Broadcast<N> {
|
||||
type NodeId = N;
|
||||
|
@ -327,7 +327,8 @@ impl<N: NodeIdT> Broadcast<N> {
|
|||
None
|
||||
}
|
||||
})
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
if let Some(value) = self.decode_from_shards(&mut leaf_values, hash) {
|
||||
self.decided = true;
|
||||
Ok(Step::default().with_output(value))
|
||||
|
|
|
@ -15,10 +15,7 @@ pub enum Error {
|
|||
CodingReconstructShardsReedSolomon(#[cause] rse::Error),
|
||||
/// Failed to reconstruct the value.
|
||||
// TODO: This should be unreachable.
|
||||
#[fail(
|
||||
display = "CodingReconstructShardsTrivialReedSolomon error: {}",
|
||||
_0
|
||||
)]
|
||||
#[fail(display = "CodingReconstructShardsTrivialReedSolomon error: {}", _0)]
|
||||
CodingReconstructShardsTrivialReedSolomon(#[cause] rse::Error),
|
||||
/// Observers cannot propose a value.
|
||||
#[fail(display = "Instance cannot propose")]
|
||||
|
|
|
@ -90,9 +90,6 @@
|
|||
//! node, and that it did so exactly once.
|
||||
//!
|
||||
//! ```
|
||||
//! extern crate hbbft;
|
||||
//! extern crate rand;
|
||||
//!
|
||||
//! use hbbft::broadcast::{Broadcast, Error, Step};
|
||||
//! use hbbft::{NetworkInfo, SourcedMessage, Target, TargetedMessage};
|
||||
//! use rand::{thread_rng, Rng};
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::collections::BTreeMap;
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::{ChangeState, JoinPlan, Params};
|
||||
use {NetworkInfo, NodeIdT};
|
||||
use crate::{NetworkInfo, NodeIdT};
|
||||
|
||||
/// A batch of transactions the algorithm has output.
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::iter::once;
|
|||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crypto::{SecretKey, SecretKeySet};
|
||||
use crate::crypto::{SecretKey, SecretKeySet};
|
||||
use rand::{self, Rand, Rng};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use super::{DynamicHoneyBadger, EncryptionSchedule, JoinPlan, Result, Step, VoteCounter};
|
||||
use honey_badger::{HoneyBadger, Params, SubsetHandlingStrategy};
|
||||
use util::SubRng;
|
||||
use {Contribution, NetworkInfo, NodeIdT};
|
||||
use crate::honey_badger::{HoneyBadger, Params, SubsetHandlingStrategy};
|
||||
use crate::util::SubRng;
|
||||
use crate::{Contribution, NetworkInfo, NodeIdT};
|
||||
|
||||
/// A Dynamic Honey Badger builder, to configure the parameters and create new instances of
|
||||
/// `DynamicHoneyBadger`.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use crypto::PublicKey;
|
||||
use crate::crypto::PublicKey;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use super::EncryptionSchedule;
|
||||
|
|
|
@ -2,8 +2,8 @@ use std::collections::BTreeMap;
|
|||
use std::sync::Arc;
|
||||
use std::{fmt, result};
|
||||
|
||||
use crate::crypto::{PublicKey, SecretKey, Signature};
|
||||
use bincode;
|
||||
use crypto::{PublicKey, SecretKey, Signature};
|
||||
use derivative::Derivative;
|
||||
use log::debug;
|
||||
use rand::{self, Rand, Rng};
|
||||
|
@ -15,12 +15,12 @@ use super::{
|
|||
InternalContrib, JoinPlan, KeyGenMessage, KeyGenState, Message, Params, Result,
|
||||
SignedKeyGenMsg, Step,
|
||||
};
|
||||
use fault_log::{Fault, FaultKind, FaultLog};
|
||||
use honey_badger::{self, HoneyBadger, Message as HbMessage};
|
||||
use crate::fault_log::{Fault, FaultKind, FaultLog};
|
||||
use crate::honey_badger::{self, HoneyBadger, Message as HbMessage};
|
||||
|
||||
use sync_key_gen::{Ack, AckOutcome, Part, PartOutcome, SyncKeyGen};
|
||||
use util::{self, SubRng};
|
||||
use {Contribution, DistAlgorithm, Epoched, NetworkInfo, NodeIdT, Target};
|
||||
use crate::sync_key_gen::{Ack, AckOutcome, Part, PartOutcome, SyncKeyGen};
|
||||
use crate::util::{self, SubRng};
|
||||
use crate::{Contribution, DistAlgorithm, Epoched, NetworkInfo, NodeIdT, Target};
|
||||
|
||||
/// A Honey Badger instance that can handle adding and removing nodes.
|
||||
#[derive(Derivative)]
|
||||
|
@ -154,7 +154,8 @@ where
|
|||
contrib,
|
||||
key_gen_messages,
|
||||
votes: self.vote_counter.pending_votes().cloned().collect(),
|
||||
}).map_err(Error::ProposeHoneyBadger)?;
|
||||
})
|
||||
.map_err(Error::ProposeHoneyBadger)?;
|
||||
self.process_output(step)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use bincode;
|
||||
use failure::Fail;
|
||||
|
||||
use honey_badger;
|
||||
use sync_key_gen;
|
||||
use crate::honey_badger;
|
||||
use crate::sync_key_gen;
|
||||
|
||||
/// Dynamic honey badger error variants.
|
||||
#[derive(Debug, Fail)]
|
||||
|
@ -14,10 +14,7 @@ pub enum Error {
|
|||
#[fail(display = "Error serializing a vote: {}", _0)]
|
||||
SerializeVote(bincode::ErrorKind),
|
||||
/// Failed to propose a contribution in `HoneyBadger`.
|
||||
#[fail(
|
||||
display = "Error proposing a contribution in HoneyBadger: {}",
|
||||
_0
|
||||
)]
|
||||
#[fail(display = "Error proposing a contribution in HoneyBadger: {}", _0)]
|
||||
ProposeHoneyBadger(honey_badger::Error),
|
||||
/// Failed to handle a `HoneyBadger` message.
|
||||
#[fail(display = "Error handling a HoneyBadger message: {}", _0)]
|
||||
|
|
|
@ -74,14 +74,14 @@ mod votes;
|
|||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crypto::{PublicKey, PublicKeySet, Signature};
|
||||
use crate::crypto::{PublicKey, PublicKeySet, Signature};
|
||||
use rand::Rand;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use self::votes::{SignedVote, VoteCounter};
|
||||
use honey_badger::{EncryptionSchedule, Message as HbMessage, Params};
|
||||
use sync_key_gen::{Ack, Part, SyncKeyGen};
|
||||
use NodeIdT;
|
||||
use crate::honey_badger::{EncryptionSchedule, Message as HbMessage, Params};
|
||||
use crate::sync_key_gen::{Ack, Part, SyncKeyGen};
|
||||
use crate::NodeIdT;
|
||||
|
||||
pub use self::batch::Batch;
|
||||
pub use self::builder::DynamicHoneyBadgerBuilder;
|
||||
|
@ -90,7 +90,7 @@ pub use self::dynamic_honey_badger::DynamicHoneyBadger;
|
|||
pub use self::error::{Error, Result};
|
||||
|
||||
/// A `DynamicHoneyBadger` step, possibly containing multiple outputs.
|
||||
pub type Step<C, N> = ::DaStep<DynamicHoneyBadger<C, N>>;
|
||||
pub type Step<C, N> = crate::DaStep<DynamicHoneyBadger<C, N>>;
|
||||
|
||||
/// The user input for `DynamicHoneyBadger`.
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::crypto::Signature;
|
||||
use bincode;
|
||||
use crypto::Signature;
|
||||
use serde::Serialize;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use super::{Change, Error, Result};
|
||||
use fault_log::{FaultKind, FaultLog};
|
||||
use {NetworkInfo, NodeIdT};
|
||||
use crate::fault_log::{FaultKind, FaultLog};
|
||||
use crate::{NetworkInfo, NodeIdT};
|
||||
|
||||
/// A buffer and counter collecting pending and committed votes for validator set changes.
|
||||
///
|
||||
|
@ -65,10 +65,11 @@ where
|
|||
sender_id: &N,
|
||||
signed_vote: SignedVote<N>,
|
||||
) -> Result<FaultLog<N>> {
|
||||
if signed_vote.vote.era != self.era || self
|
||||
.pending
|
||||
.get(&signed_vote.voter)
|
||||
.map_or(false, |sv| sv.vote.num >= signed_vote.vote.num)
|
||||
if signed_vote.vote.era != self.era
|
||||
|| self
|
||||
.pending
|
||||
.get(&signed_vote.voter)
|
||||
.map_or(false, |sv| sv.vote.num >= signed_vote.vote.num)
|
||||
{
|
||||
return Ok(FaultLog::new()); // The vote is obsolete or already exists.
|
||||
}
|
||||
|
@ -190,9 +191,9 @@ mod tests {
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::{Change, SignedVote, VoteCounter};
|
||||
use fault_log::{FaultKind, FaultLog};
|
||||
use crate::fault_log::{FaultKind, FaultLog};
|
||||
use crate::NetworkInfo;
|
||||
use rand;
|
||||
use NetworkInfo;
|
||||
|
||||
/// Returns a vector of `node_num` `VoteCounter`s, and some signed example votes.
|
||||
///
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! calling algorithm via `DistAlgorihm`'s `.handle_input()` and
|
||||
//! `.handle_message()` trait methods.
|
||||
|
||||
pub use sync_key_gen::{AckFault, PartFault};
|
||||
pub use crate::sync_key_gen::{AckFault, PartFault};
|
||||
|
||||
/// Represents each reason why a node could be considered faulty.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use NodeIdT;
|
||||
use crate::NodeIdT;
|
||||
|
||||
/// A batch of contributions the algorithm has output.
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -6,8 +6,8 @@ use rand::{self, Rand, Rng};
|
|||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use super::{EncryptionSchedule, HoneyBadger, Params, SubsetHandlingStrategy};
|
||||
use util::SubRng;
|
||||
use {Contribution, NetworkInfo, NodeIdT};
|
||||
use crate::util::SubRng;
|
||||
use crate::{Contribution, NetworkInfo, NodeIdT};
|
||||
|
||||
/// A Honey Badger builder, to configure the parameters and create new instances of `HoneyBadger`.
|
||||
pub struct HoneyBadgerBuilder<C, N> {
|
||||
|
|
|
@ -6,18 +6,18 @@ use std::mem::replace;
|
|||
use std::result;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::crypto::Ciphertext;
|
||||
use bincode;
|
||||
use crypto::Ciphertext;
|
||||
use log::error;
|
||||
use rand::{Rand, Rng};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use super::{Batch, Error, MessageContent, Result, Step};
|
||||
use fault_log::{Fault, FaultKind, FaultLog};
|
||||
use subset::{self as cs, Subset, SubsetOutput};
|
||||
use threshold_decrypt::{self as td, ThresholdDecrypt};
|
||||
use {Contribution, DistAlgorithm, NetworkInfo, NodeIdT};
|
||||
use crate::fault_log::{Fault, FaultKind, FaultLog};
|
||||
use crate::subset::{self as cs, Subset, SubsetOutput};
|
||||
use crate::threshold_decrypt::{self as td, ThresholdDecrypt};
|
||||
use crate::{Contribution, DistAlgorithm, NetworkInfo, NodeIdT};
|
||||
|
||||
type CsStep<N> = cs::Step<N>;
|
||||
|
||||
|
@ -77,7 +77,8 @@ where
|
|||
match self {
|
||||
SubsetState::Ongoing(ref mut cs) => cs.handle_input(proposal),
|
||||
SubsetState::Complete(_) => return Ok(cs::Step::default()),
|
||||
}.map_err(Error::InputSubset)
|
||||
}
|
||||
.map_err(Error::InputSubset)
|
||||
}
|
||||
|
||||
/// Handles a message in the Subset instance, unless it has already completed.
|
||||
|
@ -85,7 +86,8 @@ where
|
|||
match self {
|
||||
SubsetState::Ongoing(ref mut cs) => cs.handle_message(sender_id, msg),
|
||||
SubsetState::Complete(_) => return Ok(cs::Step::default()),
|
||||
}.map_err(Error::HandleSubsetMessage)
|
||||
}
|
||||
.map_err(Error::HandleSubsetMessage)
|
||||
}
|
||||
|
||||
/// Returns the number of contributions that we have already received or, after completion, how
|
||||
|
@ -269,7 +271,8 @@ where
|
|||
Entry::Vacant(entry) => {
|
||||
entry.insert(DecryptionState::new(self.netinfo.clone()))
|
||||
}
|
||||
}.handle_message(sender_id, share)
|
||||
}
|
||||
.handle_message(sender_id, share)
|
||||
.map_err(Error::ThresholdDecrypt)?;
|
||||
self.process_decryption(proposer_id, td_step)
|
||||
}
|
||||
|
@ -364,7 +367,8 @@ where
|
|||
MessageContent::DecryptionShare {
|
||||
proposer_id: proposer_id.clone(),
|
||||
share,
|
||||
}.with_epoch(self.epoch)
|
||||
}
|
||||
.with_epoch(self.epoch)
|
||||
});
|
||||
if let Some(output) = opt_output.into_iter().next() {
|
||||
self.decryption
|
||||
|
@ -385,7 +389,8 @@ where
|
|||
let td_result = match self.decryption.entry(proposer_id.clone()) {
|
||||
Entry::Occupied(entry) => entry.into_mut(),
|
||||
Entry::Vacant(entry) => entry.insert(DecryptionState::new(self.netinfo.clone())),
|
||||
}.set_ciphertext(ciphertext);
|
||||
}
|
||||
.set_ciphertext(ciphertext);
|
||||
match td_result {
|
||||
Ok(td_step) => self.process_decryption(proposer_id, td_step),
|
||||
Err(td::Error::InvalidCiphertext(_)) => {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use bincode;
|
||||
use failure::Fail;
|
||||
|
||||
use subset;
|
||||
use threshold_decrypt;
|
||||
use crate::subset;
|
||||
use crate::threshold_decrypt;
|
||||
|
||||
/// Honey badger error variants.
|
||||
#[derive(Debug, Fail)]
|
||||
|
|
|
@ -9,7 +9,7 @@ use serde_derive::{Deserialize, Serialize};
|
|||
|
||||
use super::epoch_state::EpochState;
|
||||
use super::{Batch, Error, HoneyBadgerBuilder, Message, Result};
|
||||
use {util, Contribution, DistAlgorithm, Fault, FaultKind, NetworkInfo, NodeIdT};
|
||||
use crate::{util, Contribution, DistAlgorithm, Fault, FaultKind, NetworkInfo, NodeIdT};
|
||||
|
||||
use super::Params;
|
||||
|
||||
|
@ -37,7 +37,7 @@ pub struct HoneyBadger<C, N: Rand> {
|
|||
}
|
||||
|
||||
/// A `HoneyBadger` step, possibly containing multiple outputs.
|
||||
pub type Step<C, N> = ::DaStep<HoneyBadger<C, N>>;
|
||||
pub type Step<C, N> = crate::DaStep<HoneyBadger<C, N>>;
|
||||
|
||||
impl<C, N> DistAlgorithm for HoneyBadger<C, N>
|
||||
where
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
// `threshold_sign::Message` triggers this Clippy lint, but `Box<T>` doesn't implement `Rand`.
|
||||
#![allow(clippy::large_enum_variant)]
|
||||
|
||||
use rand::Rand;
|
||||
use rand_derive::Rand;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use subset;
|
||||
use threshold_decrypt;
|
||||
use crate::subset;
|
||||
use crate::threshold_decrypt;
|
||||
|
||||
/// The content of a `HoneyBadger` message. It should be further annotated with an epoch.
|
||||
#[derive(Clone, Debug, Deserialize, Rand, Serialize)]
|
||||
// `threshold_sign::Message` triggers this Clippy lint, but `Box<T>` doesn't implement `Rand`.
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
|
||||
pub enum MessageContent<N: Rand> {
|
||||
/// A message belonging to the subset algorithm in the given epoch.
|
||||
Subset(subset::Message<N>),
|
||||
|
|
27
src/lib.rs
27
src/lib.rs
|
@ -115,23 +115,10 @@
|
|||
//! types.
|
||||
|
||||
// We put algorithm structs in `src/algorithm/algorithm.rs`.
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(module_inception))]
|
||||
// Some of our constructors return results.
|
||||
#![allow(clippy::module_inception, clippy::new_ret_no_self)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
extern crate bincode;
|
||||
extern crate byteorder;
|
||||
extern crate derivative;
|
||||
extern crate failure;
|
||||
extern crate hex_fmt;
|
||||
extern crate init_with;
|
||||
extern crate log;
|
||||
extern crate rand;
|
||||
extern crate rand_derive;
|
||||
extern crate reed_solomon_erasure;
|
||||
extern crate serde;
|
||||
extern crate serde_derive;
|
||||
extern crate tiny_keccak;
|
||||
|
||||
pub extern crate threshold_crypto as crypto;
|
||||
|
||||
mod fault_log;
|
||||
|
@ -152,10 +139,10 @@ pub mod threshold_sign;
|
|||
pub mod transaction_queue;
|
||||
pub mod util;
|
||||
|
||||
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::{
|
||||
pub use crate::crypto::pairing;
|
||||
pub use crate::fault_log::{Fault, FaultKind, 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,
|
||||
};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use crypto::{self, PublicKey, PublicKeySet, PublicKeyShare, SecretKey, SecretKeyShare};
|
||||
use crate::crypto::{self, PublicKey, PublicKeySet, PublicKeyShare, SecretKey, SecretKeyShare};
|
||||
use rand;
|
||||
|
||||
use {util, NodeIdT};
|
||||
use crate::{util, NodeIdT};
|
||||
|
||||
/// Common data shared between algorithms: the nodes' IDs and key shares.
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -162,7 +162,7 @@ impl<N: NodeIdT> NetworkInfo<N> {
|
|||
I: IntoIterator<Item = N>,
|
||||
R: rand::Rng,
|
||||
{
|
||||
use crypto::SecretKeySet;
|
||||
use crate::crypto::SecretKeySet;
|
||||
|
||||
let all_ids: BTreeSet<N> = ids.into_iter().collect();
|
||||
let num_faulty = util::max_faulty(all_ids.len());
|
||||
|
|
|
@ -25,17 +25,17 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::{cmp, iter};
|
||||
|
||||
use crypto::PublicKey;
|
||||
use crate::crypto::PublicKey;
|
||||
use derivative::Derivative;
|
||||
use failure::Fail;
|
||||
use rand::{Rand, Rng};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use dynamic_honey_badger::{self, Batch as DhbBatch, DynamicHoneyBadger, Message};
|
||||
use transaction_queue::TransactionQueue;
|
||||
use {util, Contribution, DistAlgorithm, NetworkInfo, NodeIdT};
|
||||
use crate::dynamic_honey_badger::{self, Batch as DhbBatch, DynamicHoneyBadger, Message};
|
||||
use crate::transaction_queue::TransactionQueue;
|
||||
use crate::{util, Contribution, DistAlgorithm, NetworkInfo, NodeIdT};
|
||||
|
||||
pub use dynamic_honey_badger::{Change, ChangeState, Input};
|
||||
pub use crate::dynamic_honey_badger::{Change, ChangeState, Input};
|
||||
|
||||
/// Queueing honey badger error variants.
|
||||
#[derive(Debug, Fail)]
|
||||
|
@ -149,7 +149,7 @@ pub struct QueueingHoneyBadger<T, N: Rand + Ord, Q> {
|
|||
}
|
||||
|
||||
/// A `QueueingHoneyBadger` step, possibly containing multiple outputs.
|
||||
pub type Step<T, N> = ::Step<Message<N>, Batch<T, N>, N>;
|
||||
pub type Step<T, N> = crate::Step<Message<N>, Batch<T, N>, N>;
|
||||
|
||||
impl<T, N, Q> DistAlgorithm for QueueingHoneyBadger<T, N, Q>
|
||||
where
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
use std::result;
|
||||
|
||||
use crypto::PublicKey;
|
||||
use crate::crypto::PublicKey;
|
||||
use rand::Rand;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use super::{
|
||||
SenderQueue, SenderQueueableDistAlgorithm, SenderQueueableMessage, SenderQueueableOutput,
|
||||
};
|
||||
use {Contribution, DaStep, NodeIdT};
|
||||
use crate::{Contribution, DaStep, NodeIdT};
|
||||
|
||||
use dynamic_honey_badger::{
|
||||
use crate::dynamic_honey_badger::{
|
||||
Batch, Change, ChangeState, DynamicHoneyBadger, Error as DhbError, Message,
|
||||
};
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ use rand::Rand;
|
|||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use super::{SenderQueueableDistAlgorithm, SenderQueueableMessage, SenderQueueableOutput};
|
||||
use honey_badger::{Batch, HoneyBadger, Message};
|
||||
use {Contribution, Epoched, NodeIdT};
|
||||
use crate::honey_badger::{Batch, HoneyBadger, Message};
|
||||
use crate::{Contribution, Epoched, NodeIdT};
|
||||
|
||||
impl<C, N> SenderQueueableOutput<N, Message<N>> for Batch<C, N>
|
||||
where
|
||||
|
|
|
@ -13,8 +13,8 @@ mod queueing_honey_badger;
|
|||
use std::collections::BTreeMap;
|
||||
use std::fmt::Debug;
|
||||
|
||||
use traits::EpochT;
|
||||
use {DaStep, DistAlgorithm, Epoched, NodeIdT, Target};
|
||||
use crate::traits::EpochT;
|
||||
use crate::{DaStep, DistAlgorithm, Epoched, NodeIdT, Target};
|
||||
|
||||
pub use self::message::Message;
|
||||
|
||||
|
@ -84,7 +84,7 @@ where
|
|||
}
|
||||
|
||||
/// A `SenderQueue` step. The output corresponds to the wrapped algorithm.
|
||||
pub type Step<D> = ::DaStep<SenderQueue<D>>;
|
||||
pub type Step<D> = crate::DaStep<SenderQueue<D>>;
|
||||
|
||||
impl<D> DistAlgorithm for SenderQueue<D>
|
||||
where
|
||||
|
@ -181,7 +181,8 @@ where
|
|||
if *e < epoch {
|
||||
*e = epoch;
|
||||
}
|
||||
}).or_insert(epoch);
|
||||
})
|
||||
.or_insert(epoch);
|
||||
self.process_new_epoch(sender_id, epoch)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
use std::result;
|
||||
|
||||
use crypto::PublicKey;
|
||||
use crate::crypto::PublicKey;
|
||||
use rand::Rand;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use super::{SenderQueue, SenderQueueableDistAlgorithm};
|
||||
use queueing_honey_badger::{Change, Error as QhbError, QueueingHoneyBadger};
|
||||
use transaction_queue::TransactionQueue;
|
||||
use {Contribution, DaStep, Epoched, NodeIdT};
|
||||
use crate::queueing_honey_badger::{Change, Error as QhbError, QueueingHoneyBadger};
|
||||
use crate::transaction_queue::TransactionQueue;
|
||||
use crate::{Contribution, DaStep, Epoched, NodeIdT};
|
||||
|
||||
impl<T, N, Q> Epoched for QueueingHoneyBadger<T, N, Q>
|
||||
where
|
||||
|
|
|
@ -2,8 +2,8 @@ use failure::Fail;
|
|||
|
||||
use std::result;
|
||||
|
||||
use binary_agreement;
|
||||
use broadcast;
|
||||
use crate::binary_agreement;
|
||||
use crate::broadcast;
|
||||
|
||||
/// A subset error.
|
||||
#[derive(Clone, PartialEq, Debug, Fail)]
|
||||
|
@ -18,10 +18,7 @@ pub enum Error {
|
|||
#[fail(display = "Error handling Broadcast input/message: {}", _0)]
|
||||
HandleBroadcast(broadcast::Error),
|
||||
/// Error handling a `BinaryAgreement` input or message.
|
||||
#[fail(
|
||||
display = "Error handling BinaryAgreement input/message: {}",
|
||||
_0
|
||||
)]
|
||||
#[fail(display = "Error handling BinaryAgreement input/message: {}", _0)]
|
||||
HandleAgreement(binary_agreement::Error),
|
||||
/// Unknown proposer.
|
||||
#[fail(display = "Unknown proposer ID")]
|
||||
|
|
|
@ -2,8 +2,8 @@ use rand::Rand;
|
|||
use rand_derive::Rand;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use binary_agreement;
|
||||
use broadcast;
|
||||
use crate::binary_agreement;
|
||||
use crate::broadcast;
|
||||
|
||||
/// Message from Subset to remote nodes.
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Rand)]
|
||||
|
|
|
@ -3,16 +3,16 @@ use std::sync::Arc;
|
|||
|
||||
use super::subset::BaSessionId;
|
||||
use super::{Error, MessageContent, Result};
|
||||
use binary_agreement;
|
||||
use broadcast::{self, Broadcast};
|
||||
use crate::binary_agreement;
|
||||
use crate::broadcast::{self, Broadcast};
|
||||
use crate::{NetworkInfo, NodeIdT, SessionIdT};
|
||||
use rand::Rand;
|
||||
use {NetworkInfo, NodeIdT, SessionIdT};
|
||||
|
||||
type BaInstance<N, S> = binary_agreement::BinaryAgreement<N, BaSessionId<S>>;
|
||||
type ValueAndStep<N> = (Option<Vec<u8>>, Step<N>);
|
||||
type BaResult<N> = binary_agreement::Result<binary_agreement::Step<N>>;
|
||||
|
||||
pub type Step<N> = ::Step<MessageContent, Vec<u8>, N>;
|
||||
pub type Step<N> = crate::Step<MessageContent, Vec<u8>, N>;
|
||||
|
||||
/// The state of a proposal's broadcast and agreement process.
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -9,11 +9,11 @@ use serde_derive::Serialize;
|
|||
|
||||
use super::proposal_state::{ProposalState, Step as ProposalStep};
|
||||
use super::{Error, Message, MessageContent, Result};
|
||||
use crate::{util, DistAlgorithm, NetworkInfo, NodeIdT, SessionIdT};
|
||||
use rand::Rand;
|
||||
use {util, DistAlgorithm, NetworkInfo, NodeIdT, SessionIdT};
|
||||
|
||||
/// A `Subset` step, possibly containing several outputs.
|
||||
pub type Step<N> = ::Step<Message<N>, SubsetOutput<N>, N>;
|
||||
pub type Step<N> = crate::Step<Message<N>, SubsetOutput<N>, N>;
|
||||
|
||||
/// An output with an accepted contribution or the end of the set.
|
||||
#[derive(Derivative, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
|
|
|
@ -56,10 +56,6 @@
|
|||
//! ## Example
|
||||
//!
|
||||
//! ```
|
||||
//! extern crate rand;
|
||||
//! extern crate hbbft;
|
||||
//! extern crate threshold_crypto;
|
||||
//!
|
||||
//! use std::collections::BTreeMap;
|
||||
//!
|
||||
//! use threshold_crypto::{PublicKey, SecretKey, SignatureShare};
|
||||
|
@ -176,19 +172,19 @@
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fmt::{self, Debug, Formatter};
|
||||
|
||||
use bincode;
|
||||
use crypto::{
|
||||
use crate::crypto::{
|
||||
error::Error as CryptoError,
|
||||
poly::{BivarCommitment, BivarPoly, Poly},
|
||||
serde_impl::field_vec::FieldWrap,
|
||||
Ciphertext, Fr, G1Affine, PublicKey, PublicKeySet, SecretKey, SecretKeyShare,
|
||||
};
|
||||
use crate::pairing::{CurveAffine, Field};
|
||||
use bincode;
|
||||
use failure::Fail;
|
||||
use pairing::{CurveAffine, Field};
|
||||
use rand;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use {NetworkInfo, NodeIdT};
|
||||
use crate::{NetworkInfo, NodeIdT};
|
||||
|
||||
/// A local error while handling an `Ack` or `Part` message, that was not caused by that message
|
||||
/// being invalid.
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crypto::{self, Ciphertext, DecryptionShare};
|
||||
use crate::crypto::{self, Ciphertext, DecryptionShare};
|
||||
use failure::Fail;
|
||||
use rand_derive::Rand;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use fault_log::{Fault, FaultKind, FaultLog};
|
||||
use {DistAlgorithm, NetworkInfo, NodeIdT, Target};
|
||||
use crate::fault_log::{Fault, FaultKind, FaultLog};
|
||||
use crate::{DistAlgorithm, NetworkInfo, NodeIdT, Target};
|
||||
|
||||
/// A threshold decryption error.
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
|
||||
|
@ -65,7 +65,7 @@ pub struct ThresholdDecrypt<N> {
|
|||
}
|
||||
|
||||
/// A `ThresholdDecrypt` step. It will contain at most one output.
|
||||
pub type Step<N> = ::DaStep<ThresholdDecrypt<N>>;
|
||||
pub type Step<N> = crate::DaStep<ThresholdDecrypt<N>>;
|
||||
|
||||
impl<N: NodeIdT> DistAlgorithm for ThresholdDecrypt<N> {
|
||||
type NodeId = N;
|
||||
|
@ -135,8 +135,7 @@ impl<N: NodeIdT> ThresholdDecrypt<N> {
|
|||
let mut step = Step::default();
|
||||
step.fault_log.extend(self.remove_invalid_shares());
|
||||
self.had_input = true;
|
||||
// TODO: Remove `cloned()` once non-lexical lifetimes are stable.
|
||||
let share = match self.netinfo.secret_key_share().cloned() {
|
||||
let share = match self.netinfo.secret_key_share() {
|
||||
Some(sks) => sks.decrypt_share_no_verify(&ct),
|
||||
None => return Ok(step.join(self.try_output()?)), // Not a validator.
|
||||
};
|
||||
|
|
|
@ -19,14 +19,14 @@ use std::collections::BTreeMap;
|
|||
use std::sync::Arc;
|
||||
use std::{fmt, result};
|
||||
|
||||
use crypto::{self, hash_g2, Signature, SignatureShare, G2};
|
||||
use crate::crypto::{self, hash_g2, Signature, SignatureShare, G2};
|
||||
use failure::Fail;
|
||||
use log::debug;
|
||||
use rand_derive::Rand;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use fault_log::{Fault, FaultKind, FaultLog};
|
||||
use {DistAlgorithm, NetworkInfo, NodeIdT, Target};
|
||||
use crate::fault_log::{Fault, FaultKind, FaultLog};
|
||||
use crate::{DistAlgorithm, NetworkInfo, NodeIdT, Target};
|
||||
|
||||
/// A threshold signing error.
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
|
||||
|
@ -35,10 +35,7 @@ pub enum Error {
|
|||
#[fail(display = "Redundant input provided")]
|
||||
MultipleMessagesToSign,
|
||||
/// Error combining and verifying signature shares.
|
||||
#[fail(
|
||||
display = "Error combining and verifying signature shares: {}",
|
||||
_0
|
||||
)]
|
||||
#[fail(display = "Error combining and verifying signature shares: {}", _0)]
|
||||
CombineAndVerifySigCrypto(crypto::error::Error),
|
||||
/// Unknown sender
|
||||
#[fail(display = "Unknown sender")]
|
||||
|
@ -75,7 +72,7 @@ pub struct ThresholdSign<N> {
|
|||
}
|
||||
|
||||
/// A step returned from `ThresholdSign`. It contains at most one output.
|
||||
pub type Step<N> = ::DaStep<ThresholdSign<N>>;
|
||||
pub type Step<N> = crate::DaStep<ThresholdSign<N>>;
|
||||
|
||||
impl<N: NodeIdT> DistAlgorithm for ThresholdSign<N> {
|
||||
type NodeId = N;
|
||||
|
@ -143,8 +140,7 @@ impl<N: NodeIdT> ThresholdSign<N> {
|
|||
self.had_input = true;
|
||||
let mut step = Step::default();
|
||||
step.fault_log.extend(self.remove_invalid_shares());
|
||||
// TODO: Remove `cloned()` once non-lexical lifetimes are stable.
|
||||
let msg = match self.netinfo.secret_key_share().cloned() {
|
||||
let msg = match self.netinfo.secret_key_share() {
|
||||
Some(sks) => Message(sks.sign_g2(hash)),
|
||||
None => return Ok(step.join(self.try_output()?)), // Not a validator.
|
||||
};
|
||||
|
|
|
@ -8,9 +8,9 @@ use std::iter::once;
|
|||
use failure::Fail;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use fault_log::{Fault, FaultLog};
|
||||
use sender_queue::SenderQueueableMessage;
|
||||
use {Target, TargetedMessage};
|
||||
use crate::fault_log::{Fault, FaultLog};
|
||||
use crate::sender_queue::SenderQueueableMessage;
|
||||
use crate::{Target, TargetedMessage};
|
||||
|
||||
/// A transaction, user message, or other user data.
|
||||
pub trait Contribution: Eq + Debug + Hash + Send + Sync {}
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::{cmp, fmt};
|
|||
|
||||
use rand::{self, Rng};
|
||||
|
||||
use Contribution;
|
||||
use crate::Contribution;
|
||||
|
||||
/// An interface to the transaction queue. A transaction queue is a structural part of
|
||||
/// `QueueingHoneyBadger` that manages enqueueing of transactions for a future batch and dequeueing
|
||||
|
|
|
@ -40,6 +40,6 @@ pub fn fmt_hex<T: AsRef<[u8]>>(bytes: T, f: &mut fmt::Formatter) -> fmt::Result
|
|||
/// Given a number of nodes, returns the maximum number of faulty nodes that can be tolerated: the
|
||||
/// greatest number less than one third of `n`.
|
||||
#[inline]
|
||||
pub fn max_faulty(n: usize) -> usize {
|
||||
pub const fn max_faulty(n: usize) -> usize {
|
||||
(n - 1) / 3
|
||||
}
|
||||
|
|
|
@ -13,13 +13,6 @@
|
|||
//! - Validity: If any correct node outputs `b`, then at least one correct node received `b` as
|
||||
//! input.
|
||||
|
||||
extern crate failure;
|
||||
extern crate hbbft;
|
||||
extern crate integer_sqrt;
|
||||
extern crate proptest;
|
||||
extern crate rand;
|
||||
extern crate threshold_crypto;
|
||||
|
||||
pub mod net;
|
||||
|
||||
use std::iter::once;
|
||||
|
@ -33,9 +26,9 @@ use rand::{Rng, SeedableRng};
|
|||
use hbbft::binary_agreement::BinaryAgreement;
|
||||
use hbbft::DistAlgorithm;
|
||||
|
||||
use net::adversary::ReorderingAdversary;
|
||||
use net::proptest::{gen_seed, NetworkDimension, TestRng, TestRngSeed};
|
||||
use net::{NetBuilder, NewNodeInfo, VirtualNet};
|
||||
use crate::net::adversary::ReorderingAdversary;
|
||||
use crate::net::proptest::{gen_seed, NetworkDimension, TestRng, TestRngSeed};
|
||||
use crate::net::{NetBuilder, NewNodeInfo, VirtualNet};
|
||||
|
||||
/// Test configuration for Binary Agreement tests.
|
||||
#[derive(Debug)]
|
||||
|
@ -66,12 +59,12 @@ prop_compose! {
|
|||
}
|
||||
|
||||
/// Proptest wrapper for `binary_agreement` that runs the test function on generated configurations.
|
||||
proptest!{
|
||||
proptest! {
|
||||
#![proptest_config(ProptestConfig {
|
||||
cases: 1, .. ProptestConfig::default()
|
||||
})]
|
||||
#[test]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(unnecessary_operation))]
|
||||
#[allow(clippy::unnecessary_operation)]
|
||||
fn run_binary_agreement(cfg in arb_config()) {
|
||||
binary_agreement(cfg)
|
||||
}
|
||||
|
@ -109,7 +102,7 @@ impl VirtualNet<BinaryAgreement<NodeId, u8>> {
|
|||
}
|
||||
|
||||
/// Tests Binary Agreement on a given configuration.
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn binary_agreement(cfg: TestConfig) {
|
||||
let mut rng: TestRng = TestRng::from_seed(cfg.seed);
|
||||
let size = cfg.dimension.size();
|
||||
|
@ -129,7 +122,8 @@ fn binary_agreement(cfg: TestConfig) {
|
|||
.using(move |node_info: NewNodeInfo<_>| {
|
||||
BinaryAgreement::new(Arc::new(node_info.netinfo), 0)
|
||||
.expect("Failed to create a BinaryAgreement instance.")
|
||||
}).build()
|
||||
})
|
||||
.build()
|
||||
.expect("Could not construct test network.");
|
||||
net.test_binary_agreement(cfg.input, rng.gen::<TestRng>());
|
||||
println!(
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
#![deny(unused_must_use)]
|
||||
//! Tests the BinaryAgreement protocol with a MTIM adversary.
|
||||
|
||||
extern crate env_logger;
|
||||
extern crate failure;
|
||||
extern crate hbbft;
|
||||
extern crate integer_sqrt;
|
||||
extern crate proptest;
|
||||
extern crate rand;
|
||||
extern crate threshold_crypto;
|
||||
|
||||
pub mod net;
|
||||
|
||||
use std::iter;
|
||||
|
@ -18,9 +10,9 @@ use hbbft::binary_agreement::{BinaryAgreement, MessageContent, SbvMessage};
|
|||
use hbbft::threshold_sign::ThresholdSign;
|
||||
use hbbft::{DaStep, DistAlgorithm, NetworkInfo};
|
||||
|
||||
use net::adversary::{NetMutHandle, QueuePosition};
|
||||
use net::err::CrankError;
|
||||
use net::{Adversary, NetBuilder, NetMessage};
|
||||
use crate::net::adversary::{NetMutHandle, QueuePosition};
|
||||
use crate::net::err::CrankError;
|
||||
use crate::net::{Adversary, NetBuilder, NetMessage};
|
||||
|
||||
type NodeId = usize;
|
||||
type SessionId = u8;
|
||||
|
@ -339,7 +331,8 @@ impl AbaCommonCoinAdversary {
|
|||
.map(|x| {
|
||||
(x.msg_type == MessageType::Coin && self.coin_state.value().is_some())
|
||||
|| self.stage_progress >= x.msg_count
|
||||
}).unwrap_or(false);
|
||||
})
|
||||
.unwrap_or(false);
|
||||
if stage_finished {
|
||||
self.stage += 1;
|
||||
self.stage_progress = 0;
|
||||
|
@ -448,7 +441,8 @@ fn reordering_attack() {
|
|||
*adversary_netinfo.lock().unwrap() = Some(netinfo.clone());
|
||||
}
|
||||
BinaryAgreement::new(netinfo, 0).expect("failed to create BinaryAgreement instance")
|
||||
}).num_faulty(1)
|
||||
})
|
||||
.num_faulty(1)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
#![deny(unused_must_use)]
|
||||
//! Integration test of the reliable broadcast protocol.
|
||||
|
||||
extern crate env_logger;
|
||||
extern crate hbbft;
|
||||
extern crate log;
|
||||
extern crate rand;
|
||||
extern crate rand_derive;
|
||||
extern crate serde_derive;
|
||||
extern crate threshold_crypto as crypto;
|
||||
|
||||
mod network;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
@ -18,12 +10,12 @@ use std::sync::Arc;
|
|||
use log::info;
|
||||
use rand::Rng;
|
||||
|
||||
use hbbft::broadcast::{Broadcast, Message};
|
||||
use hbbft::{util, DistAlgorithm, NetworkInfo, Target, TargetedMessage};
|
||||
use network::{
|
||||
use crate::network::{
|
||||
Adversary, MessageScheduler, MessageWithSender, NodeId, RandomAdversary, SilentAdversary,
|
||||
TestNetwork, TestNode,
|
||||
};
|
||||
use hbbft::broadcast::{Broadcast, Message};
|
||||
use hbbft::{util, DistAlgorithm, NetworkInfo, Target, TargetedMessage};
|
||||
|
||||
/// An adversary that inputs an alternate value.
|
||||
struct ProposeAdversary {
|
||||
|
@ -70,7 +62,8 @@ impl Adversary<Broadcast<NodeId>> for ProposeAdversary {
|
|||
.messages
|
||||
.into_iter()
|
||||
.map(move |msg| MessageWithSender::new(id, msg))
|
||||
}).collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
#![deny(unused_must_use)]
|
||||
//! Network tests for Dynamic Honey Badger.
|
||||
|
||||
extern crate env_logger;
|
||||
extern crate hbbft;
|
||||
extern crate itertools;
|
||||
extern crate log;
|
||||
extern crate rand;
|
||||
extern crate rand_derive;
|
||||
extern crate serde_derive;
|
||||
extern crate threshold_crypto as crypto;
|
||||
|
||||
mod network;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
@ -25,7 +16,7 @@ use hbbft::sender_queue::{SenderQueue, Step};
|
|||
use hbbft::transaction_queue::TransactionQueue;
|
||||
use hbbft::{util, NetworkInfo};
|
||||
|
||||
use network::{Adversary, MessageScheduler, NodeId, SilentAdversary, TestNetwork, TestNode};
|
||||
use crate::network::{Adversary, MessageScheduler, NodeId, SilentAdversary, TestNetwork, TestNode};
|
||||
|
||||
type UsizeDhb = SenderQueue<DynamicHoneyBadger<Vec<usize>, NodeId>>;
|
||||
|
||||
|
@ -87,7 +78,8 @@ where
|
|||
// If there's only one node, it will immediately output on input. Make sure we
|
||||
// first process all incoming messages before providing input again.
|
||||
&& (network.nodes.len() > 2 || node.queue.is_empty())
|
||||
}).map(|(id, _)| *id)
|
||||
})
|
||||
.map(|(id, _)| *id)
|
||||
.collect();
|
||||
if let Some(id) = rng.choose(&input_ids) {
|
||||
let queue = queues.get_mut(id).unwrap();
|
||||
|
@ -105,7 +97,7 @@ where
|
|||
}
|
||||
|
||||
// Allow passing `netinfo` by value. `TestNetwork` expects this function signature.
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn new_dynamic_hb(
|
||||
netinfo: Arc<NetworkInfo<NodeId>>,
|
||||
) -> (UsizeDhb, Step<DynamicHoneyBadger<Vec<usize>, NodeId>>) {
|
||||
|
@ -119,7 +111,8 @@ fn new_dynamic_hb(
|
|||
SenderQueue::builder(
|
||||
DynamicHoneyBadger::builder().build((*netinfo).clone()),
|
||||
peer_ids,
|
||||
).build(our_id)
|
||||
)
|
||||
.build(our_id)
|
||||
}
|
||||
|
||||
fn test_dynamic_honey_badger_different_sizes<A, F>(new_adversary: F, num_txs: usize)
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
#![deny(unused_must_use)]
|
||||
//! Network tests for Honey Badger.
|
||||
|
||||
extern crate bincode;
|
||||
extern crate env_logger;
|
||||
extern crate hbbft;
|
||||
extern crate itertools;
|
||||
extern crate log;
|
||||
extern crate rand;
|
||||
extern crate rand_derive;
|
||||
extern crate serde_derive;
|
||||
extern crate threshold_crypto as crypto;
|
||||
|
||||
mod network;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
@ -26,7 +16,7 @@ use hbbft::sender_queue::{self, SenderQueue, Step};
|
|||
use hbbft::transaction_queue::TransactionQueue;
|
||||
use hbbft::{threshold_decrypt, util, DistAlgorithm, NetworkInfo, Target, TargetedMessage};
|
||||
|
||||
use network::{
|
||||
use crate::network::{
|
||||
Adversary, MessageScheduler, MessageWithSender, NodeId, RandomAdversary, SilentAdversary,
|
||||
TestNetwork, TestNode,
|
||||
};
|
||||
|
@ -112,7 +102,8 @@ impl Adversary<UsizeHoneyBadger> for FaultyShareAdversary {
|
|||
MessageContent::DecryptionShare {
|
||||
proposer_id: NodeId(proposer_id),
|
||||
share: threshold_decrypt::Message(share.clone()),
|
||||
}.with_epoch(*epoch),
|
||||
}
|
||||
.with_epoch(*epoch),
|
||||
)),
|
||||
))
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ use rand::Rng;
|
|||
|
||||
use hbbft::{DaStep, DistAlgorithm};
|
||||
|
||||
use net::{CrankError, NetMessage, Node, VirtualNet};
|
||||
use crate::net::{CrankError, NetMessage, Node, VirtualNet};
|
||||
|
||||
/// Immutable network handle.
|
||||
///
|
||||
|
@ -361,7 +361,8 @@ where
|
|||
D: DistAlgorithm,
|
||||
D::Message: Clone,
|
||||
D::Output: Clone,
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/// Ascending node id message order adversary.
|
||||
///
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
//! delivered to a node.
|
||||
|
||||
// We need to allow writes with newlines, resulting from `net_trace!` calls.
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(write_with_newline))]
|
||||
#![allow(clippy::write_with_newline)]
|
||||
// Almost all of our types are fairly readable, but trigger the type complexity checks, probably
|
||||
// due to associated types.
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||
#![allow(clippy::type_complexity)]
|
||||
// Some of our constructors return results.
|
||||
#![allow(clippy::new_ret_no_self)]
|
||||
|
||||
pub mod adversary;
|
||||
pub mod err;
|
||||
|
@ -27,7 +29,7 @@ use hbbft::dynamic_honey_badger::Batch;
|
|||
use hbbft::util::SubRng;
|
||||
use hbbft::{self, Contribution, DaStep, DistAlgorithm, Fault, NetworkInfo, NodeIdT, Step};
|
||||
|
||||
use try_some;
|
||||
use crate::try_some;
|
||||
|
||||
pub use self::adversary::Adversary;
|
||||
pub use self::err::CrankError;
|
||||
|
@ -212,7 +214,7 @@ pub type NetMessage<D> =
|
|||
/// The function will panic if the `sender` ID is not a valid node ID in `nodes`.
|
||||
// This function is defined outside `VirtualNet` and takes arguments "piecewise" to work around
|
||||
// borrow-checker restrictions.
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn process_step<'a, D>(
|
||||
nodes: &'a mut collections::BTreeMap<D::NodeId, Node<D>>,
|
||||
sender: D::NodeId,
|
||||
|
@ -552,7 +554,7 @@ where
|
|||
.expect("cannot build network without a constructor function for the nodes");
|
||||
|
||||
// Note: Closure is not redundant, won't compile without it.
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(redundant_closure))]
|
||||
#[allow(clippy::redundant_closure)]
|
||||
let (mut net, steps) = VirtualNet::new(
|
||||
self.node_ids,
|
||||
self.num_faulty as usize,
|
||||
|
@ -690,7 +692,7 @@ where
|
|||
///
|
||||
/// Returns `None` if the node ID is not part of the network.
|
||||
#[inline]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn get<'a>(&'a self, id: D::NodeId) -> Option<&'a Node<D>> {
|
||||
self.nodes.get(&id)
|
||||
}
|
||||
|
@ -699,7 +701,7 @@ where
|
|||
///
|
||||
/// Returns `None` if the node ID is not part of the network.
|
||||
#[inline]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn get_mut<'a>(&'a mut self, id: D::NodeId) -> Option<&'a mut Node<D>> {
|
||||
self.nodes.get_mut(&id)
|
||||
}
|
||||
|
@ -810,7 +812,8 @@ where
|
|||
});
|
||||
steps.insert(id.clone(), step);
|
||||
(id, Node::new(algorithm, is_faulty))
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut message_count: usize = 0;
|
||||
// For every recorded step, apply it.
|
||||
|
@ -951,11 +954,11 @@ where
|
|||
// Unfortunately, we have to re-borrow the target node further down to make the borrow
|
||||
// checker happy. First, we check if the receiving node is faulty, so we can dispatch
|
||||
// through the adversary if it is.
|
||||
let is_faulty = try_some!(
|
||||
self.nodes
|
||||
.get(&msg.to)
|
||||
.ok_or_else(|| CrankError::NodeDisappeared(msg.to.clone()))
|
||||
).is_faulty();
|
||||
let is_faulty = try_some!(self
|
||||
.nodes
|
||||
.get(&msg.to)
|
||||
.ok_or_else(|| CrankError::NodeDisappeared(msg.to.clone())))
|
||||
.is_faulty();
|
||||
|
||||
let step: Step<_, _, _> = if is_faulty {
|
||||
// The swap-dance is painful here, as we are creating an `opt_step` just to avoid
|
||||
|
@ -979,16 +982,18 @@ where
|
|||
|
||||
// All messages are expanded and added to the queue. We opt for copying them, so we can
|
||||
// return unaltered step later on for inspection.
|
||||
self.message_count = self.message_count.saturating_add(match process_step(
|
||||
&mut self.nodes,
|
||||
receiver.clone(),
|
||||
&step,
|
||||
&mut self.messages,
|
||||
self.error_on_fault,
|
||||
) {
|
||||
Ok(n) => n,
|
||||
Err(e) => return Some(Err(e)),
|
||||
});
|
||||
self.message_count = self.message_count.saturating_add(
|
||||
match process_step(
|
||||
&mut self.nodes,
|
||||
receiver.clone(),
|
||||
&step,
|
||||
&mut self.messages,
|
||||
self.error_on_fault,
|
||||
) {
|
||||
Ok(n) => n,
|
||||
Err(e) => return Some(Err(e)),
|
||||
},
|
||||
);
|
||||
|
||||
// Increase the crank count.
|
||||
self.crank_count += 1;
|
||||
|
@ -1042,7 +1047,8 @@ where
|
|||
.handle_input(input.clone())
|
||||
.map_err(CrankError::HandleInputAll)?,
|
||||
))
|
||||
}).collect::<Result<_, _>>()?;
|
||||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
// Process all messages from all steps in the queue.
|
||||
for (id, step) in &steps {
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
extern crate failure;
|
||||
extern crate hbbft;
|
||||
extern crate integer_sqrt;
|
||||
extern crate proptest;
|
||||
extern crate rand;
|
||||
extern crate threshold_crypto;
|
||||
|
||||
pub mod net;
|
||||
|
||||
use std::{collections, time};
|
||||
|
||||
use crate::net::adversary::ReorderingAdversary;
|
||||
use crate::net::proptest::{gen_seed, NetworkDimension, TestRng, TestRngSeed};
|
||||
use crate::net::{NetBuilder, NewNodeInfo};
|
||||
use hbbft::dynamic_honey_badger::{Change, ChangeState, DynamicHoneyBadger, Input};
|
||||
use hbbft::sender_queue::SenderQueue;
|
||||
use net::adversary::ReorderingAdversary;
|
||||
use net::proptest::{gen_seed, NetworkDimension, TestRng, TestRngSeed};
|
||||
use net::{NetBuilder, NewNodeInfo};
|
||||
use proptest::{prelude::ProptestConfig, prop_compose, proptest, proptest_helper};
|
||||
use rand::{Rng, SeedableRng};
|
||||
|
||||
|
@ -75,12 +68,12 @@ prop_compose! {
|
|||
}
|
||||
|
||||
/// Proptest wrapper for `do_drop_and_readd`.
|
||||
proptest!{
|
||||
proptest! {
|
||||
#![proptest_config(ProptestConfig {
|
||||
cases: 1, .. ProptestConfig::default()
|
||||
})]
|
||||
#[test]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(unnecessary_operation))]
|
||||
#[allow(clippy::unnecessary_operation)]
|
||||
fn drop_and_readd(cfg in arb_config()) {
|
||||
do_drop_and_readd(cfg)
|
||||
}
|
||||
|
@ -88,7 +81,7 @@ proptest!{
|
|||
|
||||
/// Dynamic honey badger: Drop a validator node, demoting it to observer, then re-add it, all while
|
||||
/// running a regular honey badger network.
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn do_drop_and_readd(cfg: TestConfig) {
|
||||
let mut rng: TestRng = TestRng::from_seed(cfg.seed);
|
||||
|
||||
|
@ -111,8 +104,10 @@ fn do_drop_and_readd(cfg: TestConfig) {
|
|||
SenderQueue::builder(
|
||||
dhb,
|
||||
node.netinfo.all_ids().filter(|&&them| them != id).cloned(),
|
||||
).build(node.id)
|
||||
}).build()
|
||||
)
|
||||
.build(node.id)
|
||||
})
|
||||
.build()
|
||||
.expect("could not construct test network");
|
||||
|
||||
// We will use the first correct node as the node we will remove from and re-add to the network.
|
||||
|
@ -190,7 +185,8 @@ fn do_drop_and_readd(cfg: TestConfig) {
|
|||
} else {
|
||||
// The node has added the pivot node back.
|
||||
pub_keys_add.keys()
|
||||
}.collect();
|
||||
}
|
||||
.collect();
|
||||
assert!(
|
||||
batch.contributions().count() * 3 > expected_participants.len() * 2,
|
||||
"The batch contains less than N - f contributions: {:?}",
|
||||
|
@ -223,7 +219,8 @@ fn do_drop_and_readd(cfg: TestConfig) {
|
|||
.send_input(
|
||||
node_id,
|
||||
Input::Change(Change::NodeChange(pub_keys_add.clone())),
|
||||
).expect("failed to send `Add` input");
|
||||
)
|
||||
.expect("failed to send `Add` input");
|
||||
}
|
||||
|
||||
ChangeState::Complete(Change::NodeChange(ref pub_keys))
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
extern crate failure;
|
||||
extern crate hbbft;
|
||||
extern crate integer_sqrt;
|
||||
extern crate proptest;
|
||||
extern crate rand;
|
||||
extern crate rand_core;
|
||||
extern crate threshold_crypto;
|
||||
|
||||
pub mod net;
|
||||
|
||||
use proptest::arbitrary::any;
|
||||
|
@ -13,7 +5,7 @@ use proptest::strategy::{Strategy, ValueTree};
|
|||
use proptest::{prelude::RngCore, proptest, proptest_helper};
|
||||
use rand::{Rng as Rng4, SeedableRng as SeedableRng4};
|
||||
|
||||
use net::proptest::{max_sum, NetworkDimension, NetworkDimensionTree};
|
||||
use crate::net::proptest::{max_sum, NetworkDimension, NetworkDimensionTree};
|
||||
|
||||
struct RngAdapter4To5<T>(pub T);
|
||||
|
||||
|
@ -53,7 +45,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
proptest!{
|
||||
proptest! {
|
||||
/// Ensures all generated network dimensions are actually sane.
|
||||
#[test]
|
||||
fn generated_network_dimensions_are_sane(_nt in NetworkDimension::range(1, 400)) {
|
||||
|
@ -71,7 +63,7 @@ fn any_op() -> impl Strategy<Value = Op> {
|
|||
any::<bool>().prop_map(|v| if v { Op::Simplify } else { Op::Complicate })
|
||||
}
|
||||
|
||||
proptest!{
|
||||
proptest! {
|
||||
/// Verifies generated network dimensions can be grown and shrunk multiple times.
|
||||
#[test]
|
||||
fn network_dimensions_shrink_and_grow(
|
||||
|
@ -180,7 +172,7 @@ fn network_to_u32_is_correct() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
|
||||
#[allow(clippy::cyclomatic_complexity)]
|
||||
fn network_from_u32_is_correct() {
|
||||
assert_eq!(NetworkDimension::new(1, 0), NetworkDimension::from(0u32));
|
||||
assert_eq!(NetworkDimension::new(2, 0), NetworkDimension::from(1u32));
|
||||
|
|
|
@ -117,7 +117,8 @@ impl MessageScheduler {
|
|||
rand::thread_rng().choose(&ids).cloned()
|
||||
} else {
|
||||
ids.next()
|
||||
}.expect("no more messages in queue")
|
||||
}
|
||||
.expect("no more messages in queue")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -533,7 +534,7 @@ where
|
|||
|
||||
// The node handles the incoming message and creates new outgoing ones to be dispatched.
|
||||
let (msgs, faults): (Vec<_>, Vec<_>) = {
|
||||
let mut node = self.nodes.get_mut(&id).unwrap();
|
||||
let node = self.nodes.get_mut(&id).unwrap();
|
||||
|
||||
// Ensure the adversary is playing fair by selecting a node that will result in actual
|
||||
// progress being made, otherwise `TestNode::handle_message()` will panic on `expect()`
|
||||
|
@ -558,7 +559,7 @@ where
|
|||
/// Inputs a value in node `id`.
|
||||
pub fn input(&mut self, id: NodeId, value: D::Input) {
|
||||
let (msgs, faults): (Vec<_>, Vec<_>) = {
|
||||
let mut node = self.nodes.get_mut(&id).expect("input instance");
|
||||
let node = self.nodes.get_mut(&id).expect("input instance");
|
||||
node.handle_input(value);
|
||||
(
|
||||
node.messages.drain(..).collect(),
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
#![deny(unused_must_use)]
|
||||
//! Network tests for Queueing Honey Badger.
|
||||
|
||||
extern crate env_logger;
|
||||
extern crate hbbft;
|
||||
extern crate itertools;
|
||||
extern crate log;
|
||||
extern crate rand;
|
||||
extern crate rand_derive;
|
||||
extern crate serde_derive;
|
||||
extern crate threshold_crypto as crypto;
|
||||
|
||||
mod network;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
@ -25,7 +16,7 @@ use hbbft::queueing_honey_badger::{Batch, Change, ChangeState, Input, QueueingHo
|
|||
use hbbft::sender_queue::{Message, SenderQueue, Step};
|
||||
use hbbft::{util, NetworkInfo};
|
||||
|
||||
use network::{Adversary, MessageScheduler, NodeId, SilentAdversary, TestNetwork, TestNode};
|
||||
use crate::network::{Adversary, MessageScheduler, NodeId, SilentAdversary, TestNetwork, TestNode};
|
||||
|
||||
type QHB = SenderQueue<QueueingHoneyBadger<usize, NodeId, Vec<usize>>>;
|
||||
|
||||
|
@ -87,7 +78,7 @@ where
|
|||
}
|
||||
|
||||
// Allow passing `netinfo` by value. `TestNetwork` expects this function signature.
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn new_queueing_hb(
|
||||
netinfo: Arc<NetworkInfo<NodeId>>,
|
||||
) -> (QHB, Step<QueueingHoneyBadger<usize, NodeId, Vec<usize>>>) {
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
#![deny(unused_must_use)]
|
||||
//! Integration tests of the Subset protocol.
|
||||
|
||||
extern crate env_logger;
|
||||
extern crate hbbft;
|
||||
extern crate log;
|
||||
extern crate rand;
|
||||
extern crate rand_derive;
|
||||
extern crate serde_derive;
|
||||
extern crate threshold_crypto as crypto;
|
||||
|
||||
mod network;
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
@ -18,7 +10,7 @@ use std::sync::Arc;
|
|||
use hbbft::subset::{Subset, SubsetOutput};
|
||||
use hbbft::NetworkInfo;
|
||||
|
||||
use network::{Adversary, MessageScheduler, NodeId, SilentAdversary, TestNetwork, TestNode};
|
||||
use crate::network::{Adversary, MessageScheduler, NodeId, SilentAdversary, TestNetwork, TestNode};
|
||||
|
||||
type ProposedValue = Vec<u8>;
|
||||
|
||||
|
@ -42,7 +34,7 @@ fn test_subset<A: Adversary<Subset<NodeId, u8>>>(
|
|||
// Verify that all instances output the same set.
|
||||
let observer: BTreeSet<_> = network.observer.outputs().iter().cloned().collect();
|
||||
for node in network.nodes.values() {
|
||||
let mut outputs = node.outputs();
|
||||
let outputs = node.outputs();
|
||||
let mut actual = BTreeMap::default();
|
||||
|
||||
let mut has_seen_done = false;
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
#![deny(unused_must_use)]
|
||||
//! Tests for synchronous distributed key generation.
|
||||
|
||||
extern crate env_logger;
|
||||
extern crate hbbft;
|
||||
extern crate rand;
|
||||
extern crate threshold_crypto as crypto;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crypto::{PublicKey, SecretKey};
|
||||
|
||||
use hbbft::crypto::{PublicKey, SecretKey};
|
||||
use hbbft::sync_key_gen::{PartOutcome, SyncKeyGen};
|
||||
use hbbft::util;
|
||||
|
||||
|
@ -35,7 +29,8 @@ fn test_sync_key_gen_with(threshold: usize, node_num: usize) {
|
|||
});
|
||||
nodes.push(sync_key_gen);
|
||||
proposal
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Handle the first `threshold + 1` proposals. Those should suffice for key generation.
|
||||
let mut acks = Vec::new();
|
||||
|
@ -88,7 +83,8 @@ fn test_sync_key_gen_with(threshold: usize, node_num: usize) {
|
|||
let sig = sk.sign(msg);
|
||||
assert!(pks.public_key_share(idx).verify(&sig, msg));
|
||||
(idx, sig)
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
let sig = pub_key_set
|
||||
.combine_signatures(sig_shares.iter().take(threshold + 1))
|
||||
.expect("signature shares match");
|
||||
|
|
|
@ -1,27 +1,16 @@
|
|||
#![deny(unused_must_use)]
|
||||
//! Threshold signing tests
|
||||
|
||||
extern crate env_logger;
|
||||
extern crate hbbft;
|
||||
extern crate log;
|
||||
extern crate rand;
|
||||
extern crate rand_derive;
|
||||
extern crate serde_derive;
|
||||
extern crate threshold_crypto as crypto;
|
||||
|
||||
mod network;
|
||||
|
||||
use std::iter::once;
|
||||
|
||||
use log::info;
|
||||
use rand::Rng;
|
||||
use rand_derive::Rand;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use crypto::Signature;
|
||||
use hbbft::{threshold_sign::ThresholdSign, util};
|
||||
use hbbft::{crypto::Signature, threshold_sign::ThresholdSign, util};
|
||||
|
||||
use network::{Adversary, MessageScheduler, NodeId, SilentAdversary, TestNetwork, TestNode};
|
||||
use crate::network::{Adversary, MessageScheduler, NodeId, SilentAdversary, TestNetwork, TestNode};
|
||||
|
||||
/// Tests a network of threshold signing instances with an optional expected value. Outputs the
|
||||
/// computed signature if the test is successful.
|
||||
|
|
Loading…
Reference in New Issue