From e5ca37ed5e5207e6c0bb3d88b927c1e172f65c96 Mon Sep 17 00:00:00 2001 From: blacktemplar Date: Thu, 23 Jul 2020 13:34:30 +0000 Subject: [PATCH] Fix clippy warnings (#1385) ## Issue Addressed NA ## Proposed Changes Fixes most clippy warnings and ignores the rest of them, see issue #1388. --- Makefile | 2 +- .../src/upgrade_legacy_keypairs.rs | 4 +- account_manager/src/validator/deposit.rs | 1 - account_manager/src/validator/mod.rs | 10 +-- account_manager/src/wallet/create.rs | 14 ++-- account_manager/src/wallet/mod.rs | 10 +-- .../src/attestation_verification.rs | 16 ++-- beacon_node/beacon_chain/src/beacon_chain.rs | 51 ++++++----- .../beacon_chain/src/block_verification.rs | 5 +- beacon_node/beacon_chain/src/builder.rs | 12 ++- beacon_node/beacon_chain/src/eth1_chain.rs | 5 +- beacon_node/beacon_chain/src/events.rs | 12 ++- beacon_node/beacon_chain/src/migrate.rs | 3 +- .../beacon_chain/src/observed_attesters.rs | 6 +- beacon_node/beacon_chain/src/test_utils.rs | 3 + .../src/validator_pubkey_cache.rs | 17 ++-- .../beacon_chain/tests/block_verification.rs | 31 ++++--- beacon_node/client/src/builder.rs | 4 +- beacon_node/client/src/error.rs | 2 - beacon_node/client/src/notifier.rs | 55 ++++++------ beacon_node/eth1/src/service.rs | 2 +- .../src/behaviour/handler/delegate.rs | 21 ++--- .../eth2_libp2p/src/behaviour/handler/mod.rs | 1 + beacon_node/eth2_libp2p/src/behaviour/mod.rs | 4 +- beacon_node/eth2_libp2p/src/discovery/enr.rs | 4 +- .../eth2_libp2p/src/discovery/enr_ext.rs | 6 +- .../eth2_libp2p/src/peer_manager/mod.rs | 6 +- .../eth2_libp2p/src/peer_manager/score.rs | 2 +- .../eth2_libp2p/src/rpc/codec/ssz_snappy.rs | 18 ++-- beacon_node/eth2_libp2p/src/rpc/handler.rs | 2 +- beacon_node/eth2_libp2p/src/rpc/methods.rs | 2 +- .../network/src/attestation_service/mod.rs | 84 +++++++++---------- beacon_node/network/src/persisted_dht.rs | 1 - beacon_node/network/src/service.rs | 1 + beacon_node/network/src/sync/manager.rs | 6 +- .../network/src/sync/peer_sync_info.rs | 7 +- .../network/src/sync/range_sync/chain.rs | 3 +- beacon_node/rest_api/src/beacon.rs | 4 +- beacon_node/rest_api/src/helpers.rs | 1 - beacon_node/rest_api/src/node.rs | 3 +- beacon_node/src/config.rs | 7 +- beacon_node/src/lib.rs | 2 +- beacon_node/store/src/chunked_vector.rs | 1 + beacon_node/store/src/forwards_iter.rs | 2 +- beacon_node/store/src/leveldb_store.rs | 4 +- beacon_node/store/src/partial_beacon_state.rs | 8 +- boot_node/src/config.rs | 10 +-- boot_node/src/lib.rs | 1 - common/clap_utils/src/lib.rs | 1 - common/deposit_contract/build.rs | 5 +- common/eth2_testnet_config/build.rs | 1 - .../eth2_wallet_manager/src/wallet_manager.rs | 2 +- common/hashset_delay/src/hashset_delay.rs | 5 ++ common/remote_beacon_node/src/lib.rs | 2 +- common/rest_types/src/node.rs | 22 ++--- common/slot_clock/src/manual_slot_clock.rs | 10 +-- common/validator_dir/src/validator_dir.rs | 2 +- consensus/fork_choice/src/fork_choice.rs | 55 ++++++------ consensus/proto_array/src/bin.rs | 1 - consensus/proto_array/src/proto_array.rs | 12 ++- .../src/proto_array_fork_choice.rs | 6 +- consensus/proto_array/src/ssz_container.rs | 2 +- consensus/ssz/src/decode.rs | 11 ++- consensus/ssz_types/src/fixed_vector.rs | 3 +- .../src/per_block_processing.rs | 4 +- .../block_processing_builder.rs | 2 +- .../block_signature_verifier.rs | 4 +- .../per_block_processing/signature_sets.rs | 4 +- .../verify_attestation.rs | 8 +- .../src/per_epoch_processing.rs | 6 +- .../src/per_slot_processing.rs | 11 +-- consensus/types/src/beacon_state.rs | 8 +- .../types/src/beacon_state/tree_hash_cache.rs | 13 +-- .../testing_attestation_data_builder.rs | 4 +- .../testing_attester_slashing_builder.rs | 2 +- crypto/bls/src/signature_set.rs | 2 +- crypto/eth2_key_derivation/src/derived_key.rs | 2 +- crypto/eth2_key_derivation/src/plain_text.rs | 5 ++ .../src/json_keystore/hex_bytes.rs | 4 + .../src/json_keystore/kdf_module.rs | 2 +- crypto/eth2_keystore/src/keystore.rs | 4 +- lcli/src/deploy_deposit_contract.rs | 1 - lcli/src/new_testnet.rs | 12 ++- lighthouse/environment/src/executor.rs | 2 +- lighthouse/src/main.rs | 4 +- testing/simulator/src/eth1_sim.rs | 10 +-- testing/simulator/src/no_eth1_sim.rs | 8 +- testing/simulator/src/sync_sim.rs | 6 +- validator_client/src/attestation_service.rs | 2 +- validator_client/src/duties_service.rs | 4 +- validator_client/src/fork_service.rs | 2 +- .../src/initialized_validators.rs | 7 +- validator_client/src/validator_definitions.rs | 10 +-- 93 files changed, 386 insertions(+), 383 deletions(-) diff --git a/Makefile b/Makefile index 76da24603c1..dd408e3ae5b 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ test-full: cargo-fmt test-release test-debug test-ef # Lints the code for bad style and potentially unsafe arithmetic using Clippy. # Clippy lints are opt-in per-crate for now. By default, everything is allowed except for performance and correctness lints. lint: - cargo clippy --all -- -A clippy::all --D clippy::perf --D clippy::correctness + cargo clippy --all -- -D warnings # Runs the makefile in the `ef_tests` repo. # diff --git a/account_manager/src/upgrade_legacy_keypairs.rs b/account_manager/src/upgrade_legacy_keypairs.rs index 77e9fe8059e..3d91bce0486 100644 --- a/account_manager/src/upgrade_legacy_keypairs.rs +++ b/account_manager/src/upgrade_legacy_keypairs.rs @@ -112,7 +112,7 @@ fn upgrade_keypair>( let validator_dir = validator_dir.as_ref(); let secrets_dir = secrets_dir.as_ref(); - let keypair: Keypair = load_unencrypted_keypair(validator_dir.join(input_filename))?.into(); + let keypair: Keypair = load_unencrypted_keypair(validator_dir.join(input_filename))?; let password = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -136,7 +136,7 @@ fn upgrade_keypair>( .to_json_writer(&mut file) .map_err(|e| format!("Cannot write keystore to {:?}: {:?}", keystore_path, e))?; - let password_path = secrets_dir.join(format!("{}", keypair.pk.as_hex_string())); + let password_path = secrets_dir.join(keypair.pk.as_hex_string()); if password_path.exists() { return Err(format!("{:?} already exists", password_path)); diff --git a/account_manager/src/validator/deposit.rs b/account_manager/src/validator/deposit.rs index b052fd1da06..23f970ed20b 100644 --- a/account_manager/src/validator/deposit.rs +++ b/account_manager/src/validator/deposit.rs @@ -1,6 +1,5 @@ use crate::VALIDATOR_DIR_FLAG; use clap::{App, Arg, ArgMatches}; -use clap_utils; use deposit_contract::DEPOSIT_GAS; use environment::Environment; use futures::compat::Future01CompatExt; diff --git a/account_manager/src/validator/mod.rs b/account_manager/src/validator/mod.rs index ac52c6d7135..25d0846f5c7 100644 --- a/account_manager/src/validator/mod.rs +++ b/account_manager/src/validator/mod.rs @@ -28,11 +28,9 @@ pub fn cli_run(matches: &ArgMatches, env: Environment) -> Result< match matches.subcommand() { (create::CMD, Some(matches)) => create::cli_run::(matches, env, base_wallet_dir), (deposit::CMD, Some(matches)) => deposit::cli_run::(matches, env), - (unknown, _) => { - return Err(format!( - "{} does not have a {} command. See --help", - CMD, unknown - )); - } + (unknown, _) => Err(format!( + "{} does not have a {} command. See --help", + CMD, unknown + )), } } diff --git a/account_manager/src/wallet/create.rs b/account_manager/src/wallet/create.rs index 904f651dd4d..64703f4dc35 100644 --- a/account_manager/src/wallet/create.rs +++ b/account_manager/src/wallet/create.rs @@ -117,24 +117,24 @@ pub fn cli_run(matches: &ArgMatches, base_dir: PathBuf) -> Result<(), String> { } println!("Your wallet's 12-word BIP-39 mnemonic is:"); - println!(""); + println!(); println!("\t{}", mnemonic.phrase()); - println!(""); + println!(); println!("This mnemonic can be used to fully restore your wallet, should "); println!("you lose the JSON file or your password. "); - println!(""); + println!(); println!("It is very important that you DO NOT SHARE this mnemonic as it will "); println!("reveal the private keys of all validators and keys generated with "); println!("this wallet. That would be catastrophic."); - println!(""); + println!(); println!("It is also important to store a backup of this mnemonic so you can "); println!("recover your private keys in the case of data loss. Writing it on "); println!("a piece of paper and storing it in a safe place would be prudent."); - println!(""); + println!(); println!("Your wallet's UUID is:"); - println!(""); + println!(); println!("\t{}", wallet.wallet().uuid()); - println!(""); + println!(); println!("You do not need to backup your UUID or keep it secret."); Ok(()) diff --git a/account_manager/src/wallet/mod.rs b/account_manager/src/wallet/mod.rs index 76148474967..fb1c5869f18 100644 --- a/account_manager/src/wallet/mod.rs +++ b/account_manager/src/wallet/mod.rs @@ -30,11 +30,9 @@ pub fn cli_run(matches: &ArgMatches) -> Result<(), String> { match matches.subcommand() { (create::CMD, Some(matches)) => create::cli_run(matches, base_dir), (list::CMD, Some(_)) => list::cli_run(base_dir), - (unknown, _) => { - return Err(format!( - "{} does not have a {} command. See --help", - CMD, unknown - )); - } + (unknown, _) => Err(format!( + "{} does not have a {} command. See --help", + CMD, unknown + )), } } diff --git a/beacon_node/beacon_chain/src/attestation_verification.rs b/beacon_node/beacon_chain/src/attestation_verification.rs index 49fac92f3a5..a62e9fc6e63 100644 --- a/beacon_node/beacon_chain/src/attestation_verification.rs +++ b/beacon_node/beacon_chain/src/attestation_verification.rs @@ -287,7 +287,7 @@ impl VerifiedAggregatedAttestation { if chain .observed_aggregators .observe_validator(&attestation, aggregator_index as usize) - .map_err(|e| BeaconChainError::from(e))? + .map_err(BeaconChainError::from)? { return Err(Error::PriorAttestationKnown { validator_index: aggregator_index, @@ -370,7 +370,7 @@ impl VerifiedUnaggregatedAttestation { if chain .observed_attesters .validator_has_been_observed(&attestation, validator_index as usize) - .map_err(|e| BeaconChainError::from(e))? + .map_err(BeaconChainError::from)? { return Err(Error::PriorAttestationKnown { validator_index, @@ -390,7 +390,7 @@ impl VerifiedUnaggregatedAttestation { if chain .observed_attesters .observe_validator(&attestation, validator_index as usize) - .map_err(|e| BeaconChainError::from(e))? + .map_err(BeaconChainError::from)? { return Err(Error::PriorAttestationKnown { validator_index, @@ -504,7 +504,7 @@ pub fn verify_attestation_signature( .canonical_head .try_read_for(HEAD_LOCK_TIMEOUT) .ok_or_else(|| BeaconChainError::CanonicalHeadLockTimeout) - .map(|head| head.beacon_state.fork.clone())?; + .map(|head| head.beacon_state.fork)?; let signature_set = indexed_attestation_signature_set_from_pubkeys( |validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed), @@ -559,7 +559,7 @@ pub fn verify_signed_aggregate_signatures( .canonical_head .try_read_for(HEAD_LOCK_TIMEOUT) .ok_or_else(|| BeaconChainError::CanonicalHeadLockTimeout) - .map(|head| head.beacon_state.fork.clone())?; + .map(|head| head.beacon_state.fork)?; let signature_sets = vec![ signed_aggregate_selection_proof_signature_set( @@ -694,7 +694,7 @@ where // The state roots are not useful for the shuffling, so there's no need to // compute them. per_slot_processing(&mut state, Some(Hash256::zero()), &chain.spec) - .map_err(|e| BeaconChainError::from(e))?; + .map_err(BeaconChainError::from)?; } metrics::stop_timer(state_skip_timer); @@ -706,11 +706,11 @@ where state .build_committee_cache(relative_epoch, &chain.spec) - .map_err(|e| BeaconChainError::from(e))?; + .map_err(BeaconChainError::from)?; let committee_cache = state .committee_cache(relative_epoch) - .map_err(|e| BeaconChainError::from(e))?; + .map_err(BeaconChainError::from)?; chain .shuffling_cache diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 452ad822975..d9120159858 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -199,6 +199,8 @@ pub struct BeaconChain { pub genesis_block_root: Hash256, /// The root of the list of genesis validators, used during syncing. pub genesis_validators_root: Hash256, + + #[allow(clippy::type_complexity)] /// A state-machine that is updated with information from the network and chooses a canonical /// head block. pub fork_choice: RwLock< @@ -493,9 +495,9 @@ impl BeaconChain { slot: head.beacon_block.slot(), block_root: head.beacon_block_root, state_root: head.beacon_state_root, - current_justified_checkpoint: head.beacon_state.current_justified_checkpoint.clone(), - finalized_checkpoint: head.beacon_state.finalized_checkpoint.clone(), - fork: head.beacon_state.fork.clone(), + current_justified_checkpoint: head.beacon_state.current_justified_checkpoint, + finalized_checkpoint: head.beacon_state.finalized_checkpoint, + fork: head.beacon_state.fork, genesis_time: head.beacon_state.genesis_time, genesis_validators_root: head.beacon_state.genesis_validators_root, }) @@ -853,8 +855,8 @@ impl BeaconChain { data: AttestationData { slot, index, - beacon_block_root: beacon_block_root, - source: state.current_justified_checkpoint.clone(), + beacon_block_root, + source: state.current_justified_checkpoint, target: Checkpoint { epoch, root: target_root, @@ -986,8 +988,7 @@ impl BeaconChain { .try_read_for(HEAD_LOCK_TIMEOUT) .ok_or_else(|| Error::CanonicalHeadLockTimeout)? .beacon_state - .fork - .clone(); + .fork; self.op_pool .insert_attestation( @@ -1348,7 +1349,7 @@ impl BeaconChain { }; // Verify and import the block. - let result = match import_block(unverified_block) { + match import_block(unverified_block) { // The block was successfully verified and imported. Yay. Ok(block_root) => { trace!( @@ -1362,7 +1363,7 @@ impl BeaconChain { metrics::inc_counter(&metrics::BLOCK_PROCESSING_SUCCESSES); let _ = self.event_handler.register(EventKind::BeaconBlockImported { - block_root: block_root, + block_root, block: Box::new(block), }); @@ -1399,9 +1400,7 @@ impl BeaconChain { Err(other) } - }; - - result + } } /// Accepts a fully-verified block and imports it into the chain without performing any @@ -1642,7 +1641,7 @@ impl BeaconChain { body: BeaconBlockBody { randao_reveal, eth1_data, - graffiti: self.graffiti.clone(), + graffiti: self.graffiti, proposer_slashings: proposer_slashings.into(), attester_slashings: attester_slashings.into(), attestations: self @@ -1718,7 +1717,7 @@ impl BeaconChain { .snapshot_cache .try_read_for(BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT) .and_then(|snapshot_cache| snapshot_cache.get_cloned(beacon_block_root)) - .map::, _>(|snapshot| Ok(snapshot)) + .map::, _>(Ok) .unwrap_or_else(|| { let beacon_block = self .get_block(&beacon_block_root)? @@ -2010,8 +2009,8 @@ impl BeaconChain { let mut finalized_blocks: HashSet = HashSet::new(); let genesis_block_hash = Hash256::zero(); - write!(output, "digraph beacon {{\n").unwrap(); - write!(output, "\t_{:?}[label=\"genesis\"];\n", genesis_block_hash).unwrap(); + writeln!(output, "digraph beacon {{").unwrap(); + writeln!(output, "\t_{:?}[label=\"genesis\"];", genesis_block_hash).unwrap(); // Canonical head needs to be processed first as otherwise finalized blocks aren't detected // properly. @@ -2045,36 +2044,36 @@ impl BeaconChain { } if block_hash == canonical_head_hash { - write!( + writeln!( output, - "\t_{:?}[label=\"{} ({})\" shape=box3d];\n", + "\t_{:?}[label=\"{} ({})\" shape=box3d];", block_hash, block_hash, signed_beacon_block.slot() ) .unwrap(); } else if finalized_blocks.contains(&block_hash) { - write!( + writeln!( output, - "\t_{:?}[label=\"{} ({})\" shape=Msquare];\n", + "\t_{:?}[label=\"{} ({})\" shape=Msquare];", block_hash, block_hash, signed_beacon_block.slot() ) .unwrap(); } else { - write!( + writeln!( output, - "\t_{:?}[label=\"{} ({})\" shape=box];\n", + "\t_{:?}[label=\"{} ({})\" shape=box];", block_hash, block_hash, signed_beacon_block.slot() ) .unwrap(); } - write!( + writeln!( output, - "\t_{:?} -> _{:?};\n", + "\t_{:?} -> _{:?};", block_hash, signed_beacon_block.parent_root() ) @@ -2082,7 +2081,7 @@ impl BeaconChain { } } - write!(output, "}}\n").unwrap(); + writeln!(output, "}}").unwrap(); } // Used for debugging @@ -2135,7 +2134,7 @@ impl From for Error { } impl ChainSegmentResult { - pub fn to_block_error(self) -> Result<(), BlockError> { + pub fn into_block_error(self) -> Result<(), BlockError> { match self { ChainSegmentResult::Failed { error, .. } => Err(error), ChainSegmentResult::Successful { .. } => Ok(()), diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index 4acc7da0125..880e801d772 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -584,8 +584,9 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> { state_root }; - per_slot_processing(&mut state, Some(state_root), &chain.spec)? - .map(|summary| summaries.push(summary)); + if let Some(summary) = per_slot_processing(&mut state, Some(state_root), &chain.spec)? { + summaries.push(summary) + } } expose_participation_metrics(&summaries); diff --git a/beacon_node/beacon_chain/src/builder.rs b/beacon_node/beacon_chain/src/builder.rs index 9ebe1f0bf67..800f5e7cb64 100644 --- a/beacon_node/beacon_chain/src/builder.rs +++ b/beacon_node/beacon_chain/src/builder.rs @@ -93,6 +93,7 @@ where /// /// See the tests for an example of a complete working example. pub struct BeaconChainBuilder { + #[allow(clippy::type_complexity)] store: Option>>, store_migrator: Option, canonical_head: Option>, @@ -461,13 +462,10 @@ where .pubkey_cache_path .ok_or_else(|| "Cannot build without a pubkey cache path".to_string())?; - let validator_pubkey_cache = self - .validator_pubkey_cache - .map(|cache| Ok(cache)) - .unwrap_or_else(|| { - ValidatorPubkeyCache::new(&canonical_head.beacon_state, pubkey_cache_path) - .map_err(|e| format!("Unable to init validator pubkey cache: {:?}", e)) - })?; + let validator_pubkey_cache = self.validator_pubkey_cache.map(Ok).unwrap_or_else(|| { + ValidatorPubkeyCache::new(&canonical_head.beacon_state, pubkey_cache_path) + .map_err(|e| format!("Unable to init validator pubkey cache: {:?}", e)) + })?; let persisted_fork_choice = store .get_item::(&Hash256::from_slice(&FORK_CHOICE_DB_KEY)) diff --git a/beacon_node/beacon_chain/src/eth1_chain.rs b/beacon_node/beacon_chain/src/eth1_chain.rs index b9af5027c42..b2477c3b190 100644 --- a/beacon_node/beacon_chain/src/eth1_chain.rs +++ b/beacon_node/beacon_chain/src/eth1_chain.rs @@ -331,7 +331,7 @@ impl Eth1ChainBackend for CachingEth1Backend { // // Here we choose the eth1_data corresponding to the latest block in our voting window. // If no votes exist, choose `state.eth1_data` as default vote. - let default_vote = votes_to_consider + votes_to_consider .iter() .max_by(|(_, x), (_, y)| x.cmp(y)) .map(|vote| { @@ -355,8 +355,7 @@ impl Eth1ChainBackend for CachingEth1Backend { ); metrics::inc_counter(&metrics::DEFAULT_ETH1_VOTES); vote - }); - default_vote + }) }; debug!( diff --git a/beacon_node/beacon_chain/src/events.rs b/beacon_node/beacon_chain/src/events.rs index 441d63be10a..f673813e6f1 100644 --- a/beacon_node/beacon_chain/src/events.rs +++ b/beacon_node/beacon_chain/src/events.rs @@ -37,7 +37,7 @@ impl ServerSentEvents { let arc = Arc::new(mutex); let this = Self { head_changed_queue: arc.clone(), - log: log, + log, _phantom: PhantomData, }; (this, arc) @@ -52,7 +52,10 @@ impl EventHandler for ServerSentEvents { .. } => { let mut guard = self.head_changed_queue.lock(); - if let Err(_) = guard.try_broadcast(current_head_beacon_block_root.into()) { + if guard + .try_broadcast(current_head_beacon_block_root.into()) + .is_err() + { error!( self.log, "Head change streaming queue full"; @@ -75,14 +78,15 @@ pub struct TeeEventHandler { } impl TeeEventHandler { + #[allow(clippy::type_complexity)] pub fn new( log: Logger, websockets_handler: WebSocketSender, ) -> Result<(Self, Arc>>), String> { let (sse_handler, bus) = ServerSentEvents::new(log); let result = Self { - websockets_handler: websockets_handler, - sse_handler: sse_handler, + websockets_handler, + sse_handler, }; Ok((result, bus)) } diff --git a/beacon_node/beacon_chain/src/migrate.rs b/beacon_node/beacon_chain/src/migrate.rs index 1ad83b63356..59079344c92 100644 --- a/beacon_node/beacon_chain/src/migrate.rs +++ b/beacon_node/beacon_chain/src/migrate.rs @@ -154,7 +154,7 @@ pub trait Migrate, Cold: ItemStore>: let batch: Vec> = abandoned_blocks .into_iter() - .map(|block_hash| StoreOp::DeleteBlock(block_hash)) + .map(StoreOp::DeleteBlock) .chain( abandoned_states .into_iter() @@ -296,6 +296,7 @@ impl, Cold: ItemStore> BackgroundMigrator max_finality_distance } + #[allow(clippy::type_complexity)] /// Spawn a new child thread to run the migration process. /// /// Return a channel handle for sending new finalized states to the thread. diff --git a/beacon_node/beacon_chain/src/observed_attesters.rs b/beacon_node/beacon_chain/src/observed_attesters.rs index 8cc3f50705d..c0eac9b4d8f 100644 --- a/beacon_node/beacon_chain/src/observed_attesters.rs +++ b/beacon_node/beacon_chain/src/observed_attesters.rs @@ -88,9 +88,9 @@ impl Item for EpochBitfield { .unwrap_or_else(|| { self.bitfield .resize(validator_index.saturating_add(1), false); - self.bitfield - .get_mut(validator_index) - .map(|mut bit| *bit = true); + if let Some(mut bit) = self.bitfield.get_mut(validator_index) { + *bit = true; + } false }) } diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index aaf2d6e96d2..744712eb4bf 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -393,6 +393,7 @@ where (block_root.into(), new_state) } + #[allow(clippy::type_complexity)] /// `add_block()` repeated `num_blocks` times. pub fn add_blocks( &self, @@ -422,6 +423,7 @@ where (blocks, states, slot, head_hash, state) } + #[allow(clippy::type_complexity)] /// A wrapper on `add_blocks()` to avoid passing enums explicitly. pub fn add_canonical_chain_blocks( &self, @@ -446,6 +448,7 @@ where ) } + #[allow(clippy::type_complexity)] /// A wrapper on `add_blocks()` to avoid passing enums explicitly. pub fn add_stray_blocks( &self, diff --git a/beacon_node/beacon_chain/src/validator_pubkey_cache.rs b/beacon_node/beacon_chain/src/validator_pubkey_cache.rs index 111eb0e1568..4d588d023cc 100644 --- a/beacon_node/beacon_chain/src/validator_pubkey_cache.rs +++ b/beacon_node/beacon_chain/src/validator_pubkey_cache.rs @@ -138,8 +138,8 @@ struct ValidatorPubkeyCacheFile(File); #[derive(Debug)] enum Error { - IoError(io::Error), - SszError(DecodeError), + Io(io::Error), + Ssz(DecodeError), /// The file read from disk does not have a contiguous list of validator public keys. The file /// has become corrupted. InconsistentIndex { @@ -162,7 +162,7 @@ impl ValidatorPubkeyCacheFile { .write(true) .open(path) .map(Self) - .map_err(Error::IoError) + .map_err(Error::Io) } /// Opens an existing file for reading and writing. @@ -174,7 +174,7 @@ impl ValidatorPubkeyCacheFile { .append(true) .open(path) .map(Self) - .map_err(Error::IoError) + .map_err(Error::Io) } /// Append a public key to file. @@ -188,10 +188,9 @@ impl ValidatorPubkeyCacheFile { /// Creates a `ValidatorPubkeyCache` by reading and parsing the underlying file. pub fn into_cache(mut self) -> Result { let mut bytes = vec![]; - self.0.read_to_end(&mut bytes).map_err(Error::IoError)?; + self.0.read_to_end(&mut bytes).map_err(Error::Io)?; - let list: Vec<(usize, PublicKeyBytes)> = - Vec::from_ssz_bytes(&bytes).map_err(Error::SszError)?; + let list: Vec<(usize, PublicKeyBytes)> = Vec::from_ssz_bytes(&bytes).map_err(Error::Ssz)?; let mut last = None; let mut pubkeys = Vec::with_capacity(list.len()); @@ -201,7 +200,7 @@ impl ValidatorPubkeyCacheFile { let expected = last.map(|n| n + 1); if expected.map_or(true, |expected| index == expected) { last = Some(index); - pubkeys.push((&pubkey).try_into().map_err(Error::SszError)?); + pubkeys.push((&pubkey).try_into().map_err(Error::Ssz)?); indices.insert(pubkey, index); } else { return Err(Error::InconsistentIndex { @@ -225,7 +224,7 @@ fn append_to_file(file: &mut File, index: usize, pubkey: &PublicKeyBytes) -> Res index.ssz_append(&mut line); pubkey.ssz_append(&mut line); - file.write_all(&mut line).map_err(Error::IoError) + file.write_all(&line).map_err(Error::Io) } #[cfg(test)] diff --git a/beacon_node/beacon_chain/tests/block_verification.rs b/beacon_node/beacon_chain/tests/block_verification.rs index da524a56731..101443d93ff 100644 --- a/beacon_node/beacon_chain/tests/block_verification.rs +++ b/beacon_node/beacon_chain/tests/block_verification.rs @@ -126,13 +126,13 @@ fn chain_segment_full_segment() { harness .chain .process_chain_segment(vec![]) - .to_block_error() + .into_block_error() .expect("should import empty chain segment"); harness .chain .process_chain_segment(blocks.clone()) - .to_block_error() + .into_block_error() .expect("should import chain segment"); harness.chain.fork_choice().expect("should run fork choice"); @@ -163,7 +163,7 @@ fn chain_segment_varying_chunk_size() { harness .chain .process_chain_segment(chunk.to_vec()) - .to_block_error() + .into_block_error() .expect(&format!( "should import chain segment of len {}", chunk_size @@ -203,7 +203,7 @@ fn chain_segment_non_linear_parent_roots() { harness .chain .process_chain_segment(blocks.clone()) - .to_block_error(), + .into_block_error(), Err(BlockError::NonLinearParentRoots) ), "should not import chain with missing parent" @@ -220,7 +220,7 @@ fn chain_segment_non_linear_parent_roots() { harness .chain .process_chain_segment(blocks.clone()) - .to_block_error(), + .into_block_error(), Err(BlockError::NonLinearParentRoots) ), "should not import chain with a broken parent root link" @@ -247,7 +247,7 @@ fn chain_segment_non_linear_slots() { harness .chain .process_chain_segment(blocks.clone()) - .to_block_error(), + .into_block_error(), Err(BlockError::NonLinearSlots) ), "should not import chain with a parent that has a lower slot than its child" @@ -265,7 +265,7 @@ fn chain_segment_non_linear_slots() { harness .chain .process_chain_segment(blocks.clone()) - .to_block_error(), + .into_block_error(), Err(BlockError::NonLinearSlots) ), "should not import chain with a parent that has an equal slot to its child" @@ -292,7 +292,7 @@ fn invalid_signatures() { harness .chain .process_chain_segment(ancestor_blocks) - .to_block_error() + .into_block_error() .expect("should import all blocks prior to the one being tested"); // For the given snapshots, test the following: @@ -312,7 +312,10 @@ fn invalid_signatures() { // Ensure the block will be rejected if imported in a chain segment. assert!( matches!( - harness.chain.process_chain_segment(blocks).to_block_error(), + harness + .chain + .process_chain_segment(blocks) + .into_block_error(), Err(BlockError::InvalidSignature) ), "should not import chain segment with an invalid {} signature", @@ -351,7 +354,10 @@ fn invalid_signatures() { // Ensure the block will be rejected if imported in a chain segment. assert!( matches!( - harness.chain.process_chain_segment(blocks).to_block_error(), + harness + .chain + .process_chain_segment(blocks) + .into_block_error(), Err(BlockError::InvalidSignature) ), "should not import chain segment with an invalid gossip signature", @@ -489,7 +495,10 @@ fn invalid_signatures() { .collect(); assert!( !matches!( - harness.chain.process_chain_segment(blocks).to_block_error(), + harness + .chain + .process_chain_segment(blocks) + .into_block_error(), Err(BlockError::InvalidSignature) ), "should not throw an invalid signature error for a bad deposit signature" diff --git a/beacon_node/client/src/builder.rs b/beacon_node/client/src/builder.rs index 27047e78d87..12645b8a5ea 100644 --- a/beacon_node/client/src/builder.rs +++ b/beacon_node/client/src/builder.rs @@ -50,6 +50,7 @@ pub const ETH1_GENESIS_UPDATE_INTERVAL_MILLIS: u64 = 7_000; /// `self.memory_store(..)` has been called. pub struct ClientBuilder { slot_clock: Option, + #[allow(clippy::type_complexity)] store: Option>>, store_migrator: Option, runtime_context: Option>, @@ -134,7 +135,7 @@ where let eth_spec_instance = self.eth_spec_instance.clone(); let data_dir = config.data_dir.clone(); let disabled_forks = config.disabled_forks.clone(); - let graffiti = config.graffiti.clone(); + let graffiti = config.graffiti; let store = store.ok_or_else(|| "beacon_chain_start_method requires a store".to_string())?; @@ -452,6 +453,7 @@ where THotStore: ItemStore + 'static, TColdStore: ItemStore + 'static, { + #[allow(clippy::type_complexity)] /// Specifies that the `BeaconChain` should publish events using the WebSocket server. pub fn tee_event_handler( mut self, diff --git a/beacon_node/client/src/error.rs b/beacon_node/client/src/error.rs index 680ad8277d2..20cf6f9877b 100644 --- a/beacon_node/client/src/error.rs +++ b/beacon_node/client/src/error.rs @@ -1,5 +1,3 @@ -use network; - use error_chain::error_chain; error_chain! { diff --git a/beacon_node/client/src/notifier.rs b/beacon_node/client/src/notifier.rs index 644e13c94fc..208bd389a53 100644 --- a/beacon_node/client/src/notifier.rs +++ b/beacon_node/client/src/notifier.rs @@ -7,7 +7,6 @@ use slog::{debug, error, info, warn}; use slot_clock::SlotClock; use std::sync::Arc; use std::time::{Duration, Instant}; -use time; use tokio::time::delay_for; use types::{EthSpec, Slot}; @@ -64,7 +63,7 @@ pub fn spawn_notifier( } // Perform post-genesis logging. - while let Some(_) = interval.next().await { + while interval.next().await.is_some() { let connected_peer_count = network.connected_peers(); let sync_state = network.sync_state(); @@ -131,34 +130,32 @@ pub fn spawn_notifier( "speed" => sync_speed_pretty(speedo.slots_per_second()), "est_time" => estimated_time_pretty(speedo.estimated_time_till_slot(current_slot)), ); - } else { - if sync_state.is_synced() { - let block_info = if current_slot > head_slot { - format!(" … empty") - } else { - format!("{}", head_root) - }; - info!( - log, - "Synced"; - "peers" => peer_count_pretty(connected_peer_count), - "finalized_root" => format!("{}", finalized_root), - "finalized_epoch" => finalized_epoch, - "epoch" => current_epoch, - "block" => block_info, - "slot" => current_slot, - ); + } else if sync_state.is_synced() { + let block_info = if current_slot > head_slot { + " … empty".to_string() } else { - info!( - log, - "Searching for peers"; - "peers" => peer_count_pretty(connected_peer_count), - "finalized_root" => format!("{}", finalized_root), - "finalized_epoch" => finalized_epoch, - "head_slot" => head_slot, - "current_slot" => current_slot, - ); - } + head_root.to_string() + }; + info!( + log, + "Synced"; + "peers" => peer_count_pretty(connected_peer_count), + "finalized_root" => format!("{}", finalized_root), + "finalized_epoch" => finalized_epoch, + "epoch" => current_epoch, + "block" => block_info, + "slot" => current_slot, + ); + } else { + info!( + log, + "Searching for peers"; + "peers" => peer_count_pretty(connected_peer_count), + "finalized_root" => format!("{}", finalized_root), + "finalized_epoch" => finalized_epoch, + "head_slot" => head_slot, + "current_slot" => current_slot, + ); } } Ok::<(), ()>(()) diff --git a/beacon_node/eth1/src/service.rs b/beacon_node/eth1/src/service.rs index b3197e8e45b..221d0a49df6 100644 --- a/beacon_node/eth1/src/service.rs +++ b/beacon_node/eth1/src/service.rs @@ -434,7 +434,7 @@ impl Service { for (block_range, log_chunk) in logs.iter() { let mut cache = self.deposits().write(); log_chunk - .into_iter() + .iter() .map(|raw_log| { DepositLog::from_log(&raw_log, self.inner.spec()).map_err(|error| { Error::FailedToParseDepositLog { diff --git a/beacon_node/eth2_libp2p/src/behaviour/handler/delegate.rs b/beacon_node/eth2_libp2p/src/behaviour/handler/delegate.rs index 272a4ae756b..03a2a08a733 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/handler/delegate.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/handler/delegate.rs @@ -188,10 +188,10 @@ impl ProtocolsHandler for DelegatingHandler { // Identify ( EitherOutput::Second(EitherOutput::Second(protocol)), - EitherOutput::Second(EitherOutput::Second(info)), + EitherOutput::Second(EitherOutput::Second(())), ) => self .identify_handler - .inject_fully_negotiated_outbound(protocol, info), + .inject_fully_negotiated_outbound(protocol, ()), // Reaching here means we got a protocol and info for different behaviours _ => unreachable!("output and protocol don't match"), } @@ -201,7 +201,7 @@ impl ProtocolsHandler for DelegatingHandler { match event { DelegateIn::Gossipsub(ev) => self.gossip_handler.inject_event(ev), DelegateIn::RPC(ev) => self.rpc_handler.inject_event(ev), - DelegateIn::Identify(ev) => self.identify_handler.inject_event(ev), + DelegateIn::Identify(()) => self.identify_handler.inject_event(()), } } @@ -263,23 +263,23 @@ impl ProtocolsHandler for DelegatingHandler { } }, // Identify - EitherOutput::Second(EitherOutput::Second(info)) => match error { + EitherOutput::Second(EitherOutput::Second(())) => match error { ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Select(err)) => { self.identify_handler.inject_dial_upgrade_error( - info, + (), ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Select(err)), ) } ProtocolsHandlerUpgrErr::Timer => self .identify_handler - .inject_dial_upgrade_error(info, ProtocolsHandlerUpgrErr::Timer), + .inject_dial_upgrade_error((), ProtocolsHandlerUpgrErr::Timer), ProtocolsHandlerUpgrErr::Timeout => self .identify_handler - .inject_dial_upgrade_error(info, ProtocolsHandlerUpgrErr::Timeout), + .inject_dial_upgrade_error((), ProtocolsHandlerUpgrErr::Timeout), ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::B( EitherError::B(err), ))) => self.identify_handler.inject_dial_upgrade_error( - info, + (), ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(err)), ), ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(_)) => { @@ -296,6 +296,7 @@ impl ProtocolsHandler for DelegatingHandler { .max(self.identify_handler.connection_keep_alive()) } + #[allow(clippy::type_complexity)] fn poll( &mut self, cx: &mut Context, @@ -350,10 +351,10 @@ impl ProtocolsHandler for DelegatingHandler { Poll::Ready(ProtocolsHandlerEvent::Close(event)) => { return Poll::Ready(ProtocolsHandlerEvent::Close(DelegateError::Identify(event))); } - Poll::Ready(ProtocolsHandlerEvent::OutboundSubstreamRequest { protocol, info }) => { + Poll::Ready(ProtocolsHandlerEvent::OutboundSubstreamRequest { protocol, info: () }) => { return Poll::Ready(ProtocolsHandlerEvent::OutboundSubstreamRequest { protocol: protocol.map_upgrade(|u| EitherUpgrade::B(EitherUpgrade::B(u))), - info: EitherOutput::Second(EitherOutput::Second(info)), + info: EitherOutput::Second(EitherOutput::Second(())), }); } Poll::Pending => (), diff --git a/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs b/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs index 70b628b6fe2..f74040d91a5 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs @@ -100,6 +100,7 @@ impl ProtocolsHandler for BehaviourHandler { KeepAlive::Yes } + #[allow(clippy::type_complexity)] fn poll( &mut self, cx: &mut Context, diff --git a/beacon_node/eth2_libp2p/src/behaviour/mod.rs b/beacon_node/eth2_libp2p/src/behaviour/mod.rs index e9bc77aa4d7..857a9ededf4 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/mod.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/mod.rs @@ -397,7 +397,7 @@ impl Behaviour { if self.seen_gossip_messages.put(id.clone(), ()).is_none() { match PubsubMessage::decode(&gs_msg.topics, &gs_msg.data) { Err(e) => { - debug!(self.log, "Could not decode gossipsub message"; "error" => format!("{}", e)) + debug!(self.log, "Could not decode gossipsub message"; "error" => e) } Ok(msg) => { // if this message isn't a duplicate, notify the network @@ -412,7 +412,7 @@ impl Behaviour { } else { match PubsubMessage::::decode(&gs_msg.topics, &gs_msg.data) { Err(e) => { - debug!(self.log, "Could not decode gossipsub message"; "error" => format!("{}", e)) + debug!(self.log, "Could not decode gossipsub message"; "error" => e) } Ok(msg) => { debug!(self.log, "A duplicate gossipsub message was received"; "message_source" => format!("{}", gs_msg.source), "propagated_peer" => format!("{}",propagation_source), "message" => format!("{}", msg)); diff --git a/beacon_node/eth2_libp2p/src/discovery/enr.rs b/beacon_node/eth2_libp2p/src/discovery/enr.rs index 798fbee4859..e60bb38babd 100644 --- a/beacon_node/eth2_libp2p/src/discovery/enr.rs +++ b/beacon_node/eth2_libp2p/src/discovery/enr.rs @@ -17,9 +17,9 @@ use std::str::FromStr; use types::{EnrForkId, EthSpec}; /// The ENR field specifying the fork id. -pub const ETH2_ENR_KEY: &'static str = "eth2"; +pub const ETH2_ENR_KEY: &str = "eth2"; /// The ENR field specifying the subnet bitfield. -pub const BITFIELD_ENR_KEY: &'static str = "attnets"; +pub const BITFIELD_ENR_KEY: &str = "attnets"; /// Extension trait for ENR's within Eth2. pub trait Eth2Enr { diff --git a/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs b/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs index 3c6f5c78131..c0df6b16f47 100644 --- a/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs +++ b/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs @@ -197,7 +197,7 @@ pub fn peer_id_to_node_id(peer_id: &PeerId) -> Result { let uncompressed_key_bytes = pk.encode(); @@ -205,9 +205,9 @@ pub fn peer_id_to_node_id(peer_id: &PeerId) -> Result return Err("Unsupported public key".into()), + _ => Err("Unsupported public key".into()), } } diff --git a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs index b04fd7338a6..a57fa90b20f 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs @@ -194,10 +194,8 @@ impl PeerManager { // Update the PeerDB state. if let Some(peer_id) = ban_peer.take() { self.network_globals.peers.write().ban(&peer_id); - } else { - if let Some(peer_id) = unban_peer.take() { - self.network_globals.peers.write().unban(&peer_id); - } + } else if let Some(peer_id) = unban_peer.take() { + self.network_globals.peers.write().unban(&peer_id); } } diff --git a/beacon_node/eth2_libp2p/src/peer_manager/score.rs b/beacon_node/eth2_libp2p/src/peer_manager/score.rs index 2aa53076e4c..719b6e990cd 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/score.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/score.rs @@ -9,7 +9,7 @@ use serde::Serialize; use std::time::Instant; lazy_static! { - static ref HALFLIFE_DECAY: f64 = -2.0f64.ln() / SCORE_HALFLIFE; + static ref HALFLIFE_DECAY: f64 = -(2.0f64.ln()) / SCORE_HALFLIFE; } /// The default score for new peers. diff --git a/beacon_node/eth2_libp2p/src/rpc/codec/ssz_snappy.rs b/beacon_node/eth2_libp2p/src/rpc/codec/ssz_snappy.rs index 5e6163cadbc..d17ac6aa57b 100644 --- a/beacon_node/eth2_libp2p/src/rpc/codec/ssz_snappy.rs +++ b/beacon_node/eth2_libp2p/src/rpc/codec/ssz_snappy.rs @@ -196,10 +196,8 @@ impl Decoder for SSZSnappyInboundCodec { Err(e) => match e.kind() { // Haven't received enough bytes to decode yet // TODO: check if this is the only Error variant where we return `Ok(None)` - ErrorKind::UnexpectedEof => { - return Ok(None); - } - _ => return Err(e).map_err(RPCError::from), + ErrorKind::UnexpectedEof => Ok(None), + _ => Err(e).map_err(RPCError::from), }, } } @@ -368,10 +366,8 @@ impl Decoder for SSZSnappyOutboundCodec { Err(e) => match e.kind() { // Haven't received enough bytes to decode yet // TODO: check if this is the only Error variant where we return `Ok(None)` - ErrorKind::UnexpectedEof => { - return Ok(None); - } - _ => return Err(e).map_err(RPCError::from), + ErrorKind::UnexpectedEof => Ok(None), + _ => Err(e).map_err(RPCError::from), }, } } @@ -412,10 +408,8 @@ impl OutboundCodec> for SSZSnappyOutboundCodec Err(e) => match e.kind() { // Haven't received enough bytes to decode yet // TODO: check if this is the only Error variant where we return `Ok(None)` - ErrorKind::UnexpectedEof => { - return Ok(None); - } - _ => return Err(e).map_err(RPCError::from), + ErrorKind::UnexpectedEof => Ok(None), + _ => Err(e).map_err(RPCError::from), }, } } diff --git a/beacon_node/eth2_libp2p/src/rpc/handler.rs b/beacon_node/eth2_libp2p/src/rpc/handler.rs index 02e2cc4e526..89f0bda7fcb 100644 --- a/beacon_node/eth2_libp2p/src/rpc/handler.rs +++ b/beacon_node/eth2_libp2p/src/rpc/handler.rs @@ -808,7 +808,7 @@ where //trace!(self.log, "RPC Response - stream closed by remote"); // drop the stream let delay_key = &entry.get().delay_key; - let request_id = *&entry.get().req_id; + let request_id = entry.get().req_id; self.outbound_substreams_delay.remove(delay_key); entry.remove_entry(); self.update_keep_alive(); diff --git a/beacon_node/eth2_libp2p/src/rpc/methods.rs b/beacon_node/eth2_libp2p/src/rpc/methods.rs index c3cb358f916..6ff4d3a99b5 100644 --- a/beacon_node/eth2_libp2p/src/rpc/methods.rs +++ b/beacon_node/eth2_libp2p/src/rpc/methods.rs @@ -182,7 +182,7 @@ impl ssz::Decode for GoodbyeReason { } fn from_ssz_bytes(bytes: &[u8]) -> Result { - u64::from_ssz_bytes(bytes).and_then(|n| Ok(n.into())) + u64::from_ssz_bytes(bytes).map(|n| n.into()) } } diff --git a/beacon_node/network/src/attestation_service/mod.rs b/beacon_node/network/src/attestation_service/mod.rs index b96d4726962..5673f73fd58 100644 --- a/beacon_node/network/src/attestation_service/mod.rs +++ b/beacon_node/network/src/attestation_service/mod.rs @@ -2,22 +2,25 @@ //! given time. It schedules subscriptions to shard subnets, requests peer discoveries and //! determines whether attestations should be aggregated and/or passed to the beacon node. -use crate::metrics; -use beacon_chain::{BeaconChain, BeaconChainTypes}; -use eth2_libp2p::{types::GossipKind, NetworkGlobals}; -use futures::prelude::*; -use hashset_delay::HashSetDelay; -use rand::seq::SliceRandom; -use rest_types::ValidatorSubscription; -use slog::{crit, debug, error, o, trace, warn}; -use slot_clock::SlotClock; use std::collections::VecDeque; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; use std::time::{Duration, Instant}; + +use futures::prelude::*; +use rand::seq::SliceRandom; +use slog::{crit, debug, error, o, trace, warn}; + +use beacon_chain::{BeaconChain, BeaconChainTypes}; +use eth2_libp2p::{types::GossipKind, NetworkGlobals}; +use hashset_delay::HashSetDelay; +use rest_types::ValidatorSubscription; +use slot_clock::SlotClock; use types::{Attestation, EthSpec, Slot, SubnetId}; +use crate::metrics; + mod tests; /// The minimum number of slots ahead that we attempt to discover peers for a subscription. If the @@ -276,7 +279,7 @@ impl AttestationService { attestation: &Attestation, ) -> bool { let exact_subnet = ExactSubnet { - subnet_id: subnet.clone(), + subnet_id: subnet, slot: attestation.data.slot, }; self.aggregate_validators_on_subnet.contains(&exact_subnet) @@ -360,35 +363,33 @@ impl AttestationService { let mut is_duplicate = false; self.events.iter_mut().for_each(|event| { - match event { - AttServiceMessage::DiscoverPeers { - subnet_id: other_subnet_id, - min_ttl: other_min_ttl, - } => { - if subnet_id == *other_subnet_id { - let other_min_ttl_clone = other_min_ttl.clone(); - match (min_ttl, other_min_ttl_clone) { - (Some(min_ttl_instant), Some(other_min_ttl_instant)) => - // only update the min_ttl if it is greater than the existing min_ttl and a DURATION_DIFFERENCE padding + if let AttServiceMessage::DiscoverPeers { + subnet_id: other_subnet_id, + min_ttl: other_min_ttl, + } = event + { + if subnet_id == *other_subnet_id { + let other_min_ttl_clone = *other_min_ttl; + match (min_ttl, other_min_ttl_clone) { + (Some(min_ttl_instant), Some(other_min_ttl_instant)) => + // only update the min_ttl if it is greater than the existing min_ttl and a DURATION_DIFFERENCE padding + { + if min_ttl_instant.saturating_duration_since(other_min_ttl_instant) + > DURATION_DIFFERENCE { - if min_ttl_instant.saturating_duration_since(other_min_ttl_instant) - > DURATION_DIFFERENCE - { - *other_min_ttl = min_ttl; - } + *other_min_ttl = min_ttl; } - (None, Some(_)) => {} // Keep the current one as it has an actual min_ttl - (Some(min_ttl), None) => { - // Update the request to include a min_ttl. - *other_min_ttl = Some(min_ttl); - } - (None, None) => {} // Duplicate message, do nothing. } - is_duplicate = true; - return; + (None, Some(_)) => {} // Keep the current one as it has an actual min_ttl + (Some(min_ttl), None) => { + // Update the request to include a min_ttl. + *other_min_ttl = Some(min_ttl); + } + (None, None) => {} // Duplicate message, do nothing. } + is_duplicate = true; + return; } - _ => {} }; }); if !is_duplicate { @@ -542,8 +543,7 @@ impl AttestationService { .gossipsub_subscriptions .read() .iter() - .find(|topic| topic.kind() == topic_kind) - .is_some(); + .any(|topic| topic.kind() == topic_kind); if !already_subscribed { // send a discovery request and a subscription @@ -735,7 +735,7 @@ impl Stream for AttestationService { match self.discover_peers.poll_next_unpin(cx) { Poll::Ready(Some(Ok(exact_subnet))) => self.handle_discover_peers(exact_subnet), Poll::Ready(Some(Err(e))) => { - error!(self.log, "Failed to check for peer discovery requests"; "error"=> format ! ("{}", e)); + error!(self.log, "Failed to check for peer discovery requests"; "error"=> e); } Poll::Ready(None) | Poll::Pending => {} } @@ -744,7 +744,7 @@ impl Stream for AttestationService { match self.subscriptions.poll_next_unpin(cx) { Poll::Ready(Some(Ok(exact_subnet))) => self.handle_subscriptions(exact_subnet), Poll::Ready(Some(Err(e))) => { - error!(self.log, "Failed to check for subnet subscription times"; "error"=> format!("{}", e)); + error!(self.log, "Failed to check for subnet subscription times"; "error"=> e); } Poll::Ready(None) | Poll::Pending => {} } @@ -753,7 +753,7 @@ impl Stream for AttestationService { match self.unsubscriptions.poll_next_unpin(cx) { Poll::Ready(Some(Ok(exact_subnet))) => self.handle_unsubscriptions(exact_subnet), Poll::Ready(Some(Err(e))) => { - error!(self.log, "Failed to check for subnet unsubscription times"; "error"=> format!("{}", e)); + error!(self.log, "Failed to check for subnet unsubscription times"; "error"=> e); } Poll::Ready(None) | Poll::Pending => {} } @@ -762,7 +762,7 @@ impl Stream for AttestationService { match self.random_subnets.poll_next_unpin(cx) { Poll::Ready(Some(Ok(subnet))) => self.handle_random_subnet_expiry(subnet), Poll::Ready(Some(Err(e))) => { - error!(self.log, "Failed to check for random subnet cycles"; "error"=> format!("{}", e)); + error!(self.log, "Failed to check for random subnet cycles"; "error"=> e); } Poll::Ready(None) | Poll::Pending => {} } @@ -773,13 +773,13 @@ impl Stream for AttestationService { let _ = self.handle_known_validator_expiry(); } Poll::Ready(Some(Err(e))) => { - error!(self.log, "Failed to check for random subnet cycles"; "error"=> format!("{}", e)); + error!(self.log, "Failed to check for random subnet cycles"; "error"=> e); } Poll::Ready(None) | Poll::Pending => {} } // poll to remove entries on expiration, no need to act on expiration events if let Poll::Ready(Some(Err(e))) = self.aggregate_validators_on_subnet.poll_next_unpin(cx) { - error!(self.log, "Failed to check for aggregate validator on subnet expirations"; "error"=> format!("{}", e)); + error!(self.log, "Failed to check for aggregate validator on subnet expirations"; "error"=> e); } // process any generated events diff --git a/beacon_node/network/src/persisted_dht.rs b/beacon_node/network/src/persisted_dht.rs index 1f68f7ac115..2149324422b 100644 --- a/beacon_node/network/src/persisted_dht.rs +++ b/beacon_node/network/src/persisted_dht.rs @@ -1,5 +1,4 @@ use eth2_libp2p::Enr; -use rlp; use std::sync::Arc; use store::{DBColumn, Error as StoreError, HotColdDB, ItemStore, StoreItem}; use types::{EthSpec, Hash256}; diff --git a/beacon_node/network/src/service.rs b/beacon_node/network/src/service.rs index fa9e165061d..d026704afb9 100644 --- a/beacon_node/network/src/service.rs +++ b/beacon_node/network/src/service.rs @@ -92,6 +92,7 @@ pub struct NetworkService { } impl NetworkService { + #[allow(clippy::type_complexity)] pub fn start( beacon_chain: Arc>, config: &NetworkConfig, diff --git a/beacon_node/network/src/sync/manager.rs b/beacon_node/network/src/sync/manager.rs index b53b2f61210..2952b6993e8 100644 --- a/beacon_node/network/src/sync/manager.rs +++ b/beacon_node/network/src/sync/manager.rs @@ -315,7 +315,7 @@ impl SyncManager { if let Some(block_request) = self.single_block_lookups.get_mut(&request_id) { // update the state of the lookup indicating a block was received from the peer block_request.block_returned = true; - single_block_hash = Some(block_request.hash.clone()); + single_block_hash = Some(block_request.hash); } if let Some(block_hash) = single_block_hash { self.single_block_lookup_response(peer_id, block, block_hash); @@ -498,8 +498,7 @@ impl SyncManager { if self .single_block_lookups .values() - .find(|single_block_request| single_block_request.hash == block_hash) - .is_some() + .any(|single_block_request| single_block_request.hash == block_hash) { return; } @@ -598,6 +597,7 @@ impl SyncManager { // These functions are called in the main poll function to transition the state of the sync // manager + #[allow(clippy::needless_return)] /// A new block has been received for a parent lookup query, process it. fn process_parent_request(&mut self, mut parent_request: ParentRequests) { // verify the last added block is the parent of the last requested block diff --git a/beacon_node/network/src/sync/peer_sync_info.rs b/beacon_node/network/src/sync/peer_sync_info.rs index 2897b04476f..d564383c552 100644 --- a/beacon_node/network/src/sync/peer_sync_info.rs +++ b/beacon_node/network/src/sync/peer_sync_info.rs @@ -102,12 +102,7 @@ impl PeerSyncInfo { /// than SLOT_IMPORT_TOLERANCE of our current head. /// 2) The peer has a greater finalized slot/epoch than our own. fn is_advanced_peer(&self, remote: &PeerSyncInfo) -> bool { - if remote.head_slot.sub(self.head_slot).as_usize() > SLOT_IMPORT_TOLERANCE + remote.head_slot.sub(self.head_slot).as_usize() > SLOT_IMPORT_TOLERANCE || self.finalized_epoch < remote.finalized_epoch - { - true - } else { - false - } } } diff --git a/beacon_node/network/src/sync/range_sync/chain.rs b/beacon_node/network/src/sync/range_sync/chain.rs index 22183adeb8b..51afe45d28e 100644 --- a/beacon_node/network/src/sync/range_sync/chain.rs +++ b/beacon_node/network/src/sync/range_sync/chain.rs @@ -104,6 +104,7 @@ pub enum ChainSyncingState { } impl SyncingChain { + #[allow(clippy::too_many_arguments)] pub fn new( id: u64, start_epoch: Epoch, @@ -257,7 +258,7 @@ impl SyncingChain { /// Sends a batch to the batch processor. fn process_batch(&mut self, mut batch: Batch) { let downloaded_blocks = std::mem::replace(&mut batch.downloaded_blocks, Vec::new()); - let process_id = ProcessId::RangeBatchId(self.id.clone(), batch.id.clone()); + let process_id = ProcessId::RangeBatchId(self.id, batch.id); self.current_processing_batch = Some(batch); spawn_block_processor( Arc::downgrade(&self.chain.clone()), diff --git a/beacon_node/rest_api/src/beacon.rs b/beacon_node/rest_api/src/beacon.rs index f3ac8bb80c8..73c6bd1ea91 100644 --- a/beacon_node/rest_api/src/beacon.rs +++ b/beacon_node/rest_api/src/beacon.rs @@ -557,9 +557,7 @@ pub async fn attester_slashing( format!("Error while importing attester slashing: {:?}", e) }) } else { - Err(format!( - "Attester slashing only covers already slashed indices" - )) + Err("Attester slashing only covers already slashed indices".to_string()) } }) .map_err(ApiError::BadRequest) diff --git a/beacon_node/rest_api/src/helpers.rs b/beacon_node/rest_api/src/helpers.rs index 872e7c83468..1f82849a8c7 100644 --- a/beacon_node/rest_api/src/helpers.rs +++ b/beacon_node/rest_api/src/helpers.rs @@ -2,7 +2,6 @@ use crate::{ApiError, ApiResult, NetworkChannel}; use beacon_chain::{BeaconChain, BeaconChainTypes, StateSkipConfig}; use bls::PublicKeyBytes; use eth2_libp2p::PubsubMessage; -use hex; use http::header; use hyper::{Body, Request}; use itertools::process_results; diff --git a/beacon_node/rest_api/src/node.rs b/beacon_node/rest_api/src/node.rs index b8b6a4fd2ce..c9b2cad3390 100644 --- a/beacon_node/rest_api/src/node.rs +++ b/beacon_node/rest_api/src/node.rs @@ -5,7 +5,6 @@ use hyper::{Body, Request}; use rest_types::{Health, SyncingResponse, SyncingStatus}; use std::sync::Arc; use types::{EthSpec, Slot}; -use version; /// Read the version string from the current Lighthouse build. pub fn get_version(req: Request) -> ApiResult { @@ -43,7 +42,7 @@ pub fn syncing( } pub fn get_health(req: Request) -> ApiResult { - let health = Health::observe().map_err(|e| ApiError::ServerError(e))?; + let health = Health::observe().map_err(ApiError::ServerError)?; ResponseBuilder::new(&req)?.body_no_ssz(&health) } diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 7bbc81f23bf..12f1cc1ea20 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -4,7 +4,6 @@ use clap_utils::BAD_TESTNET_DIR_MESSAGE; use client::{config::DEFAULT_DATADIR, ClientConfig, ClientGenesis}; use eth2_libp2p::{Enr, Multiaddr}; use eth2_testnet_config::Eth2TestnetConfig; -use hyper; use slog::{crit, info, Logger}; use ssz::Encode; use std::fs; @@ -68,7 +67,7 @@ pub fn get_config( let mut log_dir = client_config.data_dir.clone(); // remove /beacon from the end log_dir.pop(); - info!(log, "Data directory initialised"; "datadir" => format!("{}",log_dir.into_os_string().into_string().expect("Datadir should be a valid os string"))); + info!(log, "Data directory initialised"; "datadir" => log_dir.into_os_string().into_string().expect("Datadir should be a valid os string")); client_config.spec_constants = spec_constants.into(); client_config.testnet_dir = get_testnet_dir(cli_args); @@ -181,7 +180,7 @@ pub fn get_config( resolved_addrs .next() .map(|a| a.ip()) - .ok_or_else(|| format!("Resolved dns addr contains no entries"))? + .ok_or_else(|| "Resolved dns addr contains no entries".to_string())? } else { return Err(format!("Failed to parse enr-address: {}", enr_address)); }; @@ -406,7 +405,7 @@ pub fn get_eth2_testnet_config( } else { Eth2TestnetConfig::hard_coded() .map_err(|e| format!("Error parsing hardcoded testnet: {}", e))? - .ok_or_else(|| format!("{}", BAD_TESTNET_DIR_MESSAGE)) + .ok_or_else(|| BAD_TESTNET_DIR_MESSAGE.to_string()) } } diff --git a/beacon_node/src/lib.rs b/beacon_node/src/lib.rs index fe8cca18af0..96c655daa11 100644 --- a/beacon_node/src/lib.rs +++ b/beacon_node/src/lib.rs @@ -126,7 +126,7 @@ impl ProductionBeaconNode { let builder = builder .build_beacon_chain()? - .network(&mut client_config.network)? + .network(&client_config.network)? .notifier()?; let builder = if client_config.rest_api.enabled { diff --git a/beacon_node/store/src/chunked_vector.rs b/beacon_node/store/src/chunked_vector.rs index 8f5b09debb0..7dda6278e57 100644 --- a/beacon_node/store/src/chunked_vector.rs +++ b/beacon_node/store/src/chunked_vector.rs @@ -381,6 +381,7 @@ pub fn store_updated_vector, E: EthSpec, S: KeyValueStore>( Ok(()) } +#[allow(clippy::too_many_arguments)] fn store_range( _: F, range: I, diff --git a/beacon_node/store/src/forwards_iter.rs b/beacon_node/store/src/forwards_iter.rs index 6ae38aa85f7..fb3a0480f97 100644 --- a/beacon_node/store/src/forwards_iter.rs +++ b/beacon_node/store/src/forwards_iter.rs @@ -78,7 +78,7 @@ impl SimpleForwardsBlockRootsIterator { .collect::>() }, )?; - Ok(Self { values: values }) + Ok(Self { values }) } } diff --git a/beacon_node/store/src/leveldb_store.rs b/beacon_node/store/src/leveldb_store.rs index 4166c7a1ad6..f1c46610c2f 100644 --- a/beacon_node/store/src/leveldb_store.rs +++ b/beacon_node/store/src/leveldb_store.rs @@ -77,7 +77,7 @@ impl KeyValueStore for LevelDB { } fn sync(&self) -> Result<(), Error> { - self.put_bytes_sync("sync", "sync".as_bytes(), "sync".as_bytes()) + self.put_bytes_sync("sync", b"sync", b"sync") } /// Retrieve some bytes in `column` with `key`. @@ -108,7 +108,7 @@ impl KeyValueStore for LevelDB { self.db .get(self.read_options(), BytesKey::from_vec(column_key)) .map_err(Into::into) - .and_then(|val| Ok(val.is_some())) + .map(|val| val.is_some()) } /// Removes `key` from `column`. diff --git a/beacon_node/store/src/partial_beacon_state.rs b/beacon_node/store/src/partial_beacon_state.rs index 82d6222aaaa..e2d67458638 100644 --- a/beacon_node/store/src/partial_beacon_state.rs +++ b/beacon_node/store/src/partial_beacon_state.rs @@ -75,7 +75,7 @@ impl PartialBeaconState { genesis_time: s.genesis_time, genesis_validators_root: s.genesis_validators_root, slot: s.slot, - fork: s.fork.clone(), + fork: s.fork, // History latest_block_header: s.latest_block_header.clone(), @@ -107,9 +107,9 @@ impl PartialBeaconState { // Finality justification_bits: s.justification_bits.clone(), - previous_justified_checkpoint: s.previous_justified_checkpoint.clone(), - current_justified_checkpoint: s.current_justified_checkpoint.clone(), - finalized_checkpoint: s.finalized_checkpoint.clone(), + previous_justified_checkpoint: s.previous_justified_checkpoint, + current_justified_checkpoint: s.current_justified_checkpoint, + finalized_checkpoint: s.finalized_checkpoint, } } diff --git a/boot_node/src/config.rs b/boot_node/src/config.rs index 89bb44d4a55..3d6570973a4 100644 --- a/boot_node/src/config.rs +++ b/boot_node/src/config.rs @@ -21,13 +21,13 @@ impl TryFrom<&ArgMatches<'_>> for BootNodeConfig { .value_of("listen-address") .expect("required parameter") .parse::() - .map_err(|_| format!("Invalid listening address"))?; + .map_err(|_| "Invalid listening address".to_string())?; let listen_port = matches .value_of("port") .expect("required parameter") .parse::() - .map_err(|_| format!("Invalid listening port"))?; + .map_err(|_| "Invalid listening port".to_string())?; let boot_nodes = { if let Some(boot_nodes) = matches.value_of("boot-nodes") { @@ -43,7 +43,7 @@ impl TryFrom<&ArgMatches<'_>> for BootNodeConfig { let enr_port = { if let Some(port) = matches.value_of("boot-node-enr-port") { port.parse::() - .map_err(|_| format!("Invalid ENR port"))? + .map_err(|_| "Invalid ENR port".to_string())? } else { listen_port } @@ -59,7 +59,7 @@ impl TryFrom<&ArgMatches<'_>> for BootNodeConfig { let auto_update = matches.is_present("enable-enr_auto_update"); // the address to listen on - let listen_socket = SocketAddr::new(listen_address.into(), enr_port); + let listen_socket = SocketAddr::new(listen_address, enr_port); // Generate a new key and build a new ENR let local_key = CombinedKey::generate_secp256k1(); @@ -95,7 +95,7 @@ fn resolve_address(address_string: String, port: u16) -> Result resolved_addrs .next() .map(|a| a.ip()) - .ok_or_else(|| format!("Resolved dns addr contains no entries"))) + .ok_or_else(|| "Resolved dns addr contains no entries".to_string())) .map_err(|_| format!("Failed to parse enr-address: {}", address_string))? } } diff --git a/boot_node/src/lib.rs b/boot_node/src/lib.rs index 41d1baa8076..f066b6e41be 100644 --- a/boot_node/src/lib.rs +++ b/boot_node/src/lib.rs @@ -1,6 +1,5 @@ //! Creates a simple DISCV5 server which can be used to bootstrap an Eth2 network. use clap::ArgMatches; -use slog; use slog::{o, Drain, Level, Logger}; use std::convert::TryFrom; diff --git a/common/clap_utils/src/lib.rs b/common/clap_utils/src/lib.rs index 4fa15cfdefa..e562183bb93 100644 --- a/common/clap_utils/src/lib.rs +++ b/common/clap_utils/src/lib.rs @@ -2,7 +2,6 @@ use clap::ArgMatches; use eth2_testnet_config::Eth2TestnetConfig; -use hex; use ssz::Decode; use std::path::PathBuf; use std::str::FromStr; diff --git a/common/deposit_contract/build.rs b/common/deposit_contract/build.rs index 683b601daea..581ec819fc2 100644 --- a/common/deposit_contract/build.rs +++ b/common/deposit_contract/build.rs @@ -3,7 +3,6 @@ //! //! These files are required for some `include_bytes` calls used in this crate. -use hex; use serde_json::Value; use sha2::{Digest, Sha256}; use std::env; @@ -87,7 +86,7 @@ pub fn download_deposit_contract( let abi = contract .get("abi") - .ok_or(format!("Response does not contain key: abi"))? + .ok_or_else(|| "Response does not contain key: abi".to_string())? .to_string(); verify_checksum(abi.as_bytes(), abi_checksum); @@ -98,7 +97,7 @@ pub fn download_deposit_contract( let bytecode = contract .get("bytecode") - .ok_or(format!("Response does not contain key: bytecode"))? + .ok_or_else(|| "Response does not contain key: bytecode".to_string())? .to_string(); verify_checksum(bytecode.as_bytes(), bytecode_checksum); diff --git a/common/eth2_testnet_config/build.rs b/common/eth2_testnet_config/build.rs index cafdfad3111..0440be438e5 100644 --- a/common/eth2_testnet_config/build.rs +++ b/common/eth2_testnet_config/build.rs @@ -1,6 +1,5 @@ //! Downloads a testnet configuration from Github. -use reqwest; use std::env; use std::fs::File; use std::io::Write; diff --git a/common/eth2_wallet_manager/src/wallet_manager.rs b/common/eth2_wallet_manager/src/wallet_manager.rs index 595df9b138e..d1bef67343f 100644 --- a/common/eth2_wallet_manager/src/wallet_manager.rs +++ b/common/eth2_wallet_manager/src/wallet_manager.rs @@ -123,7 +123,7 @@ impl WalletManager { } let wallet = WalletBuilder::from_mnemonic(mnemonic, password, name)?.build()?; - let uuid = wallet.uuid().clone(); + let uuid = *wallet.uuid(); let wallet_dir = self.dir.join(format!("{}", uuid)); diff --git a/common/hashset_delay/src/hashset_delay.rs b/common/hashset_delay/src/hashset_delay.rs index 82287f266db..5eff0f03cdd 100644 --- a/common/hashset_delay/src/hashset_delay.rs +++ b/common/hashset_delay/src/hashset_delay.rs @@ -94,6 +94,11 @@ where self.entries.len() } + /// Checks if the mapping is empty. + pub fn is_empty(&self) -> bool { + self.entries.is_empty() + } + /// Updates the timeout for a given key. Returns true if the key existed, false otherwise. /// /// Panics if the duration is too far in the future. diff --git a/common/remote_beacon_node/src/lib.rs b/common/remote_beacon_node/src/lib.rs index a0b657ec128..4afc403037b 100644 --- a/common/remote_beacon_node/src/lib.rs +++ b/common/remote_beacon_node/src/lib.rs @@ -153,7 +153,7 @@ async fn error_for_status(response: Response) -> Result { let status = response.status(); if status.is_success() { - return Ok(response); + Ok(response) } else { let text_result = response.text().await; match text_result { diff --git a/common/rest_types/src/node.rs b/common/rest_types/src/node.rs index 854cfd3606e..ca98645cc8c 100644 --- a/common/rest_types/src/node.rs +++ b/common/rest_types/src/node.rs @@ -86,18 +86,18 @@ impl Health { psutil::host::loadavg().map_err(|e| format!("Unable to get loadavg: {:?}", e))?; Ok(Self { - pid: process.pid().into(), + pid: process.pid(), pid_num_threads: stat.num_threads, - pid_mem_resident_set_size: process_mem.rss().into(), - pid_mem_virtual_memory_size: process_mem.vms().into(), - sys_virt_mem_total: vm.total().into(), - sys_virt_mem_available: vm.available().into(), - sys_virt_mem_used: vm.used().into(), - sys_virt_mem_free: vm.free().into(), - sys_virt_mem_percent: vm.percent().into(), - sys_loadavg_1: loadavg.one.into(), - sys_loadavg_5: loadavg.five.into(), - sys_loadavg_15: loadavg.fifteen.into(), + pid_mem_resident_set_size: process_mem.rss(), + pid_mem_virtual_memory_size: process_mem.vms(), + sys_virt_mem_total: vm.total(), + sys_virt_mem_available: vm.available(), + sys_virt_mem_used: vm.used(), + sys_virt_mem_free: vm.free(), + sys_virt_mem_percent: vm.percent(), + sys_loadavg_1: loadavg.one, + sys_loadavg_5: loadavg.five, + sys_loadavg_15: loadavg.fifteen, }) } } diff --git a/common/slot_clock/src/manual_slot_clock.rs b/common/slot_clock/src/manual_slot_clock.rs index 236e3e7cd03..04235b6ca52 100644 --- a/common/slot_clock/src/manual_slot_clock.rs +++ b/common/slot_clock/src/manual_slot_clock.rs @@ -18,10 +18,10 @@ pub struct ManualSlotClock { impl Clone for ManualSlotClock { fn clone(&self) -> Self { ManualSlotClock { - genesis_slot: self.genesis_slot.clone(), - genesis_duration: self.genesis_duration.clone(), - current_time: RwLock::new(self.current_time.read().clone()), - slot_duration: self.slot_duration.clone(), + genesis_slot: self.genesis_slot, + genesis_duration: self.genesis_duration, + current_time: RwLock::new(*self.current_time.read()), + slot_duration: self.slot_duration, } } } @@ -98,7 +98,7 @@ impl SlotClock for ManualSlotClock { Self { genesis_slot, - current_time: RwLock::new(genesis_duration.clone()), + current_time: RwLock::new(genesis_duration), genesis_duration, slot_duration, } diff --git a/common/validator_dir/src/validator_dir.rs b/common/validator_dir/src/validator_dir.rs index e24e25cbed1..23cb3a8c1b4 100644 --- a/common/validator_dir/src/validator_dir.rs +++ b/common/validator_dir/src/validator_dir.rs @@ -264,7 +264,7 @@ fn unlock_keypair>( .as_ref() .join(format!("0x{}", keystore.pubkey())); let password: PlainText = read(&password_path) - .map_err(|_| Error::UnableToReadPassword(password_path.into()))? + .map_err(|_| Error::UnableToReadPassword(password_path))? .into(); keystore diff --git a/consensus/fork_choice/src/fork_choice.rs b/consensus/fork_choice/src/fork_choice.rs index 9d91378e91f..22204c445e1 100644 --- a/consensus/fork_choice/src/fork_choice.rs +++ b/consensus/fork_choice/src/fork_choice.rs @@ -1,11 +1,14 @@ -use crate::ForkChoiceStore; +use std::marker::PhantomData; + use proto_array::{Block as ProtoBlock, ProtoArrayForkChoice}; use ssz_derive::{Decode, Encode}; -use std::marker::PhantomData; use types::{ BeaconBlock, BeaconState, BeaconStateError, Epoch, EthSpec, Hash256, IndexedAttestation, Slot, }; +use crate::ForkChoiceStore; +use std::cmp::Ordering; + /// Defined here: /// /// https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/fork-choice.md#configuration @@ -301,21 +304,22 @@ where .get_block(&block_root) .ok_or_else(|| Error::MissingProtoArrayBlock(block_root))?; - if block.slot > ancestor_slot { - Ok(self + match block.slot.cmp(&ancestor_slot) { + Ordering::Greater => Ok(self .proto_array .core_proto_array() .iter_block_roots(&block_root) // Search for a slot that is **less than or equal to** the target slot. We check // for lower slots to account for skip slots. .find(|(_, slot)| *slot <= ancestor_slot) - .map(|(root, _)| root)) - } else if block.slot == ancestor_slot { - Ok(Some(block_root)) - } else { - // Root is older than queried slot, thus a skip slot. Return most recent root prior to - // slot. - Ok(Some(block_root)) + .map(|(root, _)| root)), + Ordering::Less => Ok(Some(block_root)), + Ordering::Equal => + // Root is older than queried slot, thus a skip slot. Return most recent root prior + // to slot. + { + Ok(Some(block_root)) + } } } @@ -331,17 +335,14 @@ where let store = &mut self.fc_store; - let result = self - .proto_array + self.proto_array .find_head( store.justified_checkpoint().epoch, store.justified_checkpoint().root, store.finalized_checkpoint().epoch, store.justified_balances(), ) - .map_err(Into::into); - - result + .map_err(Into::into) } /// Returns `true` if the given `store` should be updated to set @@ -496,17 +497,16 @@ where // information: // // https://github.com/ethereum/eth2.0-specs/pull/1880 - if *self.fc_store.justified_checkpoint() != state.current_justified_checkpoint { - if state.current_justified_checkpoint.epoch + if *self.fc_store.justified_checkpoint() != state.current_justified_checkpoint + && (state.current_justified_checkpoint.epoch > self.fc_store.justified_checkpoint().epoch || self .get_ancestor(self.fc_store.justified_checkpoint().root, finalized_slot)? - != Some(self.fc_store.finalized_checkpoint().root) - { - self.fc_store - .set_justified_checkpoint(state.current_justified_checkpoint) - .map_err(Error::UnableToSetJustifiedCheckpoint)?; - } + != Some(self.fc_store.finalized_checkpoint().root)) + { + self.fc_store + .set_justified_checkpoint(state.current_justified_checkpoint) + .map_err(Error::UnableToSetJustifiedCheckpoint)?; } } @@ -557,13 +557,13 @@ where // // This is not in the specification, however it should be transparent to other nodes. We // return early here to avoid wasting precious resources verifying the rest of it. - if indexed_attestation.attesting_indices.len() == 0 { + if indexed_attestation.attesting_indices.is_empty() { return Err(InvalidAttestation::EmptyAggregationBitfield); } let slot_now = self.fc_store.get_current_slot(); let epoch_now = slot_now.epoch(E::slots_per_epoch()); - let target = indexed_attestation.data.target.clone(); + let target = indexed_attestation.data.target; // Attestation must be from the current or previous epoch. if target.epoch > epoch_now { @@ -822,9 +822,10 @@ pub struct PersistedForkChoice { #[cfg(test)] mod tests { - use super::*; use types::{EthSpec, MainnetEthSpec}; + use super::*; + type E = MainnetEthSpec; #[test] diff --git a/consensus/proto_array/src/bin.rs b/consensus/proto_array/src/bin.rs index 73b9200c39e..ba83714ce77 100644 --- a/consensus/proto_array/src/bin.rs +++ b/consensus/proto_array/src/bin.rs @@ -1,5 +1,4 @@ use proto_array::fork_choice_test_definition::*; -use serde_yaml; use std::fs::File; fn main() { diff --git a/consensus/proto_array/src/proto_array.rs b/consensus/proto_array/src/proto_array.rs index b7f91c3f12e..299c525a727 100644 --- a/consensus/proto_array/src/proto_array.rs +++ b/consensus/proto_array/src/proto_array.rs @@ -358,14 +358,12 @@ impl ProtoArray { } } } + } else if child_leads_to_viable_head { + // There is no current best-child and the child is viable. + change_to_child } else { - if child_leads_to_viable_head { - // There is no current best-child and the child is viable. - change_to_child - } else { - // There is no current best-child but the child is not viable. - no_change - } + // There is no current best-child but the child is not viable. + no_change }; let parent = self diff --git a/consensus/proto_array/src/proto_array_fork_choice.rs b/consensus/proto_array/src/proto_array_fork_choice.rs index 9b44f60cdb7..5a728d9cfb9 100644 --- a/consensus/proto_array/src/proto_array_fork_choice.rs +++ b/consensus/proto_array/src/proto_array_fork_choice.rs @@ -95,7 +95,7 @@ impl ProtoArrayForkChoice { .map_err(|e| format!("Failed to add finalized block to proto_array: {:?}", e))?; Ok(Self { - proto_array: proto_array, + proto_array, votes: ElasticList::default(), balances: vec![], }) @@ -171,6 +171,10 @@ impl ProtoArrayForkChoice { self.proto_array.nodes.len() } + pub fn is_empty(&self) -> bool { + self.proto_array.nodes.is_empty() + } + pub fn contains_block(&self, block_root: &Hash256) -> bool { self.proto_array.indices.contains_key(block_root) } diff --git a/consensus/proto_array/src/ssz_container.rs b/consensus/proto_array/src/ssz_container.rs index 31966d6d6ed..06dc48c5f82 100644 --- a/consensus/proto_array/src/ssz_container.rs +++ b/consensus/proto_array/src/ssz_container.rs @@ -45,7 +45,7 @@ impl From for ProtoArrayForkChoice { }; Self { - proto_array: proto_array, + proto_array, votes: ElasticList(from.votes), balances: from.balances, } diff --git a/consensus/ssz/src/decode.rs b/consensus/ssz/src/decode.rs index ec87935b409..38cd7c5fdcd 100644 --- a/consensus/ssz/src/decode.rs +++ b/consensus/ssz/src/decode.rs @@ -1,5 +1,6 @@ use super::*; use smallvec::{smallvec, SmallVec}; +use std::cmp::Ordering; type SmallVec8 = SmallVec<[T; 8]>; @@ -182,10 +183,12 @@ impl<'a> SszDecoderBuilder<'a> { if let Some(first_offset) = self.offsets.first().map(|o| o.offset) { // Check to ensure the first offset points to the byte immediately following the // fixed-length bytes. - if first_offset < self.items_index { - return Err(DecodeError::OffsetIntoFixedPortion(first_offset)); - } else if first_offset > self.items_index { - return Err(DecodeError::OffsetSkipsVariableBytes(first_offset)); + match first_offset.cmp(&self.items_index) { + Ordering::Less => return Err(DecodeError::OffsetIntoFixedPortion(first_offset)), + Ordering::Greater => { + return Err(DecodeError::OffsetSkipsVariableBytes(first_offset)) + } + Ordering::Equal => (), } // Iterate through each pair of offsets, grabbing the slice between each of the offsets. diff --git a/consensus/ssz_types/src/fixed_vector.rs b/consensus/ssz_types/src/fixed_vector.rs index da2aa661607..35efbf9967a 100644 --- a/consensus/ssz_types/src/fixed_vector.rs +++ b/consensus/ssz_types/src/fixed_vector.rs @@ -261,8 +261,7 @@ where } }) } else { - ssz::decode_list_of_variable_length_items(bytes, Some(fixed_len)) - .and_then(|vec| Ok(vec.into())) + ssz::decode_list_of_variable_length_items(bytes, Some(fixed_len)).map(|vec| vec.into()) } } } diff --git a/consensus/state_processing/src/per_block_processing.rs b/consensus/state_processing/src/per_block_processing.rs index c026e3ba7a4..bcb09878bc4 100644 --- a/consensus/state_processing/src/per_block_processing.rs +++ b/consensus/state_processing/src/per_block_processing.rs @@ -301,7 +301,7 @@ pub fn process_proposer_slashings( // We have to verify in series because an invalid block may contain multiple slashings // for the same validator, and we need to correctly detect and reject that. proposer_slashings - .into_iter() + .iter() .enumerate() .try_for_each(|(i, proposer_slashing)| { verify_proposer_slashing(proposer_slashing, &state, verify_signatures, spec) @@ -508,7 +508,7 @@ pub fn process_exits( ) -> Result<(), BlockProcessingError> { // Verify and apply each exit in series. We iterate in series because higher-index exits may // become invalid due to the application of lower-index ones. - for (i, exit) in voluntary_exits.into_iter().enumerate() { + for (i, exit) in voluntary_exits.iter().enumerate() { verify_exit(&state, exit, verify_signatures, spec).map_err(|e| e.into_with_index(i))?; initiate_validator_exit(state, exit.message.validator_index as usize, spec)?; diff --git a/consensus/state_processing/src/per_block_processing/block_processing_builder.rs b/consensus/state_processing/src/per_block_processing/block_processing_builder.rs index dbdd1fc5eed..fc449649207 100644 --- a/consensus/state_processing/src/per_block_processing/block_processing_builder.rs +++ b/consensus/state_processing/src/per_block_processing/block_processing_builder.rs @@ -129,7 +129,7 @@ impl<'a, T: EthSpec> BlockProcessingBuilder<'a, T> { signature: AggregateSignature::new(), }; - for (i, &validator_index) in committee.committee.into_iter().enumerate() { + for (i, &validator_index) in committee.committee.iter().enumerate() { if should_sign(i, validator_index) { attestation .sign( diff --git a/consensus/state_processing/src/per_block_processing/block_signature_verifier.rs b/consensus/state_processing/src/per_block_processing/block_signature_verifier.rs index b7721b5331a..560695d4ca1 100644 --- a/consensus/state_processing/src/per_block_processing/block_signature_verifier.rs +++ b/consensus/state_processing/src/per_block_processing/block_signature_verifier.rs @@ -83,7 +83,7 @@ where /// add signatures, and the `verify` pub fn new(state: &'a BeaconState, get_pubkey: F, spec: &'a ChainSpec) -> Self { Self { - get_pubkey: get_pubkey, + get_pubkey, state, spec, sets: vec![], @@ -129,7 +129,7 @@ where .sets .into_par_iter() .chunks(num_chunks) - .map(|chunk| verify_signature_sets(chunk)) + .map(verify_signature_sets) .reduce(|| true, |current, this| current && this); if result { diff --git a/consensus/state_processing/src/per_block_processing/signature_sets.rs b/consensus/state_processing/src/per_block_processing/signature_sets.rs index b22fec43b13..370145ec090 100644 --- a/consensus/state_processing/src/per_block_processing/signature_sets.rs +++ b/consensus/state_processing/src/per_block_processing/signature_sets.rs @@ -314,8 +314,8 @@ pub fn deposit_pubkey_signature_message( /// Returns the signature set for some set of deposit signatures, made with /// `deposit_pubkey_signature_message`. -pub fn deposit_signature_set<'a>( - pubkey_signature_message: &'a (PublicKey, Signature, Vec), +pub fn deposit_signature_set( + pubkey_signature_message: &(PublicKey, Signature, Vec), ) -> SignatureSet { let (pubkey, signature, message) = pubkey_signature_message; diff --git a/consensus/state_processing/src/per_block_processing/verify_attestation.rs b/consensus/state_processing/src/per_block_processing/verify_attestation.rs index 09c6e855159..3ab962e2e2b 100644 --- a/consensus/state_processing/src/per_block_processing/verify_attestation.rs +++ b/consensus/state_processing/src/per_block_processing/verify_attestation.rs @@ -93,8 +93,8 @@ fn verify_casper_ffg_vote( verify!( data.source == state.current_justified_checkpoint, Invalid::WrongJustifiedCheckpoint { - state: state.current_justified_checkpoint.clone(), - attestation: data.source.clone(), + state: state.current_justified_checkpoint, + attestation: data.source, is_current: true, } ); @@ -103,8 +103,8 @@ fn verify_casper_ffg_vote( verify!( data.source == state.previous_justified_checkpoint, Invalid::WrongJustifiedCheckpoint { - state: state.previous_justified_checkpoint.clone(), - attestation: data.source.clone(), + state: state.previous_justified_checkpoint, + attestation: data.source, is_current: false, } ); diff --git a/consensus/state_processing/src/per_epoch_processing.rs b/consensus/state_processing/src/per_epoch_processing.rs index a9763088b16..0321bce35a1 100644 --- a/consensus/state_processing/src/per_epoch_processing.rs +++ b/consensus/state_processing/src/per_epoch_processing.rs @@ -91,11 +91,11 @@ pub fn process_justification_and_finalization( let previous_epoch = state.previous_epoch(); let current_epoch = state.current_epoch(); - let old_previous_justified_checkpoint = state.previous_justified_checkpoint.clone(); - let old_current_justified_checkpoint = state.current_justified_checkpoint.clone(); + let old_previous_justified_checkpoint = state.previous_justified_checkpoint; + let old_current_justified_checkpoint = state.current_justified_checkpoint; // Process justifications - state.previous_justified_checkpoint = state.current_justified_checkpoint.clone(); + state.previous_justified_checkpoint = state.current_justified_checkpoint; state.justification_bits.shift_up(1)?; if total_balances diff --git a/consensus/state_processing/src/per_slot_processing.rs b/consensus/state_processing/src/per_slot_processing.rs index 39459839293..02acfc825a6 100644 --- a/consensus/state_processing/src/per_slot_processing.rs +++ b/consensus/state_processing/src/per_slot_processing.rs @@ -21,11 +21,12 @@ pub fn per_slot_processing( ) -> Result, Error> { cache_state(state, state_root)?; - let mut summary = None; - - if state.slot > spec.genesis_slot && (state.slot + 1) % T::slots_per_epoch() == 0 { - summary = Some(per_epoch_processing(state, spec)?); - } + let summary = if state.slot > spec.genesis_slot && (state.slot + 1) % T::slots_per_epoch() == 0 + { + Some(per_epoch_processing(state, spec)?) + } else { + None + }; state.slot += 1; diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 9b06021636a..eca1543d44a 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -1073,7 +1073,7 @@ impl BeaconState { genesis_time: self.genesis_time, genesis_validators_root: self.genesis_validators_root, slot: self.slot, - fork: self.fork.clone(), + fork: self.fork, latest_block_header: self.latest_block_header.clone(), block_roots: self.block_roots.clone(), state_roots: self.state_roots.clone(), @@ -1088,9 +1088,9 @@ impl BeaconState { previous_epoch_attestations: self.previous_epoch_attestations.clone(), current_epoch_attestations: self.current_epoch_attestations.clone(), justification_bits: self.justification_bits.clone(), - previous_justified_checkpoint: self.previous_justified_checkpoint.clone(), - current_justified_checkpoint: self.current_justified_checkpoint.clone(), - finalized_checkpoint: self.finalized_checkpoint.clone(), + previous_justified_checkpoint: self.previous_justified_checkpoint, + current_justified_checkpoint: self.current_justified_checkpoint, + finalized_checkpoint: self.finalized_checkpoint, committee_caches: if config.committee_caches { self.committee_caches.clone() } else { diff --git a/consensus/types/src/beacon_state/tree_hash_cache.rs b/consensus/types/src/beacon_state/tree_hash_cache.rs index a73e3326cdf..3e1fa29d07f 100644 --- a/consensus/types/src/beacon_state/tree_hash_cache.rs +++ b/consensus/types/src/beacon_state/tree_hash_cache.rs @@ -5,6 +5,7 @@ use crate::{BeaconState, EthSpec, Hash256, Unsigned, Validator}; use cached_tree_hash::{int_log, CacheArena, CachedTreeHash, TreeHashCache}; use rayon::prelude::*; use ssz_derive::{Decode, Encode}; +use std::cmp::Ordering; use tree_hash::{mix_in_length, MerkleHasher, TreeHash}; /// The number of fields on a beacon state. @@ -270,8 +271,8 @@ impl ParallelValidatorTreeHash { /// This function makes assumptions that the `validators` list will only change in accordance /// with valid per-block/per-slot state transitions. fn leaves(&mut self, validators: &[Validator]) -> Result>, Error> { - if self.len() < validators.len() { - validators.iter().skip(self.len()).for_each(|v| { + match self.len().cmp(&validators.len()) { + Ordering::Less => validators.iter().skip(self.len()).for_each(|v| { if self .arenas .last() @@ -287,9 +288,11 @@ impl ParallelValidatorTreeHash { .expect("Cannot reach this block if arenas is empty."); caches.push(v.new_tree_hash_cache(arena)) } - }) - } else if validators.len() < self.len() { - return Err(Error::ValidatorRegistryShrunk); + }), + Ordering::Greater => { + return Err(Error::ValidatorRegistryShrunk); + } + Ordering::Equal => (), } self.arenas diff --git a/consensus/types/src/test_utils/builders/testing_attestation_data_builder.rs b/consensus/types/src/test_utils/builders/testing_attestation_data_builder.rs index 60663cea62f..9ecef281586 100644 --- a/consensus/types/src/test_utils/builders/testing_attestation_data_builder.rs +++ b/consensus/types/src/test_utils/builders/testing_attestation_data_builder.rs @@ -24,9 +24,9 @@ impl TestingAttestationDataBuilder { let is_previous_epoch = slot.epoch(T::slots_per_epoch()) != current_epoch; let mut source = if is_previous_epoch { - state.previous_justified_checkpoint.clone() + state.previous_justified_checkpoint } else { - state.current_justified_checkpoint.clone() + state.current_justified_checkpoint }; let mut target = if is_previous_epoch { diff --git a/consensus/types/src/test_utils/builders/testing_attester_slashing_builder.rs b/consensus/types/src/test_utils/builders/testing_attester_slashing_builder.rs index 356f10ec827..bc90bdb8a92 100644 --- a/consensus/types/src/test_utils/builders/testing_attester_slashing_builder.rs +++ b/consensus/types/src/test_utils/builders/testing_attester_slashing_builder.rs @@ -42,7 +42,7 @@ impl TestingAttesterSlashingBuilder { slot, index, beacon_block_root: hash_1, - source: checkpoint_1.clone(), + source: checkpoint_1, target: checkpoint_1, }; diff --git a/crypto/bls/src/signature_set.rs b/crypto/bls/src/signature_set.rs index aa0a3839bb2..c391ea45bb8 100644 --- a/crypto/bls/src/signature_set.rs +++ b/crypto/bls/src/signature_set.rs @@ -60,7 +60,7 @@ type VerifySet<'a> = ( ); #[cfg(not(feature = "fake_crypto"))] -pub fn verify_signature_sets<'a>(sets: Vec) -> bool { +pub fn verify_signature_sets(sets: Vec) -> bool { let rng = &mut rand::thread_rng(); let verify_set: Vec = sets .iter() diff --git a/crypto/eth2_key_derivation/src/derived_key.rs b/crypto/eth2_key_derivation/src/derived_key.rs index 16e20cbe310..caacac162f4 100644 --- a/crypto/eth2_key_derivation/src/derived_key.rs +++ b/crypto/eth2_key_derivation/src/derived_key.rs @@ -81,7 +81,7 @@ fn derive_child_sk(parent_sk: &[u8], index: u32) -> SecretHash { /// /// Equivalent to `HKDF_mod_r` in EIP-2333. fn hkdf_mod_r(ikm: &[u8]) -> SecretHash { - let prk = hkdf_extract("BLS-SIG-KEYGEN-SALT-".as_bytes(), ikm); + let prk = hkdf_extract(b"BLS-SIG-KEYGEN-SALT-", ikm); let okm = &hkdf_expand(prk, MOD_R_L); mod_r(okm.as_bytes()) } diff --git a/crypto/eth2_key_derivation/src/plain_text.rs b/crypto/eth2_key_derivation/src/plain_text.rs index 5aae300e52d..8d70fa8347f 100644 --- a/crypto/eth2_key_derivation/src/plain_text.rs +++ b/crypto/eth2_key_derivation/src/plain_text.rs @@ -16,6 +16,11 @@ impl PlainText { self.0.len() } + /// Checks whether `self` is empty + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + /// Returns a reference to the underlying bytes. pub fn as_bytes(&self) -> &[u8] { &self.0 diff --git a/crypto/eth2_keystore/src/json_keystore/hex_bytes.rs b/crypto/eth2_keystore/src/json_keystore/hex_bytes.rs index 92d8d16b29b..67e156ff43c 100644 --- a/crypto/eth2_keystore/src/json_keystore/hex_bytes.rs +++ b/crypto/eth2_keystore/src/json_keystore/hex_bytes.rs @@ -14,6 +14,10 @@ impl HexBytes { pub fn len(&self) -> usize { self.0.len() } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } } impl From> for HexBytes { diff --git a/crypto/eth2_keystore/src/json_keystore/kdf_module.rs b/crypto/eth2_keystore/src/json_keystore/kdf_module.rs index b8dc01fa729..89fdd219e8e 100644 --- a/crypto/eth2_keystore/src/json_keystore/kdf_module.rs +++ b/crypto/eth2_keystore/src/json_keystore/kdf_module.rs @@ -66,7 +66,7 @@ pub enum Prf { impl Prf { pub fn mac(&self, password: &[u8]) -> impl Mac { match &self { - _hmac_sha256 => { + Prf::HmacSha256 => { Hmac::::new_varkey(password).expect("Could not derive HMAC using SHA256.") } } diff --git a/crypto/eth2_keystore/src/keystore.rs b/crypto/eth2_keystore/src/keystore.rs index da679159093..4867146102a 100644 --- a/crypto/eth2_keystore/src/keystore.rs +++ b/crypto/eth2_keystore/src/keystore.rs @@ -409,10 +409,10 @@ fn derive_key(password: &[u8], kdf: &Kdf) -> Result { password, params.salt.as_bytes(), &ScryptParams::new(log2_int(params.n) as u8, params.r, params.p) - .map_err(|e| Error::ScryptInvalidParams(e))?, + .map_err(Error::ScryptInvalidParams)?, dk.as_mut_bytes(), ) - .map_err(|e| Error::ScryptInvaidOutputLen(e))?; + .map_err(Error::ScryptInvaidOutputLen)?; } } diff --git a/lcli/src/deploy_deposit_contract.rs b/lcli/src/deploy_deposit_contract.rs index c50d33cc85f..71d22f59a24 100644 --- a/lcli/src/deploy_deposit_contract.rs +++ b/lcli/src/deploy_deposit_contract.rs @@ -1,5 +1,4 @@ use clap::ArgMatches; -use clap_utils; use deposit_contract::{ testnet::{ABI, BYTECODE}, CONTRACT_DEPLOY_GAS, diff --git a/lcli/src/new_testnet.rs b/lcli/src/new_testnet.rs index a3d1e2d2226..918426e74d3 100644 --- a/lcli/src/new_testnet.rs +++ b/lcli/src/new_testnet.rs @@ -17,13 +17,11 @@ pub fn run(matches: &ArgMatches) -> Result<(), String> { let overwrite_files = matches.is_present("force"); - if testnet_dir_path.exists() { - if !overwrite_files { - return Err(format!( - "{:?} already exists, will not overwrite. Use --force to overwrite", - testnet_dir_path - )); - } + if testnet_dir_path.exists() && !overwrite_files { + return Err(format!( + "{:?} already exists, will not overwrite. Use --force to overwrite", + testnet_dir_path + )); } let mut spec = T::default_spec(); diff --git a/lighthouse/environment/src/executor.rs b/lighthouse/environment/src/executor.rs index 78c9de3039b..f7d06cc516a 100644 --- a/lighthouse/environment/src/executor.rs +++ b/lighthouse/environment/src/executor.rs @@ -79,7 +79,7 @@ impl TaskExecutor { /// This function generates prometheus metrics on number of tasks and task duration. pub fn spawn_blocking(&self, task: F, name: &'static str) where - F: FnOnce() -> () + Send + 'static, + F: FnOnce() + Send + 'static, { let exit = self.exit.clone(); let log = self.log.clone(); diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index ed5bb47caa6..349e497eb1f 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -3,7 +3,6 @@ extern crate clap; use beacon_node::ProductionBeaconNode; use clap::{App, Arg, ArgMatches}; -use clap_utils; use env_logger::{Builder, Env}; use environment::EnvironmentBuilder; use eth2_testnet_config::HARDCODED_TESTNET; @@ -272,5 +271,6 @@ fn run( drop(validator_client); // Shutdown the environment once all tasks have completed. - Ok(environment.shutdown_on_idle()) + environment.shutdown_on_idle(); + Ok(()) } diff --git a/testing/simulator/src/eth1_sim.rs b/testing/simulator/src/eth1_sim.rs index 18b846a1152..64c439320ad 100644 --- a/testing/simulator/src/eth1_sim.rs +++ b/testing/simulator/src/eth1_sim.rs @@ -17,10 +17,7 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> { .expect("missing validators_per_node default"); let speed_up_factor = value_t!(matches, "speed_up_factor", u64).expect("missing speed_up_factor default"); - let mut end_after_checks = true; - if matches.is_present("end_after_checks") { - end_after_checks = false; - } + let end_after_checks = !matches.is_present("end_after_checks"); println!("Beacon Chain Simulator:"); println!(" nodes:{}", node_count); @@ -83,7 +80,7 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> { // Start a timer that produces eth1 blocks on an interval. tokio::spawn(async move { let mut interval = tokio::time::interval(eth1_block_time); - while let Some(_) = interval.next().await { + while interval.next().await.is_some() { let _ = ganache.evm_mine().await; } }); @@ -198,5 +195,6 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> { Ok::<(), String>(()) }; - Ok(env.runtime().block_on(main_future).unwrap()) + env.runtime().block_on(main_future).unwrap(); + Ok(()) } diff --git a/testing/simulator/src/no_eth1_sim.rs b/testing/simulator/src/no_eth1_sim.rs index 910c2026783..b95bdce9313 100644 --- a/testing/simulator/src/no_eth1_sim.rs +++ b/testing/simulator/src/no_eth1_sim.rs @@ -17,10 +17,7 @@ pub fn run_no_eth1_sim(matches: &ArgMatches) -> Result<(), String> { .expect("missing validators_per_node default"); let speed_up_factor = value_t!(matches, "speed_up_factor", u64).expect("missing speed_up_factor default"); - let mut end_after_checks = true; - if matches.is_present("end_after_checks") { - end_after_checks = false; - } + let end_after_checks = !matches.is_present("end_after_checks"); println!("Beacon Chain Simulator:"); println!(" nodes:{}", node_count); @@ -165,5 +162,6 @@ pub fn run_no_eth1_sim(matches: &ArgMatches) -> Result<(), String> { Ok::<(), String>(()) }; - Ok(env.runtime().block_on(main_future).unwrap()) + env.runtime().block_on(main_future).unwrap(); + Ok(()) } diff --git a/testing/simulator/src/sync_sim.rs b/testing/simulator/src/sync_sim.rs index 68d7aa1b035..7583a6eab20 100644 --- a/testing/simulator/src/sync_sim.rs +++ b/testing/simulator/src/sync_sim.rs @@ -209,7 +209,7 @@ pub async fn verify_one_node_sync( // limited to at most `sync_timeout` epochs let mut interval = tokio::time::interval(epoch_duration); let mut count = 0; - while let Some(_) = interval.next().await { + while interval.next().await.is_some() { if count >= sync_timeout || !check_still_syncing(&network_c).await? { break; } @@ -246,7 +246,7 @@ pub async fn verify_two_nodes_sync( // limited to at most `sync_timeout` epochs let mut interval = tokio::time::interval(epoch_duration); let mut count = 0; - while let Some(_) = interval.next().await { + while interval.next().await.is_some() { if count >= sync_timeout || !check_still_syncing(&network_c).await? { break; } @@ -294,7 +294,7 @@ pub async fn verify_in_between_sync( // limited to at most `sync_timeout` epochs let mut interval = tokio::time::interval(epoch_duration); let mut count = 0; - while let Some(_) = interval.next().await { + while interval.next().await.is_some() { if count >= sync_timeout || !check_still_syncing(&network_c).await? { break; } diff --git a/validator_client/src/attestation_service.rs b/validator_client/src/attestation_service.rs index e343cde0104..fa79877774b 100644 --- a/validator_client/src/attestation_service.rs +++ b/validator_client/src/attestation_service.rs @@ -190,7 +190,7 @@ impl AttestationService { .into_iter() .fold(HashMap::new(), |mut map, duty_and_proof| { if let Some(committee_index) = duty_and_proof.duty.attestation_committee_index { - let validator_duties = map.entry(committee_index).or_insert_with(|| vec![]); + let validator_duties = map.entry(committee_index).or_insert_with(Vec::new); validator_duties.push(duty_and_proof); } diff --git a/validator_client/src/duties_service.rs b/validator_client/src/duties_service.rs index 403c384a414..7375d550235 100644 --- a/validator_client/src/duties_service.rs +++ b/validator_client/src/duties_service.rs @@ -151,9 +151,9 @@ enum InsertOutcome { impl InsertOutcome { /// Returns `true` if the outcome indicates that the validator _might_ require a subscription. - pub fn is_subscription_candidate(self) -> bool { + pub fn is_subscription_candidate(&self) -> bool { match self { - InsertOutcome::Replaced { should_resubscribe } => should_resubscribe, + InsertOutcome::Replaced { should_resubscribe } => *should_resubscribe, InsertOutcome::NewValidator | InsertOutcome::NewEpoch => true, InsertOutcome::Identical | InsertOutcome::Invalid | InsertOutcome::NewProposalSlots => { false diff --git a/validator_client/src/fork_service.rs b/validator_client/src/fork_service.rs index 1407ed3c55d..b8db7b72e3c 100644 --- a/validator_client/src/fork_service.rs +++ b/validator_client/src/fork_service.rs @@ -95,7 +95,7 @@ impl Deref for ForkService { impl ForkService { /// Returns the last fork downloaded from the beacon node, if any. pub fn fork(&self) -> Option { - self.fork.read().clone() + *self.fork.read() } /// Starts the service that periodically polls for the `Fork`. diff --git a/validator_client/src/initialized_validators.rs b/validator_client/src/initialized_validators.rs index 28f1ecbc3ab..14e034590b9 100644 --- a/validator_client/src/initialized_validators.rs +++ b/validator_client/src/initialized_validators.rs @@ -345,11 +345,14 @@ impl InitializedValidators { voting_public_key: &PublicKey, enabled: bool, ) -> Result<(), Error> { - self.definitions + if let Some(def) = self + .definitions .as_mut_slice() .iter_mut() .find(|def| def.voting_public_key == *voting_public_key) - .map(|def| def.enabled = enabled); + { + def.enabled = enabled; + } self.update_validators()?; diff --git a/validator_client/src/validator_definitions.rs b/validator_client/src/validator_definitions.rs index 6b23b7d1884..f7dbfabe81b 100644 --- a/validator_client/src/validator_definitions.rs +++ b/validator_client/src/validator_definitions.rs @@ -6,7 +6,6 @@ use account_utils::{create_with_600_perms, default_keystore_password_path, ZeroizeString}; use eth2_keystore::Keystore; use serde_derive::{Deserialize, Serialize}; -use serde_yaml; use slog::{error, Logger}; use std::collections::HashSet; use std::fs::{self, OpenOptions}; @@ -230,14 +229,13 @@ pub fn recursively_find_voting_keystores>( let file_type = dir_entry.file_type()?; if file_type.is_dir() { recursively_find_voting_keystores(dir_entry.path(), matches)? - } else if file_type.is_file() { - if dir_entry + } else if file_type.is_file() + && dir_entry .file_name() .to_str() .map_or(false, |filename| filename == VOTING_KEYSTORE_FILE) - { - matches.push(dir_entry.path()) - } + { + matches.push(dir_entry.path()) } Ok(()) })