mirror of https://github.com/poanetwork/hbbft.git
Remove more NodeUid trait bounds.
Use a `BTreeMap` instead of `HashMap` in `NetworkInfo`. The number of nodes can't grow very large anyway.
This commit is contained in:
parent
3f707a8e12
commit
66f396e01c
|
@ -4,7 +4,6 @@ pub mod bin_values;
|
|||
|
||||
use std::collections::{BTreeMap, BTreeSet, VecDeque};
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::mem::replace;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -68,10 +67,7 @@ pub struct AgreementMessage {
|
|||
}
|
||||
|
||||
/// Binary Agreement instance
|
||||
pub struct Agreement<NodeUid>
|
||||
where
|
||||
NodeUid: Eq + Hash,
|
||||
{
|
||||
pub struct Agreement<NodeUid> {
|
||||
/// Shared network information.
|
||||
netinfo: Rc<NetworkInfo<NodeUid>>,
|
||||
/// Session ID, e.g, the Honey Badger algorithm epoch.
|
||||
|
@ -121,7 +117,7 @@ where
|
|||
common_coin: CommonCoin<NodeUid, Nonce>,
|
||||
}
|
||||
|
||||
impl<NodeUid: Clone + Debug + Eq + Hash + Ord> DistAlgorithm for Agreement<NodeUid> {
|
||||
impl<NodeUid: Clone + Debug + Ord> DistAlgorithm for Agreement<NodeUid> {
|
||||
type NodeUid = NodeUid;
|
||||
type Input = bool;
|
||||
type Output = bool;
|
||||
|
@ -177,7 +173,7 @@ impl<NodeUid: Clone + Debug + Eq + Hash + Ord> DistAlgorithm for Agreement<NodeU
|
|||
}
|
||||
}
|
||||
|
||||
impl<NodeUid: Clone + Debug + Eq + Hash + Ord> Agreement<NodeUid> {
|
||||
impl<NodeUid: Clone + Debug + Ord> Agreement<NodeUid> {
|
||||
pub fn new(
|
||||
netinfo: Rc<NetworkInfo<NodeUid>>,
|
||||
session_id: u64,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::collections::{BTreeMap, VecDeque};
|
||||
use std::fmt::{self, Debug};
|
||||
use std::hash::Hash;
|
||||
use std::iter::once;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -92,7 +91,7 @@ impl Debug for BroadcastMessage {
|
|||
/// eventually be able to decode (i.e. receive at least `f + 1` `Echo` messages).
|
||||
/// * So a node with `2 * f + 1` `Ready`s and `f + 1` `Echos` will decode and _output_ the value,
|
||||
/// knowing that every other good node will eventually do the same.
|
||||
pub struct Broadcast<NodeUid: Eq + Hash> {
|
||||
pub struct Broadcast<NodeUid> {
|
||||
/// Shared network data.
|
||||
netinfo: Rc<NetworkInfo<NodeUid>>,
|
||||
/// The UID of the sending node.
|
||||
|
@ -115,7 +114,7 @@ pub struct Broadcast<NodeUid: Eq + Hash> {
|
|||
output: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl<NodeUid: Eq + Debug + Clone + Hash + Ord> DistAlgorithm for Broadcast<NodeUid> {
|
||||
impl<NodeUid: Debug + Clone + Ord> DistAlgorithm for Broadcast<NodeUid> {
|
||||
type NodeUid = NodeUid;
|
||||
// TODO: Allow anything serializable and deserializable, i.e. make this a type parameter
|
||||
// T: Serialize + DeserializeOwned
|
||||
|
@ -168,7 +167,7 @@ impl<NodeUid: Eq + Debug + Clone + Hash + Ord> DistAlgorithm for Broadcast<NodeU
|
|||
}
|
||||
}
|
||||
|
||||
impl<NodeUid: Eq + Debug + Clone + Hash + Ord> Broadcast<NodeUid> {
|
||||
impl<NodeUid: Debug + Clone + Ord> Broadcast<NodeUid> {
|
||||
/// Creates a new broadcast instance to be used by node `our_id` which expects a value proposal
|
||||
/// from node `proposer_id`.
|
||||
pub fn new(netinfo: Rc<NetworkInfo<NodeUid>>, proposer_id: NodeUid) -> BroadcastResult<Self> {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::rc::Rc;
|
||||
|
||||
use pairing::bls12_381::Bls12;
|
||||
|
@ -44,10 +43,7 @@ impl CommonCoinMessage {
|
|||
/// receiving at least `num_faulty + 1` shares, attempts to combine them into a signature. If that
|
||||
/// signature is valid, the instance outputs it and terminates; otherwise the instance aborts.
|
||||
#[derive(Debug)]
|
||||
pub struct CommonCoin<NodeUid, T>
|
||||
where
|
||||
NodeUid: Eq + Hash,
|
||||
{
|
||||
pub struct CommonCoin<NodeUid, T> {
|
||||
netinfo: Rc<NetworkInfo<NodeUid>>,
|
||||
/// The name of this common coin. It is required to be unique for each common coin round.
|
||||
nonce: T,
|
||||
|
@ -65,7 +61,7 @@ where
|
|||
|
||||
impl<NodeUid, T> DistAlgorithm for CommonCoin<NodeUid, T>
|
||||
where
|
||||
NodeUid: Clone + Debug + Hash + Ord,
|
||||
NodeUid: Clone + Debug + Ord,
|
||||
T: Clone + AsRef<[u8]>,
|
||||
{
|
||||
type NodeUid = NodeUid;
|
||||
|
@ -117,7 +113,7 @@ where
|
|||
|
||||
impl<NodeUid, T> CommonCoin<NodeUid, T>
|
||||
where
|
||||
NodeUid: Clone + Debug + Hash + Ord,
|
||||
NodeUid: Clone + Debug + Ord,
|
||||
T: Clone + AsRef<[u8]>,
|
||||
{
|
||||
pub fn new(netinfo: Rc<NetworkInfo<NodeUid>>, nonce: T) -> Self {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use std::collections::{BTreeMap, BTreeSet, VecDeque};
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::rc::Rc;
|
||||
|
||||
use agreement;
|
||||
|
@ -47,7 +46,7 @@ pub enum Message<NodeUid> {
|
|||
#[derive(Deref, DerefMut)]
|
||||
struct MessageQueue<NodeUid>(VecDeque<TargetedMessage<Message<NodeUid>, NodeUid>>);
|
||||
|
||||
impl<NodeUid: Clone + Debug + Eq + Hash + Ord> MessageQueue<NodeUid> {
|
||||
impl<NodeUid: Clone + Debug + Ord> MessageQueue<NodeUid> {
|
||||
/// Appends to the queue the messages from `agr`, wrapped with `proposer_id`.
|
||||
fn extend_agreement(&mut self, proposer_id: &NodeUid, agr: &mut Agreement<NodeUid>) {
|
||||
let convert = |msg: TargetedMessage<AgreementMessage, NodeUid>| {
|
||||
|
@ -88,7 +87,7 @@ impl<NodeUid: Clone + Debug + Eq + Hash + Ord> MessageQueue<NodeUid> {
|
|||
/// remaining ones, where we haven't provided input yet.
|
||||
/// * Once all `Agreement` instances have decided, `CommonSubset` returns the set of all proposed
|
||||
/// values for which the decision was "yes".
|
||||
pub struct CommonSubset<NodeUid: Eq + Hash> {
|
||||
pub struct CommonSubset<NodeUid> {
|
||||
/// Shared network information.
|
||||
netinfo: Rc<NetworkInfo<NodeUid>>,
|
||||
broadcast_instances: BTreeMap<NodeUid, Broadcast<NodeUid>>,
|
||||
|
@ -103,7 +102,7 @@ pub struct CommonSubset<NodeUid: Eq + Hash> {
|
|||
decided: bool,
|
||||
}
|
||||
|
||||
impl<NodeUid: Clone + Debug + Eq + Hash + Ord> DistAlgorithm for CommonSubset<NodeUid> {
|
||||
impl<NodeUid: Clone + Debug + Ord> DistAlgorithm for CommonSubset<NodeUid> {
|
||||
type NodeUid = NodeUid;
|
||||
type Input = ProposedValue;
|
||||
type Output = BTreeMap<NodeUid, ProposedValue>;
|
||||
|
@ -147,7 +146,7 @@ impl<NodeUid: Clone + Debug + Eq + Hash + Ord> DistAlgorithm for CommonSubset<No
|
|||
}
|
||||
}
|
||||
|
||||
impl<NodeUid: Clone + Debug + Eq + Hash + Ord> CommonSubset<NodeUid> {
|
||||
impl<NodeUid: Clone + Debug + Ord> CommonSubset<NodeUid> {
|
||||
pub fn new(netinfo: Rc<NetworkInfo<NodeUid>>, session_id: u64) -> CommonSubsetResult<Self> {
|
||||
// Create all broadcast instances.
|
||||
let mut broadcast_instances: BTreeMap<NodeUid, Broadcast<NodeUid>> = BTreeMap::new();
|
||||
|
|
|
@ -32,7 +32,7 @@ error_chain!{
|
|||
}
|
||||
|
||||
/// An instance of the Honey Badger Byzantine fault tolerant consensus algorithm.
|
||||
pub struct HoneyBadger<Tx, NodeUid: Eq + Hash> {
|
||||
pub struct HoneyBadger<Tx, NodeUid> {
|
||||
/// Shared network data.
|
||||
netinfo: Rc<NetworkInfo<NodeUid>>,
|
||||
/// The buffer of transactions that have not yet been included in any output batch.
|
||||
|
@ -55,7 +55,7 @@ pub struct HoneyBadger<Tx, NodeUid: Eq + Hash> {
|
|||
impl<Tx, NodeUid> DistAlgorithm for HoneyBadger<Tx, NodeUid>
|
||||
where
|
||||
Tx: Eq + Hash + Serialize + DeserializeOwned + Debug,
|
||||
NodeUid: Eq + Hash + Ord + Clone + Debug,
|
||||
NodeUid: Ord + Clone + Debug,
|
||||
{
|
||||
type NodeUid = NodeUid;
|
||||
type Input = Tx;
|
||||
|
@ -103,7 +103,7 @@ where
|
|||
impl<Tx, NodeUid> HoneyBadger<Tx, NodeUid>
|
||||
where
|
||||
Tx: Eq + Hash + Serialize + DeserializeOwned + Debug,
|
||||
NodeUid: Eq + Hash + Ord + Clone + Debug,
|
||||
NodeUid: Ord + Clone + Debug,
|
||||
{
|
||||
/// Returns a new Honey Badger instance with the given parameters, starting at epoch `0`.
|
||||
pub fn new<TI>(
|
||||
|
@ -304,7 +304,7 @@ pub enum Message<NodeUid> {
|
|||
#[derive(Deref, DerefMut)]
|
||||
struct MessageQueue<NodeUid>(VecDeque<TargetedMessage<Message<NodeUid>, NodeUid>>);
|
||||
|
||||
impl<NodeUid: Clone + Debug + Eq + Hash + Ord> MessageQueue<NodeUid> {
|
||||
impl<NodeUid: Clone + Debug + Ord> MessageQueue<NodeUid> {
|
||||
/// Appends to the queue the messages from `cs`, wrapped with `epoch`.
|
||||
fn extend_with_epoch(&mut self, epoch: u64, cs: &mut CommonSubset<NodeUid>) {
|
||||
let convert = |msg: TargetedMessage<common_subset::Message<NodeUid>, NodeUid>| {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
use pairing::bls12_381::Bls12;
|
||||
|
||||
|
@ -132,17 +131,17 @@ impl<'a, D: DistAlgorithm + 'a> Iterator for OutputIter<'a, D> {
|
|||
|
||||
/// Common data shared between algorithms.
|
||||
#[derive(Debug)]
|
||||
pub struct NetworkInfo<NodeUid: Eq + Hash> {
|
||||
pub struct NetworkInfo<NodeUid> {
|
||||
our_uid: NodeUid,
|
||||
all_uids: BTreeSet<NodeUid>,
|
||||
num_nodes: usize,
|
||||
num_faulty: usize,
|
||||
secret_key: SecretKey<Bls12>,
|
||||
public_key_set: PublicKeySet<Bls12>,
|
||||
node_indices: HashMap<NodeUid, usize>,
|
||||
node_indices: BTreeMap<NodeUid, usize>,
|
||||
}
|
||||
|
||||
impl<NodeUid: Clone + Hash + Ord> NetworkInfo<NodeUid> {
|
||||
impl<NodeUid: Clone + Ord> NetworkInfo<NodeUid> {
|
||||
pub fn new(
|
||||
our_uid: NodeUid,
|
||||
all_uids: BTreeSet<NodeUid>,
|
||||
|
|
Loading…
Reference in New Issue