Skip to content
This repository was archived by the owner on Apr 13, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
[package]
name = "rhododendron"
version = "0.5.0"
version = "0.6.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Asynchronously safe BFT protocol, futures-based implementation"
license = "GPL-3.0"
repository = "https://github.com/paritytech/rhododendron"
edition = "2018"

[dependencies]
futures = "0.1.17"
error-chain = "0.12"
log = "0.4"
parity-codec = { version = "3.0", optional = true }
parity-codec-derive = { version = "3.0", optional = true }
parity-codec = { version = "4.1", optional = true, features = ["derive"] }

[dev-dependencies]
tokio-core = "0.1.12"
tokio-timer = "0.1.2"
parity-codec = "3.0"
parity-codec-derive = "3.0"
parity-codec = { version = "4.1", features = ["derive"] }

[features]
codec = ['parity-codec', 'parity-codec-derive']
codec = ['parity-codec']
24 changes: 14 additions & 10 deletions src/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ use std::collections::{HashMap, HashSet};
use std::collections::hash_map::Entry;
use std::hash::Hash;

use ::{Vote, LocalizedMessage, LocalizedProposal};
use log::{debug, trace};
#[cfg(any(test, feature="codec"))]
use parity_codec::{Encode, Decode};

use crate::{Vote, LocalizedMessage, LocalizedProposal};

/// Justification for some state at a given round.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -122,8 +126,8 @@ pub enum State<Candidate, Digest, Signature> {
#[derive(Debug, Default)]
#[cfg_attr(any(test, feature="codec"), derive(Encode, Decode))]
struct VoteCounts {
prepared: usize,
committed: usize,
prepared: u64,
committed: u64,
}

#[derive(Debug)]
Expand Down Expand Up @@ -334,7 +338,7 @@ impl<Candidate, Digest, AuthorityId, Signature> Accumulator<Candidate, Digest, A
let count = self.vote_counts.entry(digest.clone()).or_insert_with(Default::default);
count.prepared += 1;

if count.prepared >= self.threshold {
if count.prepared >= self.threshold as u64 {
Some(digest)
} else {
None
Expand Down Expand Up @@ -391,7 +395,7 @@ impl<Candidate, Digest, AuthorityId, Signature> Accumulator<Candidate, Digest, A
let count = self.vote_counts.entry(digest.clone()).or_insert_with(Default::default);
count.committed += 1;

if count.committed >= self.threshold {
if count.committed >= self.threshold as u64 {
Some(digest)
} else {
None
Expand Down Expand Up @@ -458,19 +462,19 @@ impl<Candidate, Digest, AuthorityId, Signature> Accumulator<Candidate, Digest, A
#[cfg(test)]
mod tests {
use super::*;
use ::{LocalizedMessage, LocalizedProposal, LocalizedVote};
use crate::{LocalizedMessage, LocalizedProposal, LocalizedVote};

#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub struct Candidate(usize);
pub struct Candidate(u64);

#[derive(Hash, PartialEq, Eq, Clone, Debug, Encode, Decode)]
pub struct Digest(usize);
pub struct Digest(u64);

#[derive(Hash, PartialEq, Eq, Debug, Encode, Decode, Clone)]
pub struct AuthorityId(usize);
pub struct AuthorityId(u64);

#[derive(PartialEq, Eq, Clone, Debug, Encode, Decode)]
pub struct Signature(usize, usize);
pub struct Signature(u64, u64);

#[test]
fn justification_checks_out() {
Expand Down
20 changes: 4 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,15 @@
//! Users of the `Agreement` future should schedule it to be pre-empted
//! by an external import of an agreed value.

#[cfg_attr(test, macro_use)]
extern crate futures;

#[macro_use]
extern crate log;

#[cfg(test)]
extern crate tokio_timer;

#[cfg(any(test, feature="codec"))]
extern crate parity_codec as codec;
#[cfg(any(test, feature="codec"))]
#[macro_use]
extern crate parity_codec_derive;

use std::collections::{HashMap, BTreeMap, VecDeque};
use std::collections::hash_map;
use std::fmt::Debug;
use std::hash::Hash;

use futures::{future, Future, Stream, Sink, Poll, Async, AsyncSink};
use log::trace;
#[cfg(any(test, feature="codec"))]
use parity_codec::{Encode, Decode};

use self::accumulator::State;

Expand Down Expand Up @@ -448,7 +436,7 @@ impl<C: Context> Strategy<C> {
} else if round_number > current_round {
let threshold = bft_threshold(self.nodes, self.max_faulty);

let mut future_acc = self.future_accumulators.entry(round_number).or_insert_with(|| {
let future_acc = self.future_accumulators.entry(round_number).or_insert_with(|| {
Accumulator::new(
round_number,
threshold,
Expand Down
25 changes: 13 additions & 12 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;

use futures::try_ready;
use futures::prelude::*;
use futures::sync::{oneshot, mpsc};
use futures::future::FutureResult;
Expand Down Expand Up @@ -92,13 +93,13 @@ impl<T: Clone> Future for Network<T> {
}

#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, Hash)]
struct Candidate(usize);
struct Candidate(u64);

#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, Hash)]
struct Digest(usize);
struct Digest(u64);

#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, Hash)]
struct AuthorityId(usize);
struct AuthorityId(u64);

#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
struct Signature(Message<Candidate, Digest>, AuthorityId);
Expand All @@ -118,7 +119,7 @@ struct TestContext {
node_count: usize,
current_round: Arc<AtomicUsize>,
timer: Timer,
evaluated: Mutex<BTreeSet<usize>>,
evaluated: Mutex<BTreeSet<u64>>,
}

impl Context for TestContext {
Expand All @@ -140,7 +141,7 @@ impl Context for TestContext {
let mut p = self.proposal.lock().unwrap();
let x = *p;
*p += self.node_count;
x
x as u64
};

Ok(Candidate(proposal)).into_future()
Expand Down Expand Up @@ -173,7 +174,7 @@ impl Context for TestContext {
}

fn round_proposer(&self, round: u32) -> AuthorityId {
AuthorityId((round as usize) % self.node_count)
AuthorityId((round as u64) % self.node_count as u64)
}

fn proposal_valid(&self, proposal: &Candidate) -> FutureResult<bool, Error> {
Expand Down Expand Up @@ -239,7 +240,7 @@ fn consensus_completes_with_minimum_good() {
.enumerate()
.map(|(i, (tx, rx))| {
let ctx = TestContext {
local_id: AuthorityId(i),
local_id: AuthorityId(i as u64),
proposal: Mutex::new(i),
current_round: Arc::new(AtomicUsize::new(0)),
timer: timer.clone(),
Expand Down Expand Up @@ -296,7 +297,7 @@ fn consensus_completes_with_minimum_good_all_initial_proposals_bad() {
};

let ctx = TestContext {
local_id: AuthorityId(i),
local_id: AuthorityId(i as u64),
proposal: Mutex::new(proposal),
current_round: Arc::new(AtomicUsize::new(0)),
timer: timer.clone(),
Expand Down Expand Up @@ -346,7 +347,7 @@ fn consensus_does_not_complete_without_enough_nodes() {
.enumerate()
.map(|(i, (tx, rx))| {
let ctx = TestContext {
local_id: AuthorityId(i),
local_id: AuthorityId(i as u64),
proposal: Mutex::new(i),
current_round: Arc::new(AtomicUsize::new(0)),
timer: timer.clone(),
Expand Down Expand Up @@ -403,7 +404,7 @@ fn threshold_plus_one_locked_on_proposal_only_one_with_candidate() {
.enumerate()
.map(|(i, (tx, rx))| {
let ctx = TestContext {
local_id: AuthorityId(i),
local_id: AuthorityId(i as u64),
proposal: Mutex::new(i),
current_round: Arc::new(AtomicUsize::new(locked_round as usize + 1)),
timer: timer.clone(),
Expand Down Expand Up @@ -483,7 +484,7 @@ fn threshold_plus_one_locked_on_bad_proposal() {
.enumerate()
.map(|(i, (tx, rx))| {
let ctx = TestContext {
local_id: AuthorityId(i),
local_id: AuthorityId(i as u64),
proposal: Mutex::new(i),
current_round: Arc::new(AtomicUsize::new(locked_round as usize + 1)),
timer: timer.clone(),
Expand Down Expand Up @@ -552,7 +553,7 @@ fn consensus_completes_even_when_nodes_start_with_a_delay() {
.enumerate()
.map(|(i, (tx, rx))| {
let ctx = TestContext {
local_id: AuthorityId(i),
local_id: AuthorityId(i as u64),
proposal: Mutex::new(i),
current_round: Arc::new(AtomicUsize::new(0)),
timer: timer.clone(),
Expand Down