diff --git a/Cargo.toml b/Cargo.toml index f52711e..1844d86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,22 @@ [package] name = "rhododendron" -version = "0.5.0" +version = "0.6.0" authors = ["Parity Technologies "] 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'] diff --git a/src/accumulator.rs b/src/accumulator.rs index 2136824..bcad3d6 100644 --- a/src/accumulator.rs +++ b/src/accumulator.rs @@ -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)] @@ -122,8 +126,8 @@ pub enum State { #[derive(Debug, Default)] #[cfg_attr(any(test, feature="codec"), derive(Encode, Decode))] struct VoteCounts { - prepared: usize, - committed: usize, + prepared: u64, + committed: u64, } #[derive(Debug)] @@ -334,7 +338,7 @@ impl Accumulator= self.threshold { + if count.prepared >= self.threshold as u64 { Some(digest) } else { None @@ -391,7 +395,7 @@ impl Accumulator= self.threshold { + if count.committed >= self.threshold as u64 { Some(digest) } else { None @@ -458,19 +462,19 @@ impl Accumulator Strategy { } 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, diff --git a/src/tests.rs b/src/tests.rs index af64ffc..468ec20 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -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; @@ -92,13 +93,13 @@ impl Future for Network { } #[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, AuthorityId); @@ -118,7 +119,7 @@ struct TestContext { node_count: usize, current_round: Arc, timer: Timer, - evaluated: Mutex>, + evaluated: Mutex>, } impl Context for TestContext { @@ -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() @@ -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 { @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -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(),