From ede5685bc298313d564b38a24a5bbfcbe2a38339 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sun, 3 Mar 2019 11:47:09 +1100 Subject: [PATCH] Fix warnings and clippy lints --- .../test_harness/src/beacon_chain_harness.rs | 11 ----------- .../src/validator_harness/local_signer.rs | 13 +------------ .../verify_slashable_attestation.rs | 6 +----- eth2/types/src/attester_slashing/builder.rs | 4 ++-- eth2/types/src/beacon_state.rs | 3 +-- eth2/types/src/proposer_slashing/builder.rs | 4 ++-- eth2/utils/bls/src/aggregate_public_key.rs | 2 +- 7 files changed, 8 insertions(+), 35 deletions(-) diff --git a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs index 9060c4ec1..d6608cd39 100644 --- a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs +++ b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs @@ -10,10 +10,7 @@ use fork_choice::BitwiseLMDGhost; use log::debug; use rayon::prelude::*; use slot_clock::TestingSlotClock; -use ssz::TreeHash; use std::collections::HashSet; -use std::fs::File; -use std::io::prelude::*; use std::iter::FromIterator; use std::sync::Arc; use types::*; @@ -291,12 +288,4 @@ impl BeaconChainHarness { pub fn chain_dump(&self) -> Result, BeaconChainError> { self.beacon_chain.chain_dump() } - - /// Write the output of `chain_dump` to a JSON file. - pub fn dump_to_file(&self, filename: String, chain_dump: &[CheckPoint]) { - let json = serde_json::to_string(chain_dump).unwrap(); - let mut file = File::create(filename).unwrap(); - file.write_all(json.as_bytes()) - .expect("Failed writing dump to file."); - } } diff --git a/beacon_node/beacon_chain/test_harness/src/validator_harness/local_signer.rs b/beacon_node/beacon_chain/test_harness/src/validator_harness/local_signer.rs index 3f249cb19..803af5045 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator_harness/local_signer.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator_harness/local_signer.rs @@ -1,27 +1,16 @@ use attester::Signer as AttesterSigner; use block_proposer::Signer as BlockProposerSigner; -use std::sync::RwLock; use types::{Keypair, Signature}; /// A test-only struct used to perform signing for a proposer or attester. pub struct LocalSigner { keypair: Keypair, - should_sign: RwLock, } impl LocalSigner { /// Produce a new TestSigner with signing enabled by default. pub fn new(keypair: Keypair) -> Self { - Self { - keypair, - should_sign: RwLock::new(true), - } - } - - /// If set to `false`, the service will refuse to sign all messages. Otherwise, all messages - /// will be signed. - pub fn enable_signing(&self, enabled: bool) { - *self.should_sign.write().unwrap() = enabled; + Self { keypair } } /// Sign some message. diff --git a/eth2/state_processing/src/block_processable/verify_slashable_attestation.rs b/eth2/state_processing/src/block_processable/verify_slashable_attestation.rs index dddc2eb1f..35ad67df0 100644 --- a/eth2/state_processing/src/block_processable/verify_slashable_attestation.rs +++ b/eth2/state_processing/src/block_processable/verify_slashable_attestation.rs @@ -1,5 +1,4 @@ use super::Error; -use log::error; use types::*; macro_rules! ensure { @@ -27,17 +26,14 @@ pub fn verify_slashable_attestation( | slashable_attestation_1.is_surround_vote(slashable_attestation_2, spec), Error::BadAttesterSlashing ); - error!("this a"); ensure!( state.verify_slashable_attestation(&slashable_attestation_1, spec), Error::BadAttesterSlashing ); - error!("this b"); ensure!( state.verify_slashable_attestation(&slashable_attestation_2, spec), Error::BadAttesterSlashing ); - error!("this c"); let mut slashable_indices = vec![]; for i in &slashable_attestation_1.validator_indices { @@ -53,7 +49,7 @@ pub fn verify_slashable_attestation( } } - ensure!(slashable_indices.len() >= 1, Error::BadAttesterSlashing); + ensure!(!slashable_indices.is_empty(), Error::BadAttesterSlashing); for i in slashable_indices { state.penalize_validator(*i as usize, spec)?; diff --git a/eth2/types/src/attester_slashing/builder.rs b/eth2/types/src/attester_slashing/builder.rs index d382cb64c..e53706192 100644 --- a/eth2/types/src/attester_slashing/builder.rs +++ b/eth2/types/src/attester_slashing/builder.rs @@ -16,8 +16,8 @@ impl AttesterSlashingBuilder { let shard = 0; let justified_epoch = Epoch::new(0); let epoch = Epoch::new(0); - let hash_1 = Hash256::from("1".as_bytes()); - let hash_2 = Hash256::from("2".as_bytes()); + let hash_1 = Hash256::from(&[1][..]); + let hash_2 = Hash256::from(&[2][..]); let mut slashable_attestation_1 = SlashableAttestation { validator_indices: validator_indices.to_vec(), diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index 505d4d9de..932233445 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -419,8 +419,7 @@ impl BeaconState { committees_per_epoch ); - let active_validator_indices: Vec = - active_validator_indices.iter().cloned().collect(); + let active_validator_indices: Vec = active_validator_indices.to_vec(); let shuffled_active_validator_indices = shuffle_list( active_validator_indices, diff --git a/eth2/types/src/proposer_slashing/builder.rs b/eth2/types/src/proposer_slashing/builder.rs index a43a73ff0..363155a14 100644 --- a/eth2/types/src/proposer_slashing/builder.rs +++ b/eth2/types/src/proposer_slashing/builder.rs @@ -14,13 +14,13 @@ impl ProposerSlashingBuilder { let proposal_data_1 = ProposalSignedData { slot, shard, - block_root: Hash256::from("one".as_bytes()), + block_root: Hash256::from(&[1][..]), }; let proposal_data_2 = ProposalSignedData { slot, shard, - block_root: Hash256::from("two".as_bytes()), + block_root: Hash256::from(&[2][..]), }; let proposal_signature_1 = { diff --git a/eth2/utils/bls/src/aggregate_public_key.rs b/eth2/utils/bls/src/aggregate_public_key.rs index dcb08126c..2174a43cb 100644 --- a/eth2/utils/bls/src/aggregate_public_key.rs +++ b/eth2/utils/bls/src/aggregate_public_key.rs @@ -5,7 +5,7 @@ use bls_aggregates::AggregatePublicKey as RawAggregatePublicKey; /// /// This struct is a wrapper upon a base type and provides helper functions (e.g., SSZ /// serialization). -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct AggregatePublicKey(RawAggregatePublicKey); impl AggregatePublicKey {