diff --git a/Cargo.toml b/Cargo.toml index 468667ca..aa09147f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 "] license = "GPL-3.0" diff --git a/src/lib.rs b/src/lib.rs index dcdf2f31..ae634348 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -345,6 +345,35 @@ pub struct CommitValidationResult { num_invalid_voters: usize, } +impl CommitValidationResult { + /// 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 Default for CommitValidationResult { fn default() -> Self { CommitValidationResult { @@ -407,7 +436,7 @@ pub fn validate_commit>( 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, .. } => { diff --git a/src/voter/mod.rs b/src/voter/mod.rs index 0a07185c..04a61c46 100644 --- a/src/voter/mod.rs +++ b/src/voter/mod.rs @@ -118,19 +118,15 @@ pub trait Environment: Chain { /// Communication between nodes that is not round-localized. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "derive-codec", derive(Encode, Decode))] pub enum CommunicationOut { /// A commit message. - #[cfg_attr(feature = "derive-codec", codec(index = "0"))] Commit(u64, Commit), /// Auxiliary messages out. - #[cfg_attr(feature = "derive-codec", codec(index = "1"))] Auxiliary(AuxiliaryCommunication), } /// 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), @@ -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. } @@ -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, @@ -197,7 +191,6 @@ impl From> 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, @@ -205,6 +198,7 @@ pub enum Callback { Work(Box), } +#[cfg(test)] impl Clone for Callback { fn clone(&self) -> Self { Callback::Blank @@ -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 { /// A commit message. - #[cfg_attr(feature = "derive-codec", codec(index = "0"))] Commit(u64, CompactCommit, Callback), /// Auxiliary messages out. - #[cfg_attr(feature = "derive-codec", codec(index = "1"))] Auxiliary(AuxiliaryCommunication), } diff --git a/src/voter/voter_state.rs b/src/voter/voter_state.rs deleted file mode 100644 index 33dcb6bf..00000000 --- a/src/voter/voter_state.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. -// This file is part of finality-grandpa. - -// finality-grandpa is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// finality-grandpa is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with finality-grandpa. If not, see . - -//! Exposed voter-state. - -use std::sync::Arc; -use parking_lot::RwLock; - -/// -pub struct VoterState { - inner: Arc>, -} - -pub(super) struct Inner { - -}