Fix clippy lints

This commit is contained in:
Paul Hauner 2019-01-04 18:30:24 +11:00
parent 62640ad691
commit 3876e29f6e
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
9 changed files with 25 additions and 18 deletions

View File

@ -8,7 +8,7 @@ pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBloc
BeaconBlock { BeaconBlock {
slot: spec.initial_slot_number, slot: spec.initial_slot_number,
parent_root: spec.zero_hash, parent_root: spec.zero_hash,
state_root: state_root, state_root,
randao_reveal: spec.zero_hash, randao_reveal: spec.zero_hash,
candidate_pow_receipt_root: spec.zero_hash, candidate_pow_receipt_root: spec.zero_hash,
signature: genesis_signature(), signature: genesis_signature(),

View File

@ -15,8 +15,8 @@ pub enum ForkChoiceError {
} }
pub fn naive_fork_choice<T>( pub fn naive_fork_choice<T>(
head_block_hashes: &Vec<Hash256>, head_block_hashes: &[Hash256],
block_store: Arc<BeaconBlockStore<T>>, block_store: &Arc<BeaconBlockStore<T>>,
) -> Result<Option<usize>, ForkChoiceError> ) -> Result<Option<usize>, ForkChoiceError>
where where
T: ClientDB + Sized, T: ClientDB + Sized,
@ -28,7 +28,7 @@ where
*/ */
for (index, block_hash) in head_block_hashes.iter().enumerate() { for (index, block_hash) in head_block_hashes.iter().enumerate() {
let ssz = block_store let ssz = block_store
.get(&block_hash.to_vec()[..])? .get(&block_hash)?
.ok_or(ForkChoiceError::MissingBlock)?; .ok_or(ForkChoiceError::MissingBlock)?;
let (block, _) = BeaconBlock::ssz_decode(&ssz, 0)?; let (block, _) = BeaconBlock::ssz_decode(&ssz, 0)?;
head_blocks.push((index, block)); head_blocks.push((index, block));

View File

@ -64,7 +64,7 @@ impl ChainSpec {
* Intialization parameters * Intialization parameters
*/ */
initial_validators: initial_validators_for_testing(), initial_validators: initial_validators_for_testing(),
genesis_time: 1544672897, genesis_time: 1_544_672_897,
processed_pow_receipt_root: Hash256::from("pow_root".as_bytes()), processed_pow_receipt_root: Hash256::from("pow_root".as_bytes()),
} }
} }

View File

@ -5,7 +5,7 @@ use rand::RngCore;
use ssz::{Decodable, DecodeError, Encodable, SszStream}; use ssz::{Decodable, DecodeError, Encodable, SszStream};
use std::convert; use std::convert;
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone, Copy)]
pub enum ValidatorStatus { pub enum ValidatorStatus {
PendingActivation, PendingActivation,
Active, Active,
@ -87,7 +87,7 @@ impl<T: RngCore> TestRandom<T> for ValidatorStatus {
ValidatorStatus::Withdrawn, ValidatorStatus::Withdrawn,
ValidatorStatus::Penalized, ValidatorStatus::Penalized,
]; ];
options[(rng.next_u32() as usize) % options.len()].clone() options[(rng.next_u32() as usize) % options.len()]
} }
} }

View File

@ -6,7 +6,7 @@ use bls_aggregates::AggregateSignature as RawAggregateSignature;
/// ///
/// This struct is a wrapper upon a base type and provides helper functions (e.g., SSZ /// This struct is a wrapper upon a base type and provides helper functions (e.g., SSZ
/// serialization). /// serialization).
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone, Default)]
pub struct AggregateSignature(RawAggregateSignature); pub struct AggregateSignature(RawAggregateSignature);
impl AggregateSignature { impl AggregateSignature {

View File

@ -26,7 +26,7 @@ impl SystemTimeSlotClock {
if slot_duration_seconds == 0 { if slot_duration_seconds == 0 {
Err(Error::SlotDurationIsZero) Err(Error::SlotDurationIsZero)
} else { } else {
Ok(SystemTimeSlotClock { Ok(Self {
genesis_seconds, genesis_seconds,
slot_duration_seconds, slot_duration_seconds,
}) })

View File

@ -23,25 +23,31 @@ where
.present_slot()? .present_slot()?
.ok_or(Error::PresentSlotIsNone)?; .ok_or(Error::PresentSlotIsNone)?;
let parent_root = self.canonical_leaf_block; let parent_root = self.canonical_leaf_block;
let parent_block = self let parent_block_reader = self
.block_store .block_store
.get_deserialized(&parent_root)? .get_reader(&parent_root)?
.ok_or(Error::DBError("Block not found.".to_string()))?; .ok_or_else(|| Error::DBError("Block not found.".to_string()))?;
let parent_state = self let parent_state_reader = self
.state_store .state_store
.get_deserialized(&parent_block.state_root())? .get_reader(&parent_block_reader.state_root())?
.ok_or(Error::DBError("State not found.".to_string()))?; .ok_or_else(|| Error::DBError("State not found.".to_string()))?;
let parent_block = parent_block_reader
.into_beacon_block()
.ok_or_else(|| Error::DBError("Bad parent block SSZ.".to_string()))?;
let mut block = BeaconBlock { let mut block = BeaconBlock {
slot: present_slot, slot: present_slot,
parent_root, parent_root,
state_root: Hash256::zero(), // Updated after the state is calculated. state_root: Hash256::zero(), // Updated after the state is calculated.
..parent_block.to_beacon_block() ..parent_block
}; };
let parent_state = parent_state_reader
.into_beacon_state()
.ok_or_else(|| Error::DBError("Bad parent block SSZ.".to_string()))?;
let state = BeaconState { let state = BeaconState {
slot: present_slot, slot: present_slot,
..parent_state.to_beacon_state() ..parent_state
}; };
let state_root = state.canonical_root(); let state_root = state.canonical_root();

View File

@ -55,7 +55,7 @@ where
block_store.put(&block_root, &ssz_encode(&genesis_block)[..])?; block_store.put(&block_root, &ssz_encode(&genesis_block)[..])?;
let mut leaf_blocks = HashSet::new(); let mut leaf_blocks = HashSet::new();
leaf_blocks.insert(block_root.clone()); leaf_blocks.insert(block_root);
Ok(Self { Ok(Self {
block_store, block_store,

View File

@ -20,6 +20,7 @@ macro_rules! impl_crud_for_store {
}; };
} }
#[allow(unused_macros)]
macro_rules! test_crud_for_store { macro_rules! test_crud_for_store {
($store: ident, $db_column: expr) => { ($store: ident, $db_column: expr) => {
#[test] #[test]