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: 3 additions & 6 deletions src/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ use crate::voter_set::VoterInfo;

/// Errors that can occur when using the equivocation weighting tools.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
pub enum Error {
/// Attempted to index bitfield past its length.
IndexOutOfBounds(usize, usize),
Expand All @@ -65,8 +64,7 @@ impl std::error::Error for Error {}

/// Bitfield for tracking voters who have equivocated.
#[derive(Eq, PartialEq, Clone)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
pub enum Bitfield {
/// Blank bitfield,
Blank,
Expand Down Expand Up @@ -141,8 +139,7 @@ impl Bitfield {

/// Live bitfield instance.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
pub struct LiveBitfield {
bits: Vec<u64>,
}
Expand Down
30 changes: 10 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ impl<H, N> Precommit<H, N> {

/// A primary proposed block, this is a broadcast of the last round's estimate.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct PrimaryPropose<H, N> {
/// The target block's hash.
Expand All @@ -132,8 +131,7 @@ impl<H, N> PrimaryPropose<H, N> {
}

#[derive(Clone, PartialEq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
pub enum Error {
NotDescendent,
}
Expand Down Expand Up @@ -221,8 +219,7 @@ pub struct Equivocation<Id, V, S> {

/// A protocol message or vote.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub enum Message<H, N> {
/// A prevote message.
Expand All @@ -249,8 +246,7 @@ impl<H, N: Copy> Message<H, N> {

/// A signed message.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct SignedMessage<H, N, S, Id> {
/// The internal message which has been signed.
Expand All @@ -270,8 +266,7 @@ impl<H, N: Copy, S, Id> SignedMessage<H, N, S, Id> {

/// A commit message which is an aggregate of precommits.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct Commit<H, N, S, Id> {
/// The target block's hash.
Expand All @@ -284,8 +279,7 @@ pub struct Commit<H, N, S, Id> {

/// A signed prevote message.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct SignedPrevote<H, N, S, Id> {
/// The prevote message which has been signed.
Expand All @@ -298,8 +292,7 @@ pub struct SignedPrevote<H, N, S, Id> {

/// A signed precommit message.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct SignedPrecommit<H, N, S, Id> {
/// The precommit message which has been signed.
Expand All @@ -312,8 +305,7 @@ pub struct SignedPrecommit<H, N, S, Id> {

/// A commit message with compact representation of authentication data.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct CompactCommit<H, N, S, Id> {
/// The target block's hash.
Expand All @@ -332,8 +324,7 @@ pub struct CompactCommit<H, N, S, Id> {
/// This message contains a "base", which is a block all of the vote-targets are
/// a descendent of.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct CatchUp<H, N, S, Id> {
/// Round number.
Expand Down Expand Up @@ -526,8 +517,7 @@ pub fn process_commit_validation_result<H, N>(

/// Historical votes seen in a round.
#[derive(Default, Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct HistoricalVotes<H, N, S, Id> {
seen: Vec<SignedMessage<H, N, S, Id>>,
Expand Down
9 changes: 3 additions & 6 deletions src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ use crate::voter_set::VoterSet;
use super::{Equivocation, Prevote, Precommit, Chain, BlockNumberOps, HistoricalVotes, Message, SignedMessage};

#[derive(PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
struct TotalWeight {
prevote: u64,
precommit: u64,
}

#[derive(Clone)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
struct VoteWeight {
bitfield: Bitfield,
}
Expand Down Expand Up @@ -195,8 +193,7 @@ impl<Id: Ord + Eq + Clone, Vote: Clone + Eq, Signature: Clone + Eq> VoteTracker<

/// State of the round.
#[derive(PartialEq, Clone)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct State<H, N> {
/// The prevote-GHOST block.
Expand Down
24 changes: 15 additions & 9 deletions src/voter/voting_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,17 +606,23 @@ impl<H, N, E: Environment<H, N>> VotingRound<H, N, E> where

// notify when new blocks are finalized or when the round-estimate is updated
fn notify(&mut self, last_state: RoundState<H, N>, new_state: RoundState<H, N>) {
if last_state == new_state { return }

if let Some(ref b) = self.bridged_round_state {
b.update(new_state.clone());
if last_state != new_state {
if let Some(ref b) = self.bridged_round_state {
b.update(new_state.clone());
}
}

if last_state.finalized != new_state.finalized && new_state.completable {
// send notification only when the round is completable and we've cast votes.
// this is a workaround that ensures when we re-instantiate the voter after
// a shutdown, we never re-create the same round with a base that was finalized
// in this round or after.
// send notification only when the round is completable and we've cast votes.
// this is a workaround that ensures when we re-instantiate the voter after
// a shutdown, we never re-create the same round with a base that was finalized
// in this round or after.
// we try to notify if either the round state changed or if we haven't
// sent any notification yet (this is to guard against seeing enough
// votes to finalize before having precommited)
let state_changed = last_state.finalized != new_state.finalized;
let sent_finality_notifications = self.best_finalized.is_some();

if new_state.completable && (state_changed || !sent_finality_notifications) {
if let (&Some(State::Precommitted), Some((ref f_hash, ref f_number))) = (&self.state, new_state.finalized) {
let commit = Commit {
target_hash: f_hash.clone(),
Expand Down
3 changes: 1 addition & 2 deletions src/voter_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ impl<Id: Eq + Clone + Ord> std::iter::FromIterator<(Id, u64)> for VoterSet<Id> {
}

#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "std", test), derive(
Debug))]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
pub struct VoterInfo {
canon_idx: usize,
weight: u64,
Expand Down