Fix clippy warnings (#813)

* Clippy account manager

* Clippy account_manager

* Clippy beacon_node/beacon_chain

* Clippy beacon_node/client

* Clippy beacon_node/eth1

* Clippy beacon_node/eth2-libp2p

* Clippy beacon_node/genesis

* Clippy beacon_node/network

* Clippy beacon_node/rest_api

* Clippy beacon_node/src

* Clippy beacon_node/store

* Clippy eth2/lmd_ghost

* Clippy eth2/operation_pool

* Clippy eth2/state_processing

* Clippy eth2/types

* Clippy eth2/utils/bls

* Clippy eth2/utils/cahced_tree_hash

* Clippy eth2/utils/deposit_contract

* Clippy eth2/utils/eth2_interop_keypairs

* Clippy eth2/utils/eth2_testnet_config

* Clippy eth2/utils/lighthouse_metrics

* Clippy eth2/utils/ssz

* Clippy eth2/utils/ssz_types

* Clippy eth2/utils/tree_hash_derive

* Clippy lcli

* Clippy tests/beacon_chain_sim

* Clippy validator_client

* Cargo fmt
This commit is contained in:
pscott
2020-01-21 11:38:56 +04:00
committed by Age Manning
parent 1abb964652
commit 7396cd2cab
78 changed files with 387 additions and 416 deletions

View File

@@ -1,5 +1,6 @@
use super::*;
use ssz::{Decode, DecodeError};
use std::cmp::Ordering;
fn get_block_bytes<T: Store<E>, E: EthSpec>(
store: &T,
@@ -45,12 +46,10 @@ fn get_at_preceeding_slot<T: Store<E>, E: EthSpec>(
if let Some(bytes) = get_block_bytes::<_, E>(store, root)? {
let this_slot = read_slot_from_block_bytes(&bytes)?;
if this_slot == slot {
break Ok(Some((root, bytes)));
} else if this_slot < slot {
break Ok(None);
} else {
root = read_parent_root_from_block_bytes(&bytes)?;
match this_slot.cmp(&slot) {
Ordering::Equal => break Ok(Some((root, bytes))),
Ordering::Less => break Ok(None),
Ordering::Greater => root = read_parent_root_from_block_bytes(&bytes)?,
}
} else {
break Ok(None);

View File

@@ -237,7 +237,7 @@ mod test {
.add_block_root(int_hash(i), int_hash(i - 1), Slot::new(i))
.expect("add_block_root ok");
let expected = (1..i + 1)
let expected = (1..=i)
.rev()
.map(|j| (int_hash(j), Slot::new(j)))
.collect::<Vec<_>>();
@@ -262,12 +262,12 @@ mod test {
.add_block_root(int_hash(i), int_hash(i - step_length), Slot::new(i))
.expect("add_block_root ok");
let sparse_expected = (1..i + 1)
let sparse_expected = (1..=i)
.rev()
.step_by(step_length as usize)
.map(|j| (int_hash(j), Slot::new(j)))
.collect_vec();
let every_slot_expected = (1..i + 1)
let every_slot_expected = (1..=i)
.rev()
.map(|j| {
let nearest = 1 + (j - 1) / step_length * step_length;
@@ -343,10 +343,9 @@ mod test {
// Check that advancing the finalized root onto one side completely removes the other
// side.
let fin_tree = tree.clone();
let fin_tree = tree;
let prune_point = num_blocks / 2;
let remaining_fork1_blocks = all_fork1_blocks
.clone()
.into_iter()
.take_while(|(_, slot)| *slot >= prune_point)
.collect_vec();

View File

@@ -185,7 +185,7 @@ pub trait Field<E: EthSpec>: Copy {
.values
.first()
.cloned()
.ok_or(ChunkError::MissingGenesisValue.into())
.ok_or_else(|| ChunkError::MissingGenesisValue.into())
}
/// Store the given `value` as the genesis value for this field, unless stored already.
@@ -685,7 +685,7 @@ mod test {
];
assert_eq!(
stitch(chunks.clone(), 2, 6, chunk_size, 12, 99).unwrap(),
stitch(chunks, 2, 6, chunk_size, 12, 99).unwrap(),
vec![99, 99, 2, 3, 4, 5, 99, 99, 99, 99, 99, 99]
);
}
@@ -707,7 +707,7 @@ mod test {
);
assert_eq!(
stitch(chunks.clone(), 2, 10, chunk_size, 8, default).unwrap(),
stitch(chunks, 2, 10, chunk_size, 8, default).unwrap(),
vec![v(8), v(9), v(2), v(3), v(4), v(5), v(6), v(7)]
);
}

View File

@@ -20,9 +20,9 @@ pub struct SimpleForwardsBlockRootsIterator {
/// Fusion of the above two approaches to forwards iteration. Fast and efficient.
pub enum HybridForwardsBlockRootsIterator<E: EthSpec> {
PreFinalization {
iter: FrozenForwardsBlockRootsIterator<E>,
iter: Box<FrozenForwardsBlockRootsIterator<E>>,
/// Data required by the `PostFinalization` iterator when we get to it.
continuation_data: Option<(BeaconState<E>, Hash256)>,
continuation_data: Box<Option<(BeaconState<E>, Hash256)>>,
},
PostFinalization {
iter: SimpleForwardsBlockRootsIterator,
@@ -99,13 +99,13 @@ impl<E: EthSpec> HybridForwardsBlockRootsIterator<E> {
if start_slot < latest_restore_point_slot {
PreFinalization {
iter: FrozenForwardsBlockRootsIterator::new(
iter: Box::new(FrozenForwardsBlockRootsIterator::new(
store,
start_slot,
latest_restore_point_slot,
spec,
),
continuation_data: Some((end_state, end_block_root)),
)),
continuation_data: Box::new(Some((end_state, end_block_root))),
}
} else {
PostFinalization {

View File

@@ -145,14 +145,15 @@ impl<E: EthSpec> Store<E> for HotColdDB<E> {
let current_split_slot = store.get_split_slot();
if frozen_head.slot < current_split_slot {
Err(HotColdDBError::FreezeSlotError {
return Err(HotColdDBError::FreezeSlotError {
current_split_slot,
proposed_split_slot: frozen_head.slot,
})?;
}
.into());
}
if frozen_head.slot % E::slots_per_epoch() != 0 {
Err(HotColdDBError::FreezeSlotUnaligned(frozen_head.slot))?;
return Err(HotColdDBError::FreezeSlotUnaligned(frozen_head.slot).into());
}
// 1. Copy all of the states between the head and the split slot, from the hot DB
@@ -574,7 +575,7 @@ impl<E: EthSpec> HotColdDB<E> {
let key = Self::restore_point_key(restore_point_index);
RestorePointHash::db_get(&self.cold_db, &key)?
.map(|r| r.state_root)
.ok_or(HotColdDBError::MissingRestorePointHash(restore_point_index).into())
.ok_or_else(|| HotColdDBError::MissingRestorePointHash(restore_point_index).into())
}
/// Store the state root of a restore point.

View File

@@ -345,7 +345,7 @@ mod test {
state_b.state_roots[0] = state_a_root;
store.put_state(&state_a_root, &state_a).unwrap();
let iter = BlockRootsIterator::new(store.clone(), &state_b);
let iter = BlockRootsIterator::new(store, &state_b);
assert!(
iter.clone().any(|(_root, slot)| slot == 0),
@@ -394,7 +394,7 @@ mod test {
store.put_state(&state_a_root, &state_a).unwrap();
store.put_state(&state_b_root, &state_b).unwrap();
let iter = StateRootsIterator::new(store.clone(), &state_b);
let iter = StateRootsIterator::new(store, &state_b);
assert!(
iter.clone().any(|(_root, slot)| slot == 0),

View File

@@ -47,11 +47,7 @@ impl<E: EthSpec> Store<E> for MemoryStore<E> {
fn get_bytes(&self, col: &str, key: &[u8]) -> Result<Option<Vec<u8>>, Error> {
let column_key = Self::get_key_for_col(col, key);
Ok(self
.db
.read()
.get(&column_key)
.and_then(|val| Some(val.clone())))
Ok(self.db.read().get(&column_key).cloned())
}
/// Puts a key in the database.

View File

@@ -60,13 +60,12 @@ impl<E: EthSpec, S: Store<E>> Migrate<S, E> for BlockingMigrator<S> {
}
}
type MpscSender<E> = mpsc::Sender<(Hash256, BeaconState<E>)>;
/// Migrator that runs a background thread to migrate state from the hot to the cold database.
pub struct BackgroundMigrator<E: EthSpec> {
db: Arc<DiskStore<E>>,
tx_thread: Mutex<(
mpsc::Sender<(Hash256, BeaconState<E>)>,
thread::JoinHandle<()>,
)>,
tx_thread: Mutex<(MpscSender<E>, thread::JoinHandle<()>)>,
}
impl<E: EthSpec> Migrate<DiskStore<E>, E> for BackgroundMigrator<E> {