Skip to content
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
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"]
52 changes: 16 additions & 36 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -165,19 +145,19 @@ pub trait BlockNumberOps:
std::cmp::Ord +
std::ops::Add<Output=Self> +
std::ops::Sub<Output=Self> +
crate::num::One +
crate::num::Zero +
crate::num::AsPrimitive<usize>
num::One +
num::Zero +
num::AsPrimitive<usize>
{}

impl<T> BlockNumberOps for T where
T: std::fmt::Debug,
T: std::cmp::Ord,
T: std::ops::Add<Output=Self>,
T: std::ops::Sub<Output=Self>,
T: crate::num::One,
T: crate::num::Zero,
T: crate::num::AsPrimitive<usize>,
T: num::One,
T: num::Zero,
T: num::AsPrimitive<usize>,
{}

/// Chain context necessary for implementation of the finality gadget.
Expand Down Expand Up @@ -483,8 +463,8 @@ pub fn process_commit_validation_result<H, N>(
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct HistoricalVotes<H, N, S, Id> {
seen: Vec<SignedMessage<H, N, S, Id>>,
prevote_idx: Option<usize>,
precommit_idx: Option<usize>,
prevote_idx: Option<u64>,
precommit_idx: Option<u64>,
}

impl<H, N, S, Id> HistoricalVotes<H, N, S, Id> {
Expand All @@ -500,8 +480,8 @@ impl<H, N, S, Id> HistoricalVotes<H, N, S, Id> {
/// Create a new HistoricalVotes initialized from the parameters.
pub fn new_with(
seen: Vec<SignedMessage<H, N, S, Id>>,
prevote_idx: Option<usize>,
precommit_idx: Option<usize>
prevote_idx: Option<u64>,
precommit_idx: Option<u64>
) -> Self {
HistoricalVotes {
seen,
Expand All @@ -522,24 +502,24 @@ impl<H, N, S, Id> HistoricalVotes<H, N, S, Id> {

/// Return the number of messages seen before prevoting.
/// None in case we didn't prevote yet.
pub fn prevote_idx(&self) -> Option<usize> {
pub fn prevote_idx(&self) -> Option<u64> {
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<usize> {
pub fn precommit_idx(&self) -> Option<u64> {
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)
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -716,13 +719,13 @@ impl<Id, H, N, Signature> Round<Id, H, N, Signature> 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<usize> {
pub fn prevoted_index(&self) -> Option<u64> {
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<usize> {
pub fn precommited_index(&self) -> Option<u64> {
self.historical_votes.precommit_idx
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/voter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/voter/past_rounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/voter/voting_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down