Fix clippy lints

This commit is contained in:
Paul Hauner 2019-05-09 13:35:00 +10:00
parent 0ac278f44d
commit 2a938f2fd5
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
13 changed files with 20 additions and 23 deletions

View File

@ -191,7 +191,6 @@ where
count: usize, count: usize,
skip: usize, skip: usize,
) -> Result<Vec<Hash256>, Error> { ) -> Result<Vec<Hash256>, Error> {
let spec = &self.spec;
let step_by = Slot::from(skip + 1); let step_by = Slot::from(skip + 1);
let mut roots: Vec<Hash256> = vec![]; let mut roots: Vec<Hash256> = vec![];

View File

@ -1,16 +1,13 @@
use crate::ClientConfig; use crate::{ArcBeaconChain, ClientConfig};
use beacon_chain::{ use beacon_chain::{
db::{ClientDB, DiskDB, MemoryDB}, db::{ClientDB, DiskDB, MemoryDB},
fork_choice::BitwiseLMDGhost, fork_choice::BitwiseLMDGhost,
initialise, initialise,
slot_clock::{SlotClock, SystemTimeSlotClock}, slot_clock::{SlotClock, SystemTimeSlotClock},
BeaconChain,
}; };
use fork_choice::ForkChoice; use fork_choice::ForkChoice;
use types::{BeaconStateTypes, FewValidatorsStateTypes, FoundationStateTypes}; use types::{BeaconStateTypes, FewValidatorsStateTypes, FoundationStateTypes};
use std::sync::Arc;
pub trait ClientTypes { pub trait ClientTypes {
type DB: ClientDB + 'static; type DB: ClientDB + 'static;
type SlotClock: SlotClock + 'static; type SlotClock: SlotClock + 'static;
@ -19,7 +16,7 @@ pub trait ClientTypes {
fn initialise_beacon_chain( fn initialise_beacon_chain(
config: &ClientConfig, config: &ClientConfig,
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes>>; ) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes>;
} }
pub struct StandardClientType; pub struct StandardClientType;
@ -32,7 +29,7 @@ impl ClientTypes for StandardClientType {
fn initialise_beacon_chain( fn initialise_beacon_chain(
config: &ClientConfig, config: &ClientConfig,
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes>> { ) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes> {
initialise::initialise_beacon_chain(&config.spec, Some(&config.db_name)) initialise::initialise_beacon_chain(&config.spec, Some(&config.db_name))
} }
} }
@ -47,7 +44,7 @@ impl ClientTypes for TestingClientType {
fn initialise_beacon_chain( fn initialise_beacon_chain(
config: &ClientConfig, config: &ClientConfig,
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes>> { ) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes> {
initialise::initialise_test_beacon_chain(&config.spec, None) initialise::initialise_test_beacon_chain(&config.spec, None)
} }
} }

View File

@ -22,13 +22,15 @@ use tokio::runtime::TaskExecutor;
use tokio::timer::Interval; use tokio::timer::Interval;
use types::BeaconStateTypes; use types::BeaconStateTypes;
type ArcBeaconChain<D, S, F, B> = Arc<BeaconChain<D, S, F, B>>;
/// Main beacon node client service. This provides the connection and initialisation of the clients /// Main beacon node client service. This provides the connection and initialisation of the clients
/// sub-services in multiple threads. /// sub-services in multiple threads.
pub struct Client<T: ClientTypes> { pub struct Client<T: ClientTypes> {
/// Configuration for the lighthouse client. /// Configuration for the lighthouse client.
_config: ClientConfig, _config: ClientConfig,
/// The beacon chain for the running client. /// The beacon chain for the running client.
_beacon_chain: Arc<BeaconChain<T::DB, T::SlotClock, T::ForkChoice, T::BeaconStateTypes>>, _beacon_chain: ArcBeaconChain<T::DB, T::SlotClock, T::ForkChoice, T::BeaconStateTypes>,
/// Reference to the network service. /// Reference to the network service.
pub network: Arc<NetworkService<T::BeaconStateTypes>>, pub network: Arc<NetworkService<T::BeaconStateTypes>>,
/// Signal to terminate the RPC server. /// Signal to terminate the RPC server.

View File

@ -97,7 +97,7 @@ impl ClientDB for DiskDB {
None => Err(DBError { None => Err(DBError {
message: "Unknown column".to_string(), message: "Unknown column".to_string(),
}), }),
Some(handle) => self.db.put_cf(handle, key, val).map_err(|e| e.into()), Some(handle) => self.db.put_cf(handle, key, val).map_err(Into::into),
} }
} }

View File

@ -2,7 +2,7 @@ use super::STATES_DB_COLUMN as DB_COLUMN;
use super::{ClientDB, DBError}; use super::{ClientDB, DBError};
use ssz::decode; use ssz::decode;
use std::sync::Arc; use std::sync::Arc;
use types::{BeaconState, BeaconStateTypes, FoundationBeaconState, Hash256}; use types::{BeaconState, BeaconStateTypes, Hash256};
pub struct BeaconStateStore<T> pub struct BeaconStateStore<T>
where where
@ -43,7 +43,7 @@ mod tests {
use ssz::ssz_encode; use ssz::ssz_encode;
use std::sync::Arc; use std::sync::Arc;
use types::test_utils::{SeedableRng, TestRandom, XorShiftRng}; use types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use types::Hash256; use types::{FoundationBeaconState, Hash256};
test_crud_for_store!(BeaconStateStore, DB_COLUMN); test_crud_for_store!(BeaconStateStore, DB_COLUMN);

View File

@ -300,7 +300,7 @@ impl NetworkContext {
let next_id = self let next_id = self
.outgoing_request_ids .outgoing_request_ids
.entry(peer_id.clone()) .entry(peer_id.clone())
.and_modify(|id| id.increment()) .and_modify(RequestId::increment)
.or_insert_with(|| RequestId::from(1)); .or_insert_with(|| RequestId::from(1));
next_id.previous() next_id.previous()

View File

@ -175,11 +175,7 @@ impl<T: BeaconStateTypes> OperationPool<T> {
/// Total number of attestations in the pool, including attestations for the same data. /// Total number of attestations in the pool, including attestations for the same data.
pub fn num_attestations(&self) -> usize { pub fn num_attestations(&self) -> usize {
self.attestations self.attestations.read().values().map(Vec::len).sum()
.read()
.values()
.map(|atts| atts.len())
.sum()
} }
/// Get a list of attestations for inclusion in a block. /// Get a list of attestations for inclusion in a block.

View File

@ -817,7 +817,7 @@ impl<T: BeaconStateTypes> BeaconState<T> {
self.tree_hash_cache self.tree_hash_cache
.tree_hash_root() .tree_hash_root()
.and_then(|b| Ok(Hash256::from_slice(b))) .and_then(|b| Ok(Hash256::from_slice(b)))
.map_err(|e| e.into()) .map_err(Into::into)
} }
} }

View File

@ -226,7 +226,7 @@ impl Decodable for BooleanBitfield {
// as the BitVec library and the hex-parser use opposing bit orders. // as the BitVec library and the hex-parser use opposing bit orders.
fn reverse_bit_order(mut bytes: Vec<u8>) -> Vec<u8> { fn reverse_bit_order(mut bytes: Vec<u8>) -> Vec<u8> {
bytes.reverse(); bytes.reverse();
bytes.into_iter().map(|b| b.swap_bits()).collect() bytes.into_iter().map(LookupReverse::swap_bits).collect()
} }
impl Serialize for BooleanBitfield { impl Serialize for BooleanBitfield {

View File

@ -22,6 +22,10 @@ impl<T, N: Unsigned> FixedLenVec<T, N> {
self.vec.len() self.vec.len()
} }
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn capacity() -> usize { pub fn capacity() -> usize {
N::to_usize() N::to_usize()
} }

View File

@ -35,7 +35,7 @@ pub fn merkle_root(values: &[Vec<u8>]) -> Option<Vec<u8>> {
} }
// the root hash will be at index 1 // the root hash will be at index 1
return Some(o[1].clone()); Some(o[1].clone())
} }
#[cfg(test)] #[cfg(test)]

View File

@ -51,7 +51,7 @@ impl<U: BeaconNodeDuties, S: Signer + Display> DutiesManager<U, S> {
/// ///
/// be a wall-clock (e.g., system time, remote server time, etc.). /// be a wall-clock (e.g., system time, remote server time, etc.).
fn update(&self, epoch: Epoch) -> Result<UpdateOutcome, Error> { fn update(&self, epoch: Epoch) -> Result<UpdateOutcome, Error> {
let public_keys: Vec<PublicKey> = self.signers.iter().map(|s| s.to_public()).collect(); let public_keys: Vec<PublicKey> = self.signers.iter().map(Signer::to_public).collect();
let duties = self.beacon_node.request_duties(epoch, &public_keys)?; let duties = self.beacon_node.request_duties(epoch, &public_keys)?;
{ {
// If these duties were known, check to see if they're updates or identical. // If these duties were known, check to see if they're updates or identical.

View File

@ -31,7 +31,6 @@ use tokio::prelude::*;
use tokio::runtime::Builder; use tokio::runtime::Builder;
use tokio::timer::Interval; use tokio::timer::Interval;
use tokio_timer::clock::Clock; use tokio_timer::clock::Clock;
use types::test_utils::generate_deterministic_keypairs;
use types::{ChainSpec, Epoch, Fork, Slot}; use types::{ChainSpec, Epoch, Fork, Slot};
/// A fixed amount of time after a slot to perform operations. This gives the node time to complete /// A fixed amount of time after a slot to perform operations. This gives the node time to complete