diff --git a/Cargo.toml b/Cargo.toml index e73111f1..0781fe06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,9 +11,8 @@ edition = "2018" parking_lot = "0.6" log = "0.4" futures = "0.1" -parity-codec = { version = "3.0", optional = true, default-features = false } -parity-codec-derive = { version = "3.0", optional = true, default-features = false } -num-traits = "0.2" +parity-codec = { version = "4.1", optional = true, default-features = false, features = ["derive"] } +num = { package = "num-traits", version = "0.2" } hashmap_core = { version = "0.1.10", default-features = false } [dev-dependencies] @@ -23,5 +22,5 @@ tokio = "0.1.8" [features] default = ["std"] -std = ["parity-codec/std", "parity-codec-derive/std", "hashmap_core/disable"] -derive-codec = ["parity-codec", "parity-codec-derive"] +std = ["parity-codec/std", "hashmap_core/disable"] +derive-codec = ["parity-codec"] diff --git a/src/lib.rs b/src/lib.rs index 84e89a2e..c9ffe5c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,28 +28,6 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(alloc))] -extern crate parking_lot; -extern crate num_traits as num; - -#[cfg_attr(feature = "std", macro_use)] -extern crate futures; -#[cfg_attr(feature = "std", macro_use)] -extern crate log; - -#[cfg(test)] -extern crate exit_future; -#[cfg(test)] -extern crate rand; -#[cfg(test)] -extern crate tokio; - -#[cfg(feature = "derive-codec")] -#[macro_use] -extern crate parity_codec_derive; - -#[cfg(feature = "derive-codec")] -extern crate parity_codec; - #[cfg(not(feature = "std"))] extern crate core as std; @@ -75,6 +53,8 @@ use collections::Vec; use std::fmt; use crate::voter_set::VoterSet; use round::ImportResult; +#[cfg(feature = "derive-codec")] +use parity_codec::{Encode, Decode}; #[cfg(not(feature = "std"))] mod collections { @@ -165,9 +145,9 @@ pub trait BlockNumberOps: std::cmp::Ord + std::ops::Add + std::ops::Sub + - crate::num::One + - crate::num::Zero + - crate::num::AsPrimitive + num::One + + num::Zero + + num::AsPrimitive {} impl BlockNumberOps for T where @@ -175,9 +155,9 @@ impl BlockNumberOps for T where T: std::cmp::Ord, T: std::ops::Add, T: std::ops::Sub, - T: crate::num::One, - T: crate::num::Zero, - T: crate::num::AsPrimitive, + T: num::One, + T: num::Zero, + T: num::AsPrimitive, {} /// Chain context necessary for implementation of the finality gadget. @@ -483,8 +463,8 @@ pub fn process_commit_validation_result( #[cfg_attr(feature = "derive-codec", derive(Encode, Decode))] pub struct HistoricalVotes { seen: Vec>, - prevote_idx: Option, - precommit_idx: Option, + prevote_idx: Option, + precommit_idx: Option, } impl HistoricalVotes { @@ -500,8 +480,8 @@ impl HistoricalVotes { /// Create a new HistoricalVotes initialized from the parameters. pub fn new_with( seen: Vec>, - prevote_idx: Option, - precommit_idx: Option + prevote_idx: Option, + precommit_idx: Option ) -> Self { HistoricalVotes { seen, @@ -522,24 +502,24 @@ impl HistoricalVotes { /// Return the number of messages seen before prevoting. /// None in case we didn't prevote yet. - pub fn prevote_idx(&self) -> Option { + pub fn prevote_idx(&self) -> Option { self.prevote_idx } /// Return the number of messages seen before precommiting. /// None in case we didn't precommit yet. - pub fn precommit_idx(&self) -> Option { + pub fn precommit_idx(&self) -> Option { self.precommit_idx } /// Set the number of messages seen before prevoting. pub fn set_prevoted_idx(&mut self) { - self.prevote_idx = Some(self.seen.len()) + self.prevote_idx = Some(self.seen.len() as u64) } /// Set the number of messages seen before precommiting. pub fn set_precommited_idx(&mut self) { - self.precommit_idx = Some(self.seen.len()) + self.precommit_idx = Some(self.seen.len() as u64) } } diff --git a/src/round.rs b/src/round.rs index e5b1bc29..4a1137a3 100644 --- a/src/round.rs +++ b/src/round.rs @@ -17,6 +17,9 @@ use std::hash::Hash; use std::ops::AddAssign; +#[cfg(feature = "derive-codec")] +use parity_codec::{Encode, Decode}; + use crate::collections::{hash_map::{HashMap, Entry}, Vec}; use crate::bitfield::{Shared as BitfieldContext, Bitfield}; use crate::vote_graph::VoteGraph; @@ -716,13 +719,13 @@ impl Round where /// Get the number of prevotes and precommits received at the moment of prevoting. /// Returns None if the prevote wasn't realized. - pub fn prevoted_index(&self) -> Option { + pub fn prevoted_index(&self) -> Option { self.historical_votes.prevote_idx } /// Get the number of prevotes and precommits received at the moment of precommiting. /// Returns None if the precommit wasn't realized. - pub fn precommited_index(&self) -> Option { + pub fn precommited_index(&self) -> Option { self.historical_votes.precommit_idx } } diff --git a/src/voter/mod.rs b/src/voter/mod.rs index 66da7523..5b2725d0 100644 --- a/src/voter/mod.rs +++ b/src/voter/mod.rs @@ -27,6 +27,10 @@ use futures::prelude::*; use futures::sync::mpsc::{self, UnboundedReceiver}; +#[cfg(feature = "std")] +use log::trace; +#[cfg(feature = "derive-codec")] +use parity_codec::{Encode, Decode}; use std::collections::VecDeque; use std::cmp; diff --git a/src/voter/past_rounds.rs b/src/voter/past_rounds.rs index 3a944ff3..cb3728cb 100644 --- a/src/voter/past_rounds.rs +++ b/src/voter/past_rounds.rs @@ -21,10 +21,14 @@ //! - Informing it of any new finalized block heights //! - Passing it any validated commits (so backgrounded rounds don't produce conflicting ones) +#[cfg(feature = "std")] +use futures::try_ready; use futures::prelude::*; use futures::stream::{self, futures_unordered::FuturesUnordered}; use futures::task; use futures::sync::mpsc; +#[cfg(feature = "std")] +use log::{trace, debug}; use std::cmp; use std::collections::HashMap; diff --git a/src/voter/voting_round.rs b/src/voter/voting_round.rs index 383cf6ce..e96c7ae3 100644 --- a/src/voter/voting_round.rs +++ b/src/voter/voting_round.rs @@ -14,8 +14,12 @@ //! Logic for voting and handling messages within a single round. +#[cfg(feature = "std")] +use futures::try_ready; use futures::prelude::*; use futures::sync::mpsc::UnboundedSender; +#[cfg(feature = "std")] +use log::{trace, warn, debug}; use std::hash::Hash; use std::sync::Arc;