From d82811540e73d15382fc43cbfeabca6bf077a9a8 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Fri, 10 Jul 2020 12:37:11 +0200 Subject: [PATCH] Remove some unused code. --- node/src/components/consensus.rs | 7 ++---- .../consensus/highway_core/evidence.rs | 5 ++--- .../highway_core/finality_detector.rs | 1 + .../consensus/highway_core/highway.rs | 22 +++++-------------- .../consensus/highway_core/state.rs | 1 - .../consensus/highway_core/tallies.rs | 12 +++++----- .../consensus/highway_core/validators.rs | 4 ---- .../consensus/highway_core/vertex.rs | 2 -- .../components/consensus/highway_core/vote.rs | 4 ++-- 9 files changed, 19 insertions(+), 39 deletions(-) diff --git a/node/src/components/consensus.rs b/node/src/components/consensus.rs index 109ff26d39..202b455910 100644 --- a/node/src/components/consensus.rs +++ b/node/src/components/consensus.rs @@ -2,12 +2,9 @@ mod consensus_protocol; mod era_supervisor; -mod traits; -// TODO: remove when we actually construct a Highway era -mod protocols; -// TODO: remove when we actually construct a Highway era -#[allow(unused)] mod highway_core; +mod protocols; +mod traits; #[cfg(test)] #[allow(unused)] diff --git a/node/src/components/consensus/highway_core/evidence.rs b/node/src/components/consensus/highway_core/evidence.rs index 581ff1d35c..6568f14fea 100644 --- a/node/src/components/consensus/highway_core/evidence.rs +++ b/node/src/components/consensus/highway_core/evidence.rs @@ -1,6 +1,5 @@ -use super::{validators::ValidatorIndex, vertex::WireVote}; -use crate::components::consensus::highway_core::vertex::SignedWireVote; -use crate::components::consensus::traits::Context; +use super::validators::ValidatorIndex; +use crate::components::consensus::{highway_core::vertex::SignedWireVote, traits::Context}; use serde::{Deserialize, Serialize}; /// Evidence that a validator is faulty. diff --git a/node/src/components/consensus/highway_core/finality_detector.rs b/node/src/components/consensus/highway_core/finality_detector.rs index 2340b71796..a4f8c5d66e 100644 --- a/node/src/components/consensus/highway_core/finality_detector.rs +++ b/node/src/components/consensus/highway_core/finality_detector.rs @@ -1,3 +1,4 @@ +#![allow(unused)] // TODO: Use the finality detector! use std::{collections::BTreeMap, iter}; use super::{ diff --git a/node/src/components/consensus/highway_core/highway.rs b/node/src/components/consensus/highway_core/highway.rs index ae7ac3169e..eb675b15d2 100644 --- a/node/src/components/consensus/highway_core/highway.rs +++ b/node/src/components/consensus/highway_core/highway.rs @@ -1,9 +1,8 @@ use super::{ active_validator::{ActiveValidator, Effect}, - evidence::Evidence, - state::{State, VoteError, Weight}, + state::{State, VoteError}, validators::Validators, - vertex::{Dependency, Vertex, WireVote}, + vertex::{Dependency, Vertex}, }; use thiserror::Error; use tracing::warn; @@ -67,12 +66,6 @@ impl From> for Vertex { #[derive(Clone, Debug, Eq, PartialEq)] pub(crate) struct ValidVertex(Vertex); -impl ValidVertex { - pub(crate) fn vertex(&self) -> &Vertex { - &self.0 - } -} - #[derive(Debug)] pub(crate) struct HighwayParams { /// The protocol instance ID. This needs to be unique, to prevent replay attacks. @@ -227,10 +220,6 @@ impl Highway { } } - pub(crate) fn state(&self) -> &State { - &self.state - } - fn on_new_vote(&self, vhash: &C::Hash, timestamp: u64) -> Vec> { self.active_validator .as_ref() @@ -262,7 +251,7 @@ impl Highway { fn do_validate_vertex(&self, vertex: &Vertex) -> Result<(), VertexError> { match vertex { Vertex::Vote(vote) => Ok(self.state.validate_vote(vote)?), - Vertex::Evidence(evidence) => Ok(()), + Vertex::Evidence(_evidence) => Ok(()), } } @@ -292,10 +281,9 @@ pub(crate) mod tests { highway_core::{ highway::{Highway, HighwayParams, VertexError, VoteError}, state::tests::{ - AddVoteError, TestContext, ALICE, ALICE_SEC, BOB, BOB_SEC, CAROL, CAROL_SEC, - WEIGHTS, + TestContext, ALICE, ALICE_SEC, BOB, BOB_SEC, CAROL, CAROL_SEC, WEIGHTS, }, - state::{State, Weight}, + state::State, validators::Validators, vertex::{SignedWireVote, Vertex, WireVote}, vote::Panorama, diff --git a/node/src/components/consensus/highway_core/state.rs b/node/src/components/consensus/highway_core/state.rs index b7e20921bd..a39c5e42cb 100644 --- a/node/src/components/consensus/highway_core/state.rs +++ b/node/src/components/consensus/highway_core/state.rs @@ -2,7 +2,6 @@ use std::{ cmp::Ordering, collections::HashMap, convert::identity, - fmt::{self, Display, Formatter}, iter, ops::{Div, Mul}, }; diff --git a/node/src/components/consensus/highway_core/tallies.rs b/node/src/components/consensus/highway_core/tallies.rs index 6c0bda8333..ee1083cd3c 100644 --- a/node/src/components/consensus/highway_core/tallies.rs +++ b/node/src/components/consensus/highway_core/tallies.rs @@ -176,11 +176,6 @@ impl<'a, C: Context> Tallies<'a, C> { .or_insert_with(|| Tally::new(bhash, weight)); } - /// Returns the number tallies. - pub(crate) fn len(&self) -> usize { - self.0.len() - } - /// Returns `true` if there are no tallies in this map. pub(crate) fn is_empty(&self) -> bool { self.0.is_empty() @@ -194,6 +189,13 @@ mod tests { *, }; + impl<'a> Tallies<'a, TestContext> { + /// Returns the number of tallies. + pub(crate) fn len(&self) -> usize { + self.0.len() + } + } + #[test] fn tallies() -> Result<(), AddVoteError> { let mut state = State::new(WEIGHTS, 0); diff --git a/node/src/components/consensus/highway_core/validators.rs b/node/src/components/consensus/highway_core/validators.rs index 186854073e..e4256c99ed 100644 --- a/node/src/components/consensus/highway_core/validators.rs +++ b/node/src/components/consensus/highway_core/validators.rs @@ -56,10 +56,6 @@ impl Validators { self.validators.iter().map(|v| v.weight()).sum() } - pub(crate) fn len(&self) -> usize { - self.validators.len() - } - pub(crate) fn get_index(&self, id: &VID) -> ValidatorIndex { *self.index_by_id.get(id).unwrap() } diff --git a/node/src/components/consensus/highway_core/vertex.rs b/node/src/components/consensus/highway_core/vertex.rs index 9e05633bf3..853a1df523 100644 --- a/node/src/components/consensus/highway_core/vertex.rs +++ b/node/src/components/consensus/highway_core/vertex.rs @@ -1,5 +1,3 @@ -use std::iter; - use serde::{Deserialize, Serialize}; use super::{evidence::Evidence, validators::ValidatorIndex, vote::Panorama}; diff --git a/node/src/components/consensus/highway_core/vote.rs b/node/src/components/consensus/highway_core/vote.rs index 25a5fcab14..f97ca0d8f4 100644 --- a/node/src/components/consensus/highway_core/vote.rs +++ b/node/src/components/consensus/highway_core/vote.rs @@ -1,8 +1,8 @@ use serde::{Deserialize, Serialize}; -use super::{state::State, validators::ValidatorIndex, vertex::WireVote}; +use super::{state::State, validators::ValidatorIndex}; use crate::components::consensus::highway_core::vertex::SignedWireVote; -use crate::components::consensus::traits::{Context, ValidatorSecret}; +use crate::components::consensus::traits::Context; /// The observed behavior of a validator at some point in time. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]