From d52be00d0e3a1e2872c8d42a076e0dc3cb86b175 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Thu, 12 Mar 2020 12:28:07 +0100 Subject: [PATCH] Fix CI. Fix a few new Clippy lints, and some broken dependencies. --- .travis.yml | 2 +- Cargo.toml | 12 ++++------ examples/network/node.rs | 23 ++++++++----------- examples/simulation.rs | 10 ++++---- hbbft_testing/src/proptest.rs | 4 ++-- src/broadcast/broadcast.rs | 6 ++--- .../dynamic_honey_badger.rs | 16 ++++++------- tests/broadcast.rs | 4 ++-- tests/queueing_honey_badger.rs | 4 ++-- tests/subset.rs | 2 +- tests/threshold_sign.rs | 4 ++-- 11 files changed, 42 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef1f7e2..5050ba0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: rust rust: - - 1.36.0 + - 1.42.0 cache: cargo: true timeout: 2400 diff --git a/Cargo.toml b/Cargo.toml index 0342e31..8b747ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ travis-ci = { repository = "poanetwork/hbbft" } [dependencies] bincode = "1.2.0" byteorder = "1.3.2" -derivative = "1.0.3" +derivative = "2.0.2" env_logger = "0.7.1" failure = "0.1.6" hex_fmt = "0.3" @@ -31,7 +31,7 @@ init_with = "1.1.0" log = "0.4.8" rand = "0.6.5" rand_derive = "0.5.0" -reed-solomon-erasure = "3.1.1" +reed-solomon-erasure = "4.0.1" serde = { version = "1.0.102", features = ["derive", "rc"] } threshold_crypto = { rev = "624eeee", git = "https://github.com/poanetwork/threshold_crypto" } tiny-keccak = { version = "2.0.1", features = ["sha3"]} @@ -42,8 +42,8 @@ crossbeam = "0.7.3" crossbeam-channel = "0.4.0" docopt = "1.1.0" hbbft_testing = { path = "hbbft_testing", features = ["use-insecure-test-only-mock-crypto"] } -itertools = "0.8.1" -signifix = "0.10.0" +itertools = "0.9.0" +number_prefix = "0.3.0" proptest = "0.9.4" [[example]] @@ -60,6 +60,4 @@ overflow-checks = true [features] use-insecure-test-only-mock-crypto = ["threshold_crypto/use-insecure-test-only-mock-crypto"] -# TODO: Remove this feature once https://github.com/darrenldl/reed-solomon-erasure/issues/28 is -# resolved. -no-simd = ["reed-solomon-erasure/pure-rust"] +simd-accel = ["reed-solomon-erasure/simd-accel"] diff --git a/examples/network/node.rs b/examples/network/node.rs index 40bfbac..0c4dffc 100644 --- a/examples/network/node.rs +++ b/examples/network/node.rs @@ -9,21 +9,18 @@ //! use std::net::SocketAddr; //! use std::vec::Vec; //! -//! fn main() { -//! let bind_address = "127.0.0.1:10001".parse().unwrap(); -//! let remote_addresses = vec!["192.168.1.2:10002", -//! "192.168.1.3:10003", -//! "192.168.1.4:10004"] -//! .iter() -//! .map(|s| s.parse().unwrap()) -//! .collect(); +//! let bind_address = "127.0.0.1:10001".parse().unwrap(); +//! let remote_addresses = vec!["192.168.1.2:10002", +//! "192.168.1.3:10003", +//! "192.168.1.4:10004"] +//! .iter() +//! .map(|s| s.parse().unwrap()) +//! .collect(); //! -//! let value = "Value #1".as_bytes().to_vec(); +//! let value = "Value #1".as_bytes().to_vec(); //! -//! let result = Node::new(bind_address, remote_addresses, Some(value)) -//! .run(); -//! println!("Consensus result {:?}", result); -//! } +//! let result = Node::new(bind_address, remote_addresses, Some(value)).run(); +//! println!("Consensus result {:?}", result); //! ``` //! //! Similar code shall then run on hosts 192.168.1.2, 192.168.1.3 and diff --git a/examples/simulation.rs b/examples/simulation.rs index cba5e0e..2438131 100644 --- a/examples/simulation.rs +++ b/examples/simulation.rs @@ -1,15 +1,14 @@ use std::collections::{BTreeMap, VecDeque}; -use std::convert::TryFrom; use std::time::{Duration, Instant}; use std::{cmp, u64}; use colored::*; use docopt::Docopt; use itertools::Itertools; +use number_prefix::{NumberPrefix, Prefixed, Standalone}; use rand::{distributions::Standard, rngs::OsRng, seq::SliceRandom, Rng}; use rand_derive::Rand; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use signifix::metric; use hbbft::crypto::SecretKey; use hbbft::dynamic_honey_badger::DynamicHoneyBadger; @@ -362,8 +361,11 @@ impl EpochInfo { max_t.as_secs() * 1000 + u64::from(max_t.subsec_nanos()) / 1_000_000, txs, network.message_count() / network.nodes.len(), - metric::Signifix::try_from(network.message_size() / network.nodes.len() as u64) - .unwrap(), + match NumberPrefix::decimal(network.message_size() as f64 / network.nodes.len() as f64) + { + Standalone(bytes) => format!("{:3.0} ", bytes), + Prefixed(prefix, n) => format!("{:3.0} {}", n, prefix), + } ); } } diff --git a/hbbft_testing/src/proptest.rs b/hbbft_testing/src/proptest.rs index 92e8c75..c84b325 100644 --- a/hbbft_testing/src/proptest.rs +++ b/hbbft_testing/src/proptest.rs @@ -151,7 +151,7 @@ impl ValueTree for NetworkDimensionTree { self.high = self.current; self.current = (self.low + self.high) / 2; - (prev.high != self.high || prev.current != self.current) + prev.high != self.high || prev.current != self.current } fn complicate(&mut self) -> bool { @@ -164,7 +164,7 @@ impl ValueTree for NetworkDimensionTree { self.low = self.current + 1; self.current = (self.low + self.high) / 2; - (prev.current != self.current || prev.low != self.low) + prev.current != self.current || prev.low != self.low } } diff --git a/src/broadcast/broadcast.rs b/src/broadcast/broadcast.rs index 1a5b188..48c1c2d 100644 --- a/src/broadcast/broadcast.rs +++ b/src/broadcast/broadcast.rs @@ -8,7 +8,7 @@ use hex_fmt::{HexFmt, HexList}; use log::{debug, warn}; use rand::Rng; use reed_solomon_erasure as rse; -use reed_solomon_erasure::ReedSolomon; +use reed_solomon_erasure::{galois_8::Field as Field8, ReedSolomon}; use super::merkle::{Digest, MerkleTree, Proof}; use super::message::HexProof; @@ -638,7 +638,7 @@ impl fmt::Display for Broadcast { #[derive(Debug)] enum Coding { /// A `ReedSolomon` instance with at least one parity shard. - ReedSolomon(Box), + ReedSolomon(Box>), /// A no-op replacement that doesn't encode or decode anything. Trivial(usize), } @@ -681,7 +681,7 @@ impl Coding { /// If enough shards are present, reconstructs the missing ones. fn reconstruct_shards(&self, shards: &mut [Option>]) -> RseResult<()> { match *self { - Coding::ReedSolomon(ref rs) => rs.reconstruct_shards(shards), + Coding::ReedSolomon(ref rs) => rs.reconstruct(shards), Coding::Trivial(_) => { if shards.iter().all(Option::is_some) { Ok(()) diff --git a/src/dynamic_honey_badger/dynamic_honey_badger.rs b/src/dynamic_honey_badger/dynamic_honey_badger.rs index 6f60bed..19a52f3 100644 --- a/src/dynamic_honey_badger/dynamic_honey_badger.rs +++ b/src/dynamic_honey_badger/dynamic_honey_badger.rs @@ -1,3 +1,4 @@ +use std::cmp::Ordering; use std::collections::BTreeMap; use std::sync::Arc; use std::{fmt, result}; @@ -235,8 +236,12 @@ where message: Message, rng: &mut R, ) -> Result> { - if message.era() == self.era { - match message { + match message.era().cmp(&self.era) { + Ordering::Greater => { + Ok(Fault::new(sender_id.clone(), FaultKind::UnexpectedDhbMessageEra).into()) + } + Ordering::Less => Ok(Step::default()), // The message is late; discard it. + Ordering::Equal => match message { Message::HoneyBadger(_, hb_msg) => { self.handle_honey_badger_message(sender_id, hb_msg, rng) } @@ -247,12 +252,7 @@ where .vote_counter .add_pending_vote(sender_id, signed_vote) .map(FaultLog::into), - } - } else if message.era() > self.era { - Ok(Fault::new(sender_id.clone(), FaultKind::UnexpectedDhbMessageEra).into()) - } else { - // The message is late; discard it. - Ok(Step::default()) + }, } } diff --git a/tests/broadcast.rs b/tests/broadcast.rs index 5d4855d..2ec0987 100644 --- a/tests/broadcast.rs +++ b/tests/broadcast.rs @@ -125,7 +125,7 @@ fn test_broadcast>>( // verify that all other correct nodes have empty output as well. let first = net .correct_nodes() - .nth(0) + .next() .expect("At least one correct node needs to exist"); assert!(first.outputs().is_empty()); break; @@ -136,7 +136,7 @@ fn test_broadcast>>( if proposer_is_faulty { // If the proposer was faulty it is sufficient for all correct nodes having the same value. - let first = net.correct_nodes().nth(0).unwrap().outputs(); + let first = net.correct_nodes().next().unwrap().outputs(); assert!(net.nodes().all(|node| node.outputs() == first)); } else { // In the case where the proposer was valid it must be the value it proposed. diff --git a/tests/queueing_honey_badger.rs b/tests/queueing_honey_badger.rs index 2abe70c..6f9c5dd 100644 --- a/tests/queueing_honey_badger.rs +++ b/tests/queueing_honey_badger.rs @@ -41,7 +41,7 @@ where // Make two copies of all public keys. let pub_keys_add = net .correct_nodes() - .nth(0) + .next() .expect("At least one correct node needs to exist") .algorithm() .algo() @@ -52,7 +52,7 @@ where let mut pub_keys_rm = pub_keys_add.clone(); // Get the first correct node id as candidate for removal/re-adding. - let first_correct_node = *net.correct_nodes().nth(0).unwrap().id(); + let first_correct_node = *net.correct_nodes().next().unwrap().id(); // Remove the first correct node, which is to be removed. Arc::make_mut(&mut pub_keys_rm).remove(&first_correct_node); diff --git a/tests/subset.rs b/tests/subset.rs index fe05960..8f7e2e2 100644 --- a/tests/subset.rs +++ b/tests/subset.rs @@ -40,7 +40,7 @@ fn test_subset( // or drop this TODO if we decide to abandon that concept. let expected_value: BTreeSet<_> = net .correct_nodes() - .nth(0) + .next() .unwrap() .outputs() .iter() diff --git a/tests/threshold_sign.rs b/tests/threshold_sign.rs index 3c5f715..529c8eb 100644 --- a/tests/threshold_sign.rs +++ b/tests/threshold_sign.rs @@ -66,7 +66,7 @@ where while !net.nodes().all(|node| node.algorithm().terminated()) { let _ = net.crank_expect(&mut rng); } - let node0 = net.correct_nodes().nth(0).unwrap(); + let node0 = net.correct_nodes().next().unwrap(); // Verify that all instances output the same value. assert_eq!(1, node0.outputs().len()); assert!(net.nodes().all(|node| node.outputs() == node0.outputs())); @@ -136,7 +136,7 @@ where while !net.nodes().all(|node| node.algorithm().terminated()) { let _ = net.crank_expect(&mut rng); } - let node0 = net.correct_nodes().nth(0).unwrap(); + let node0 = net.correct_nodes().next().unwrap(); // Verify that all instances output the same value. assert_eq!(1, node0.outputs().len()); assert!(net.nodes().all(|node| node.outputs() == node0.outputs()));