Clippy clean (#536)
* Change into_iter to iter * Fix clippy 'easy' warnings * Clippy eth2/utils * Add struct NetworkInfo * Clippy for types, utils, and beacon_node/store/src/iters.rs * Cargo fmt * Change foo to my_foo * Remove complex signature * suppress clippy warning for unit_value in benches * Use enumerate instead of iterating over range * Allow trivially_copy_pass_by_ref in serde_utils
This commit is contained in:
@@ -246,7 +246,7 @@ where
|
||||
|
||||
pub fn latest_message(&self, validator_index: usize) -> Option<(Hash256, Slot)> {
|
||||
match self.latest_votes.get_ref(validator_index) {
|
||||
Some(Some(v)) => Some((v.hash.clone(), v.slot.clone())),
|
||||
Some(Some(v)) => Some((v.hash, v.slot)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ fn get_worst_block<T: EthSpec>(
|
||||
builder.build(&spec)
|
||||
}
|
||||
|
||||
#[allow(clippy::unit_arg)]
|
||||
fn bench_block<T: EthSpec>(
|
||||
c: &mut Criterion,
|
||||
block: BeaconBlock<T>,
|
||||
|
||||
@@ -59,8 +59,8 @@ pub enum VerifySignatures {
|
||||
}
|
||||
|
||||
impl VerifySignatures {
|
||||
pub fn is_true(&self) -> bool {
|
||||
*self == VerifySignatures::True
|
||||
pub fn is_true(self) -> bool {
|
||||
self == VerifySignatures::True
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ pub fn is_valid_indexed_attestation<T: EthSpec>(
|
||||
let check_sorted = |list: &[u64]| -> Result<()> {
|
||||
list.windows(2).enumerate().try_for_each(|(i, pair)| {
|
||||
if pair[0] >= pair[1] {
|
||||
return Err(error(Invalid::BadValidatorIndicesOrdering(i)));
|
||||
Err(error(Invalid::BadValidatorIndicesOrdering(i)))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ fn invalid_block_header_state_slot() {
|
||||
let builder = get_builder(&spec);
|
||||
let (mut block, mut state) = builder.build(None, None, &spec);
|
||||
|
||||
state.slot = Slot::new(133713);
|
||||
block.slot = Slot::new(424242);
|
||||
state.slot = Slot::new(133_713);
|
||||
block.slot = Slot::new(424_242);
|
||||
|
||||
let result = per_block_processing(
|
||||
&mut state,
|
||||
|
||||
@@ -130,6 +130,6 @@ fn verify_casper_ffg_vote<'a, T: EthSpec>(
|
||||
);
|
||||
Ok(state.get_previous_crosslink(data.crosslink.shard)?)
|
||||
} else {
|
||||
return Err(error(Invalid::BadTargetEpoch));
|
||||
Err(error(Invalid::BadTargetEpoch))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ impl<T: EthSpec> BlockBuilder<T> {
|
||||
builder.set_parent_root(parent_root);
|
||||
|
||||
// Used as a stream of validator indices for use in slashings, exits, etc.
|
||||
let mut validators_iter = (0..keypairs.len() as u64).into_iter();
|
||||
let mut validators_iter = 0..keypairs.len() as u64;
|
||||
|
||||
// Insert `ProposerSlashing` objects.
|
||||
for _ in 0..self.num_proposer_slashings {
|
||||
@@ -171,7 +171,7 @@ impl<T: EthSpec> BlockBuilder<T> {
|
||||
info!("Inserted {} transfers.", builder.block.body.transfers.len());
|
||||
|
||||
// Set the eth1 data to be different from the state.
|
||||
self.block_builder.block.body.eth1_data.block_hash = Hash256::from_slice(&vec![42; 32]);
|
||||
self.block_builder.block.body.eth1_data.block_hash = Hash256::from_slice(&[42; 32]);
|
||||
|
||||
let block = self
|
||||
.block_builder
|
||||
|
||||
@@ -73,7 +73,6 @@ fn shuffles_for_the_right_epoch() {
|
||||
let spec = &MinimalEthSpec::default_spec();
|
||||
|
||||
let distinct_hashes: Vec<Hash256> = (0..MinimalEthSpec::epochs_per_historical_vector())
|
||||
.into_iter()
|
||||
.map(|i| Hash256::from_low_u64_be(i as u64))
|
||||
.collect();
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ fn tree_hash_cache() {
|
||||
|
||||
assert_eq!(root.as_bytes(), &state.tree_hash_root()[..]);
|
||||
|
||||
state.slot = state.slot + 1;
|
||||
state.slot += 1;
|
||||
|
||||
let root = state.update_tree_hash_cache().unwrap();
|
||||
assert_eq!(root.as_bytes(), &state.tree_hash_root()[..]);
|
||||
@@ -231,9 +231,8 @@ mod committees {
|
||||
shuffle_list(active_indices, spec.shuffle_round_count, &seed[..], false).unwrap();
|
||||
|
||||
let mut expected_indices_iter = shuffling.iter();
|
||||
let mut expected_shards_iter = (0..T::ShardCount::to_u64())
|
||||
.into_iter()
|
||||
.map(|i| (start_shard + i) % T::ShardCount::to_u64());
|
||||
let mut expected_shards_iter =
|
||||
(0..T::ShardCount::to_u64()).map(|i| (start_shard + i) % T::ShardCount::to_u64());
|
||||
|
||||
// Loop through all slots in the epoch being tested.
|
||||
for slot in epoch.slot_iter(T::slots_per_epoch()) {
|
||||
@@ -306,7 +305,6 @@ mod committees {
|
||||
let (mut state, _keypairs): (BeaconState<T>, _) = builder.build();
|
||||
|
||||
let distinct_hashes: Vec<Hash256> = (0..T::epochs_per_historical_vector())
|
||||
.into_iter()
|
||||
.map(|i| Hash256::from_low_u64_be(i as u64))
|
||||
.collect();
|
||||
state.randao_mixes = FixedVector::from(distinct_hashes);
|
||||
|
||||
@@ -123,7 +123,7 @@ impl<T: EthSpec> TestingBeaconStateBuilder<T> {
|
||||
.collect::<Vec<_>>()
|
||||
.into();
|
||||
|
||||
let genesis_time = 1567052589; // 29 August, 2019;
|
||||
let genesis_time = 1_567_052_589; // 29 August, 2019;
|
||||
|
||||
let mut state = BeaconState::new(
|
||||
genesis_time,
|
||||
|
||||
@@ -46,6 +46,7 @@ where
|
||||
Ok(array)
|
||||
}
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
pub fn fork_to_hex_str<S>(bytes: &[u8; FORK_BYTES_LEN], serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
|
||||
@@ -80,8 +80,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_ssz_round_trip() {
|
||||
let original =
|
||||
SecretKey::from_bytes("jzjxxgjajfjrmgodszzsgqccmhnyvetcuxobhtynojtpdtbj".as_bytes())
|
||||
.unwrap();
|
||||
SecretKey::from_bytes(b"jzjxxgjajfjrmgodszzsgqccmhnyvetcuxobhtynojtpdtbj").unwrap();
|
||||
|
||||
let bytes = ssz_encode(&original);
|
||||
let decoded = SecretKey::from_ssz_bytes(&bytes).unwrap();
|
||||
|
||||
@@ -58,10 +58,12 @@ pub fn be_private_key(validator_index: usize) -> [u8; PRIVATE_KEY_BYTES] {
|
||||
|
||||
/// Return a public and private keypair for a given `validator_index`.
|
||||
pub fn keypair(validator_index: usize) -> Keypair {
|
||||
let sk = SecretKey::from_bytes(&be_private_key(validator_index)).expect(&format!(
|
||||
"Should build valid private key for validator index {}",
|
||||
validator_index
|
||||
));
|
||||
let sk = SecretKey::from_bytes(&be_private_key(validator_index)).unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"Should build valid private key for validator index {}",
|
||||
validator_index
|
||||
)
|
||||
});
|
||||
|
||||
Keypair {
|
||||
pk: PublicKey::from_secret_key(&sk),
|
||||
|
||||
@@ -19,14 +19,11 @@ fn reference_private_keys() {
|
||||
"2908643403277969554503670470854573663206729491025062456164283925661321952518",
|
||||
"19554639423851580804889717218680781396599791537051606512605582393920758869044",
|
||||
];
|
||||
reference
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.for_each(|(i, reference)| {
|
||||
let bytes = be_private_key(i);
|
||||
let num = BigUint::from_bytes_be(&bytes);
|
||||
assert_eq!(&num.to_str_radix(10), reference)
|
||||
});
|
||||
reference.iter().enumerate().for_each(|(i, reference)| {
|
||||
let bytes = be_private_key(i);
|
||||
let num = BigUint::from_bytes_be(&bytes);
|
||||
assert_eq!(&num.to_str_radix(10), reference)
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -46,19 +43,16 @@ fn reference_public_keys() {
|
||||
"ptMQ27+rmiJFD1mZP4ekzl22Ij87Xx8w0sTscYki1ADgs8d0HejlmWD3JBGg7hCn",
|
||||
"mJNBPAAoOj+e2f2YRd2hzqOCKNIlZ/lUHczDV+VKLWpuIEEDySVky8BfSQWsfEk6",
|
||||
];
|
||||
reference
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.for_each(|(i, reference)| {
|
||||
let pair = keypair(i);
|
||||
let reference = base64::decode(reference).expect("Reference should be valid base64");
|
||||
reference.iter().enumerate().for_each(|(i, reference)| {
|
||||
let pair = keypair(i);
|
||||
let reference = base64::decode(reference).expect("Reference should be valid base64");
|
||||
|
||||
assert_eq!(
|
||||
reference.len(),
|
||||
48,
|
||||
"Reference should be 48 bytes (public key size)"
|
||||
);
|
||||
assert_eq!(
|
||||
reference.len(),
|
||||
48,
|
||||
"Reference should be 48 bytes (public key size)"
|
||||
);
|
||||
|
||||
assert_eq!(pair.pk.as_bytes(), reference);
|
||||
});
|
||||
assert_eq!(pair.pk.as_bytes(), reference);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,7 +100,9 @@ pub fn start_timer(histogram: &Result<Histogram>) -> Option<HistogramTimer> {
|
||||
|
||||
/// Stops a timer created with `start_timer(..)`.
|
||||
pub fn stop_timer(timer: Option<HistogramTimer>) {
|
||||
timer.map(|t| t.observe_duration());
|
||||
if let Some(t) = timer {
|
||||
t.observe_duration()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inc_counter(counter: &Result<IntCounter>) {
|
||||
|
||||
@@ -21,7 +21,7 @@ lazy_static! {
|
||||
|
||||
/// Zero nodes to act as "synthetic" left and right subtrees of other zero nodes.
|
||||
static ref ZERO_NODES: Vec<MerkleTree> = {
|
||||
(0..MAX_TREE_DEPTH + 1).map(MerkleTree::Zero).collect()
|
||||
(0..=MAX_TREE_DEPTH).map(MerkleTree::Zero).collect()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ mod tests {
|
||||
let merkle_tree = MerkleTree::create(&leaves, depth);
|
||||
let merkle_root = merkle_tree.hash();
|
||||
|
||||
let proofs_ok = (0..leaves.len()).into_iter().all(|i| {
|
||||
let proofs_ok = (0..leaves.len()).all(|i| {
|
||||
let (leaf, branch) = merkle_tree.generate_proof(i, depth);
|
||||
leaf == leaves[i] && verify_merkle_proof(leaf, &branch, depth, i, merkle_root)
|
||||
});
|
||||
|
||||
@@ -8,7 +8,6 @@ fn main() {
|
||||
let vec: Vec<u64> = vec![4242; 8196];
|
||||
|
||||
let output: Vec<Vec<u64>> = (0..40_000)
|
||||
.into_iter()
|
||||
.map(|_| Vec::from_ssz_bytes(&vec.as_ssz_bytes()).unwrap())
|
||||
.collect();
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ fn main() {
|
||||
let vec: Vec<FixedLen> = vec![fixed_len; 8196];
|
||||
|
||||
let output: Vec<Vec<u64>> = (0..40_000)
|
||||
.into_iter()
|
||||
.map(|_| Vec::from_ssz_bytes(&vec.as_ssz_bytes()).unwrap())
|
||||
.collect();
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ impl Decode for Foo {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let foo = Foo {
|
||||
let my_foo = Foo {
|
||||
a: 42,
|
||||
b: vec![0, 1, 2, 3],
|
||||
c: 11,
|
||||
@@ -65,9 +65,9 @@ fn main() {
|
||||
|
||||
let bytes = vec![42, 0, 8, 0, 0, 0, 11, 0, 0, 1, 2, 3];
|
||||
|
||||
assert_eq!(foo.as_ssz_bytes(), bytes);
|
||||
assert_eq!(my_foo.as_ssz_bytes(), bytes);
|
||||
|
||||
let decoded_foo = Foo::from_ssz_bytes(&bytes).unwrap();
|
||||
|
||||
assert_eq!(foo, decoded_foo);
|
||||
assert_eq!(my_foo, decoded_foo);
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ impl<T: Encode> Encode for Vec<T> {
|
||||
if <T as Encode>::is_ssz_fixed_len() {
|
||||
<T as Encode>::ssz_fixed_len() * self.len()
|
||||
} else {
|
||||
let mut len = self.into_iter().map(|item| item.ssz_bytes_len()).sum();
|
||||
let mut len = self.iter().map(|item| item.ssz_bytes_len()).sum();
|
||||
len += BYTES_PER_LENGTH_OFFSET * self.len();
|
||||
len
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user