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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "finality-grandpa"
version = "0.7.0"
version = "0.7.1"
description = "PBFT-based finality gadget for blockchains"
authors = ["Parity Technologies <admin@parity.io>"]
license = "GPL-3.0"
Expand Down
31 changes: 30 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,35 @@ pub struct CommitValidationResult<H, N> {
num_invalid_voters: usize,
}

impl<H, N> CommitValidationResult<H, N> {
/// Returns the commit GHOST i.e. the block with highest number for which
/// the cumulative votes of descendents and itself reach finalization
/// threshold.
pub fn ghost(&self) -> Option<&(H, N)> {
self.ghost.as_ref()
}

/// Returns the number of precommits in the commit.
pub fn num_precommits(&self) -> usize {
self.num_precommits
}

/// Returns the number of duplicate precommits in the commit.
pub fn num_duplicated_precommits(&self) -> usize {
self.num_duplicated_precommits
}

/// Returns the number of equivocated precommits in the commit.
pub fn num_equivocations(&self) -> usize {
self.num_equivocations
}

/// Returns the number of invalid voters in the commit.
pub fn num_invalid_voters(&self) -> usize {
self.num_invalid_voters
}
}

impl<H, N> Default for CommitValidationResult<H, N> {
fn default() -> Self {
CommitValidationResult {
Expand Down Expand Up @@ -407,7 +436,7 @@ pub fn validate_commit<H, N, S, I, C: Chain<H, N>>(
validation_result.num_equivocations += 1;
// allow only one equivocation per voter, as extras are redundant.
if !equivocated.insert(id) {
return Ok(validation_result)
return Ok(validation_result)
}
},
ImportResult { duplicated, valid_voter, .. } => {
Expand Down
13 changes: 2 additions & 11 deletions src/voter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,15 @@ pub trait Environment<H: Eq, N: BlockNumberOps>: Chain<H, N> {

/// Communication between nodes that is not round-localized.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub enum CommunicationOut<H, N, S, Id> {
/// A commit message.
#[cfg_attr(feature = "derive-codec", codec(index = "0"))]
Commit(u64, Commit<H, N, S, Id>),
/// Auxiliary messages out.
#[cfg_attr(feature = "derive-codec", codec(index = "1"))]
Auxiliary(AuxiliaryCommunication<H, N, Id>),
}

/// The outcome of processing a commit.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub enum CommitProcessingOutcome {
/// It was beneficial to process this commit.
Good(GoodCommit),
Expand All @@ -140,7 +136,6 @@ pub enum CommitProcessingOutcome {

/// The result of processing for a good commit.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct GoodCommit {
_priv: (), // lets us add stuff without breaking API.
}
Expand All @@ -153,7 +148,6 @@ impl GoodCommit {

/// The result of processing for a bad commit
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub struct BadCommit {
_priv: (), // lets us add stuff without breaking API.
num_precommits: usize,
Expand Down Expand Up @@ -197,14 +191,14 @@ impl<H, N> From<CommitValidationResult<H, N>> for BadCommit {
}

/// Callback used to propagate the commit in case the outcome is good.
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
pub enum Callback {
/// Default value.
Blank,
/// Callback to execute given a commit processing outcome.
Work(Box<FnMut(CommitProcessingOutcome) + Send>),
}

#[cfg(test)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

impl Clone for Callback {
fn clone(&self) -> Self {
Callback::Blank
Expand All @@ -221,14 +215,11 @@ impl Callback {
}

/// Communication between nodes that is not round-localized.
#[derive(Clone)]
#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))]
#[cfg_attr(test, derive(Clone))]
pub enum CommunicationIn<H, N, S, Id> {
/// A commit message.
#[cfg_attr(feature = "derive-codec", codec(index = "0"))]
Commit(u64, CompactCommit<H, N, S, Id>, Callback),
/// Auxiliary messages out.
#[cfg_attr(feature = "derive-codec", codec(index = "1"))]
Auxiliary(AuxiliaryCommunication<H, N, Id>),
}

Expand Down
29 changes: 0 additions & 29 deletions src/voter/voter_state.rs

This file was deleted.