diff --git a/beacon_node/beacon_chain/src/head_tracker.rs b/beacon_node/beacon_chain/src/head_tracker.rs index 6d6ab6e12..4a4ce2fe5 100644 --- a/beacon_node/beacon_chain/src/head_tracker.rs +++ b/beacon_node/beacon_chain/src/head_tracker.rs @@ -1,7 +1,6 @@ use parking_lot::RwLock; use ssz_derive::{Decode, Encode}; use std::collections::HashMap; -use std::iter::FromIterator; use types::{Hash256, Slot}; #[derive(Debug, PartialEq)] @@ -61,13 +60,12 @@ impl HeadTracker { slots_len, }) } else { - let map = HashMap::from_iter( - ssz_container - .roots - .iter() - .zip(ssz_container.slots.iter()) - .map(|(root, slot)| (*root, *slot)), - ); + let map = ssz_container + .roots + .iter() + .zip(ssz_container.slots.iter()) + .map(|(root, slot)| (*root, *slot)) + .collect::>(); Ok(Self(RwLock::new(map))) } diff --git a/beacon_node/beacon_chain/src/observed_operations.rs b/beacon_node/beacon_chain/src/observed_operations.rs index e16ede5a0..f1eb996a5 100644 --- a/beacon_node/beacon_chain/src/observed_operations.rs +++ b/beacon_node/beacon_chain/src/observed_operations.rs @@ -2,7 +2,6 @@ use derivative::Derivative; use smallvec::SmallVec; use state_processing::{SigVerifiedOp, VerifyOperation}; use std::collections::HashSet; -use std::iter::FromIterator; use std::marker::PhantomData; use types::{ AttesterSlashing, BeaconState, ChainSpec, EthSpec, ProposerSlashing, SignedVoluntaryExit, @@ -57,10 +56,18 @@ impl ObservableOperation for ProposerSlashing { impl ObservableOperation for AttesterSlashing { fn observed_validators(&self) -> SmallVec<[u64; SMALL_VEC_SIZE]> { - let attestation_1_indices = - HashSet::::from_iter(self.attestation_1.attesting_indices.iter().copied()); - let attestation_2_indices = - HashSet::::from_iter(self.attestation_2.attesting_indices.iter().copied()); + let attestation_1_indices = self + .attestation_1 + .attesting_indices + .iter() + .copied() + .collect::>(); + let attestation_2_indices = self + .attestation_2 + .attesting_indices + .iter() + .copied() + .collect::>(); attestation_1_indices .intersection(&attestation_2_indices) .copied() diff --git a/beacon_node/eth1/src/service.rs b/beacon_node/eth1/src/service.rs index 6cfbf581b..22c4600e0 100644 --- a/beacon_node/eth1/src/service.rs +++ b/beacon_node/eth1/src/service.rs @@ -878,7 +878,13 @@ impl Service { // imported if any one of them cannot be parsed. .collect::, _>>()? .into_iter() - .map(|deposit_log| { + // Returns if a deposit is unable to be added to the cache. + // + // If this error occurs, the cache will no longer be guaranteed to hold either + // none or all of the logs for each block (i.e., they may exist _some_ logs for + // a block, but not _all_ logs for that block). This scenario can cause the + // node to choose an invalid genesis state or propose an invalid block. + .try_for_each(|deposit_log| { if let DepositCacheInsertOutcome::Inserted = cache .cache .insert_log(deposit_log) @@ -888,14 +894,7 @@ impl Service { } Ok(()) - }) - // Returns if a deposit is unable to be added to the cache. - // - // If this error occurs, the cache will no longer be guaranteed to hold either - // none or all of the logs for each block (i.e., they may exist _some_ logs for - // a block, but not _all_ logs for that block). This scenario can cause the - // node to choose an invalid genesis state or propose an invalid block. - .collect::>()?; + })?; debug!( self.log, diff --git a/beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs b/beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs index 875c6cf84..54fc34f92 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs @@ -70,16 +70,16 @@ impl PeerScoreSettings { enr_fork_id: &EnrForkId, current_slot: Slot, ) -> error::Result { - let mut params = PeerScoreParams::default(); - - params.decay_interval = self.decay_interval; - params.decay_to_zero = self.decay_to_zero; - params.retain_score = self.epoch * 100; - params.app_specific_weight = 1.0; - params.ip_colocation_factor_threshold = 3.0; - params.behaviour_penalty_threshold = 6.0; - - params.behaviour_penalty_decay = self.score_parameter_decay(self.epoch * 10); + let mut params = PeerScoreParams { + decay_interval: self.decay_interval, + decay_to_zero: self.decay_to_zero, + retain_score: self.epoch * 100, + app_specific_weight: 1.0, + ip_colocation_factor_threshold: 3.0, + behaviour_penalty_threshold: 6.0, + behaviour_penalty_decay: self.score_parameter_decay(self.epoch * 10), + ..Default::default() + }; let target_value = Self::decay_convergence( params.behaviour_penalty_decay, diff --git a/beacon_node/eth2_libp2p/src/peer_manager/peer_info.rs b/beacon_node/eth2_libp2p/src/peer_manager/peer_info.rs index 92b39966c..3b95fc11a 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/peer_info.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/peer_info.rs @@ -97,7 +97,7 @@ impl PeerInfo { } /// Returns the seen IP addresses of the peer. - pub fn seen_addresses<'a>(&'a self) -> impl Iterator + 'a { + pub fn seen_addresses(&self) -> impl Iterator + '_ { self.seen_addresses .iter() .map(|socket_addr| socket_addr.ip()) diff --git a/beacon_node/eth2_libp2p/src/peer_manager/peer_sync_status.rs b/beacon_node/eth2_libp2p/src/peer_manager/peer_sync_status.rs index 32580beff..473741d4f 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/peer_sync_status.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/peer_sync_status.rs @@ -29,14 +29,12 @@ pub struct SyncInfo { impl std::cmp::PartialEq for PeerSyncStatus { fn eq(&self, other: &Self) -> bool { - match (self, other) { - (PeerSyncStatus::Synced { .. }, PeerSyncStatus::Synced { .. }) => true, - (PeerSyncStatus::Advanced { .. }, PeerSyncStatus::Advanced { .. }) => true, - (PeerSyncStatus::Behind { .. }, PeerSyncStatus::Behind { .. }) => true, - (PeerSyncStatus::IrrelevantPeer, PeerSyncStatus::IrrelevantPeer) => true, - (PeerSyncStatus::Unknown, PeerSyncStatus::Unknown) => true, - _ => false, - } + matches!((self, other), + (PeerSyncStatus::Synced { .. }, PeerSyncStatus::Synced { .. }) | + (PeerSyncStatus::Advanced { .. }, PeerSyncStatus::Advanced { .. }) | + (PeerSyncStatus::Behind { .. }, PeerSyncStatus::Behind { .. }) | + (PeerSyncStatus::IrrelevantPeer, PeerSyncStatus::IrrelevantPeer) | + (PeerSyncStatus::Unknown, PeerSyncStatus::Unknown)) } } diff --git a/beacon_node/eth2_libp2p/src/types/sync_state.rs b/beacon_node/eth2_libp2p/src/types/sync_state.rs index 628058abd..f5b6a1558 100644 --- a/beacon_node/eth2_libp2p/src/types/sync_state.rs +++ b/beacon_node/eth2_libp2p/src/types/sync_state.rs @@ -23,14 +23,12 @@ pub enum SyncState { impl PartialEq for SyncState { fn eq(&self, other: &Self) -> bool { - match (self, other) { - (SyncState::SyncingFinalized { .. }, SyncState::SyncingFinalized { .. }) => true, - (SyncState::SyncingHead { .. }, SyncState::SyncingHead { .. }) => true, - (SyncState::Synced, SyncState::Synced) => true, - (SyncState::Stalled, SyncState::Stalled) => true, - (SyncState::SyncTransition, SyncState::SyncTransition) => true, - _ => false, - } + matches!((self, other), + (SyncState::SyncingFinalized { .. }, SyncState::SyncingFinalized { .. }) | + (SyncState::SyncingHead { .. }, SyncState::SyncingHead { .. }) | + (SyncState::Synced, SyncState::Synced) | + (SyncState::Stalled, SyncState::Stalled) | + (SyncState::SyncTransition, SyncState::SyncTransition)) } } diff --git a/beacon_node/network/src/service/tests.rs b/beacon_node/network/src/service/tests.rs index b425e1c64..c7186a839 100644 --- a/beacon_node/network/src/service/tests.rs +++ b/beacon_node/network/src/service/tests.rs @@ -70,11 +70,9 @@ mod tests { // Create a new network service which implicitly gets dropped at the // end of the block. - let _ = NetworkService::start(beacon_chain.clone(), &config, executor) + let _network_service = NetworkService::start(beacon_chain.clone(), &config, executor) .await .unwrap(); - // Allow the network task to spawn on the executor before shutting down. - tokio::time::sleep(std::time::Duration::from_secs(1)).await; drop(signal); }); diff --git a/beacon_node/network/src/sync/range_sync/chain.rs b/beacon_node/network/src/sync/range_sync/chain.rs index ccf18d2e5..01466e2a9 100644 --- a/beacon_node/network/src/sync/range_sync/chain.rs +++ b/beacon_node/network/src/sync/range_sync/chain.rs @@ -161,7 +161,7 @@ impl SyncingChain { } /// Peers currently syncing this chain. - pub fn peers<'a>(&'a self) -> impl Iterator + 'a { + pub fn peers(&self) -> impl Iterator + '_ { self.peers.keys().cloned() } diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 437a94620..38df71c47 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -26,9 +26,10 @@ pub fn get_config( spec: &ChainSpec, log: Logger, ) -> Result { - let mut client_config = ClientConfig::default(); - - client_config.data_dir = get_data_dir(cli_args); + let mut client_config = ClientConfig { + data_dir: get_data_dir(cli_args), + ..Default::default() + }; // If necessary, remove any existing database and configuration if client_config.data_dir.exists() && cli_args.is_present("purge-db") { diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index a612d413e..31785bdf7 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -202,9 +202,7 @@ impl HotColdDB, LevelDB> { } /// Return an iterator over the state roots of all temporary states. - pub fn iter_temporary_state_roots<'a>( - &'a self, - ) -> impl Iterator> + 'a { + pub fn iter_temporary_state_roots(&self) -> impl Iterator> + '_ { let column = DBColumn::BeaconStateTemporary; let start_key = BytesKey::from_vec(get_key_for_col(column.into(), Hash256::zero().as_bytes())); diff --git a/common/account_utils/src/validator_definitions.rs b/common/account_utils/src/validator_definitions.rs index 6106b4a5a..a38aebf40 100644 --- a/common/account_utils/src/validator_definitions.rs +++ b/common/account_utils/src/validator_definitions.rs @@ -12,7 +12,6 @@ use slog::{error, Logger}; use std::collections::HashSet; use std::fs::{self, OpenOptions}; use std::io; -use std::iter::FromIterator; use std::path::{Path, PathBuf}; use types::PublicKey; use validator_dir::VOTING_KEYSTORE_FILE; @@ -154,13 +153,16 @@ impl ValidatorDefinitions { recursively_find_voting_keystores(validators_dir, &mut keystore_paths) .map_err(Error::UnableToSearchForKeystores)?; - let known_paths: HashSet<&PathBuf> = - HashSet::from_iter(self.0.iter().map(|def| match &def.signing_definition { + let known_paths: HashSet<&PathBuf> = self + .0 + .iter() + .map(|def| match &def.signing_definition { SigningDefinition::LocalKeystore { voting_keystore_path, .. } => voting_keystore_path, - })); + }) + .collect(); let mut new_defs = keystore_paths .into_iter() diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index 41e705c72..49719a4c2 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -449,7 +449,7 @@ impl TryFrom for QueryVec { type Error = String; fn try_from(string: String) -> Result { - if string == "" { + if string.is_empty() { return Ok(Self(vec![])); } diff --git a/consensus/cached_tree_hash/src/impls.rs b/consensus/cached_tree_hash/src/impls.rs index 6c7e3cf41..0e6bf6142 100644 --- a/consensus/cached_tree_hash/src/impls.rs +++ b/consensus/cached_tree_hash/src/impls.rs @@ -24,15 +24,15 @@ pub fn u64_leaf_count(len: usize) -> usize { (len + vals_per_chunk - 1) / vals_per_chunk } -pub fn hash256_iter<'a>( - values: &'a [Hash256], -) -> impl Iterator + ExactSizeIterator + 'a { +pub fn hash256_iter( + values: &[Hash256], +) -> impl Iterator + ExactSizeIterator + '_ { values.iter().copied().map(Hash256::to_fixed_bytes) } -pub fn u64_iter<'a>( - values: &'a [u64], -) -> impl Iterator + ExactSizeIterator + 'a { +pub fn u64_iter( + values: &[u64], +) -> impl Iterator + ExactSizeIterator + '_ { let type_size = size_of::(); let vals_per_chunk = BYTES_PER_CHUNK / type_size; values.chunks(vals_per_chunk).map(move |xs| { diff --git a/consensus/proto_array/src/ssz_container.rs b/consensus/proto_array/src/ssz_container.rs index 06dc48c5f..c79c433e3 100644 --- a/consensus/proto_array/src/ssz_container.rs +++ b/consensus/proto_array/src/ssz_container.rs @@ -4,7 +4,6 @@ use crate::{ }; use ssz_derive::{Decode, Encode}; use std::collections::HashMap; -use std::iter::FromIterator; use types::{Epoch, Hash256}; #[derive(Encode, Decode)] @@ -41,7 +40,7 @@ impl From for ProtoArrayForkChoice { justified_epoch: from.justified_epoch, finalized_epoch: from.finalized_epoch, nodes: from.nodes, - indices: HashMap::from_iter(from.indices.into_iter()), + indices: from.indices.into_iter().collect::>(), }; Self { diff --git a/consensus/ssz_derive/src/lib.rs b/consensus/ssz_derive/src/lib.rs index cee167012..2170251ae 100644 --- a/consensus/ssz_derive/src/lib.rs +++ b/consensus/ssz_derive/src/lib.rs @@ -14,9 +14,7 @@ use syn::{parse_macro_input, DeriveInput}; /// /// # Panics /// Any unnamed struct field (like in a tuple struct) will raise a panic at compile time. -fn get_serializable_named_field_idents<'a>( - struct_data: &'a syn::DataStruct, -) -> Vec<&'a syn::Ident> { +fn get_serializable_named_field_idents(struct_data: &syn::DataStruct) -> Vec<&syn::Ident> { struct_data .fields .iter() @@ -35,7 +33,7 @@ fn get_serializable_named_field_idents<'a>( /// Returns a Vec of `syn::Type` for each named field in the struct, whilst filtering out fields /// that should not be serialized. -fn get_serializable_field_types<'a>(struct_data: &'a syn::DataStruct) -> Vec<&'a syn::Type> { +fn get_serializable_field_types(struct_data: &syn::DataStruct) -> Vec<&syn::Type> { struct_data .fields .iter() 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 e6b71b24e..cac8c4d1c 100644 --- a/consensus/state_processing/src/per_block_processing/signature_sets.rs +++ b/consensus/state_processing/src/per_block_processing/signature_sets.rs @@ -44,10 +44,10 @@ impl From for Error { } /// Helper function to get a public key from a `state`. -pub fn get_pubkey_from_state<'a, T>( - state: &'a BeaconState, +pub fn get_pubkey_from_state( + state: &BeaconState, validator_index: usize, -) -> Option> +) -> Option> where T: EthSpec, { diff --git a/consensus/state_processing/src/per_block_processing/tests.rs b/consensus/state_processing/src/per_block_processing/tests.rs index 55bc459cd..a0dcd66c4 100644 --- a/consensus/state_processing/src/per_block_processing/tests.rs +++ b/consensus/state_processing/src/per_block_processing/tests.rs @@ -391,7 +391,7 @@ fn invalid_attestation_wrong_justified_checkpoint() { root: Hash256::zero(), }, attestation: Checkpoint { - epoch: Epoch::from(0 as u64), + epoch: Epoch::from(0_u64), root: Hash256::zero(), }, is_current: true, @@ -877,7 +877,7 @@ fn invalid_proposer_slashing_proposal_epoch_mismatch() { Err(BlockProcessingError::ProposerSlashingInvalid { index: 0, reason: ProposerSlashingInvalid::ProposalSlotMismatch( - Slot::from(0 as u64), + Slot::from(0_u64), Slot::from(128 as u64) ) }) diff --git a/consensus/tree_hash_derive/src/lib.rs b/consensus/tree_hash_derive/src/lib.rs index d57903654..97a332394 100644 --- a/consensus/tree_hash_derive/src/lib.rs +++ b/consensus/tree_hash_derive/src/lib.rs @@ -10,7 +10,7 @@ use syn::{parse_macro_input, Attribute, DeriveInput, Meta}; /// /// # Panics /// Any unnamed struct field (like in a tuple struct) will raise a panic at compile time. -fn get_hashable_fields<'a>(struct_data: &'a syn::DataStruct) -> Vec<&'a syn::Ident> { +fn get_hashable_fields(struct_data: &syn::DataStruct) -> Vec<&syn::Ident> { get_hashable_fields_and_their_caches(struct_data) .into_iter() .map(|(ident, _, _)| ident) @@ -18,9 +18,9 @@ fn get_hashable_fields<'a>(struct_data: &'a syn::DataStruct) -> Vec<&'a syn::Ide } /// Return a Vec of the hashable fields of a struct, and each field's type and optional cache field. -fn get_hashable_fields_and_their_caches<'a>( - struct_data: &'a syn::DataStruct, -) -> Vec<(&'a syn::Ident, syn::Type, Option)> { +fn get_hashable_fields_and_their_caches( + struct_data: &syn::DataStruct, +) -> Vec<(&syn::Ident, syn::Type, Option)> { struct_data .fields .iter() diff --git a/consensus/types/src/beacon_block.rs b/consensus/types/src/beacon_block.rs index d3a916070..71b0f9545 100644 --- a/consensus/types/src/beacon_block.rs +++ b/consensus/types/src/beacon_block.rs @@ -68,7 +68,7 @@ impl BeaconBlock { }; let indexed_attestation: IndexedAttestation = IndexedAttestation { attesting_indices: VariableList::new(vec![ - 0 as u64; + 0_u64; T::MaxValidatorsPerCommittee::to_usize() ]) .unwrap(), 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 56b3e3bbe..a704374ee 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 @@ -69,7 +69,7 @@ impl TestingAttestationDataBuilder { } AttestationTestTask::WrongJustifiedCheckpoint => { source = Checkpoint { - epoch: Epoch::from(0 as u64), + epoch: Epoch::from(0_u64), root: Hash256::zero(), } } diff --git a/crypto/eth2_key_derivation/src/derived_key.rs b/crypto/eth2_key_derivation/src/derived_key.rs index 8ed6c9bd4..a783a511d 100644 --- a/crypto/eth2_key_derivation/src/derived_key.rs +++ b/crypto/eth2_key_derivation/src/derived_key.rs @@ -35,6 +35,11 @@ pub const MOD_R_L: usize = 48; #[zeroize(drop)] pub struct DerivedKey(ZeroizeHash); +#[derive(Debug, PartialEq)] +pub enum Error { + EmptySeed, +} + impl DerivedKey { /// Instantiates `Self` from some secret seed bytes. /// @@ -42,10 +47,10 @@ impl DerivedKey { /// /// ## Errors /// - /// Returns `Err(())` if `seed.is_empty()`, otherwise always returns `Ok(self)`. - pub fn from_seed(seed: &[u8]) -> Result { + /// Returns `Err(Error::EmptySeed)` if `seed.is_empty()`, otherwise always returns `Ok(self)`. + pub fn from_seed(seed: &[u8]) -> Result { if seed.is_empty() { - Err(()) + Err(Error::EmptySeed) } else { Ok(Self(derive_master_sk(seed))) } diff --git a/crypto/eth2_key_derivation/src/lib.rs b/crypto/eth2_key_derivation/src/lib.rs index 8c5c1c519..aa29da6b8 100644 --- a/crypto/eth2_key_derivation/src/lib.rs +++ b/crypto/eth2_key_derivation/src/lib.rs @@ -8,4 +8,5 @@ mod secret_bytes; pub use bls::ZeroizeHash; pub use derived_key::DerivedKey; +pub use derived_key::Error as DerivedKeyError; pub use plain_text::PlainText; diff --git a/crypto/eth2_wallet/src/wallet.rs b/crypto/eth2_wallet/src/wallet.rs index 694be44d4..a03e63557 100644 --- a/crypto/eth2_wallet/src/wallet.rs +++ b/crypto/eth2_wallet/src/wallet.rs @@ -5,17 +5,16 @@ use crate::{ }, KeyType, ValidatorPath, }; +pub use bip39::{Mnemonic, Seed as Bip39Seed}; +pub use eth2_key_derivation::{DerivedKey, DerivedKeyError}; use eth2_keystore::{ decrypt, default_kdf, encrypt, keypair_from_secret, Keystore, KeystoreBuilder, IV_SIZE, SALT_SIZE, }; +pub use eth2_keystore::{Error as KeystoreError, PlainText}; use rand::prelude::*; use serde::{Deserialize, Serialize}; use std::io::{Read, Write}; - -pub use bip39::{Mnemonic, Seed as Bip39Seed}; -pub use eth2_key_derivation::DerivedKey; -pub use eth2_keystore::{Error as KeystoreError, PlainText}; pub use uuid::Uuid; #[derive(Debug, PartialEq)] @@ -24,6 +23,7 @@ pub enum Error { PathExhausted, EmptyPassword, EmptySeed, + InvalidNextAccount { old: u32, new: u32 }, } impl From for Error { @@ -32,6 +32,14 @@ impl From for Error { } } +impl From for Error { + fn from(e: DerivedKeyError) -> Error { + match e { + DerivedKeyError::EmptySeed => Error::EmptySeed, + } + } +} + /// Contains the two keystores required for an eth2 validator. pub struct ValidatorKeystores { /// Contains the secret key used for signing every-day consensus messages (blocks, @@ -222,12 +230,15 @@ impl Wallet { /// /// Returns `Err(())` if `nextaccount` is less than `self.nextaccount()` without mutating /// `self`. This is to protect against duplicate validator generation. - pub fn set_nextaccount(&mut self, nextaccount: u32) -> Result<(), ()> { + pub fn set_nextaccount(&mut self, nextaccount: u32) -> Result<(), Error> { if nextaccount >= self.nextaccount() { self.json.nextaccount = nextaccount; Ok(()) } else { - Err(()) + Err(Error::InvalidNextAccount { + old: self.json.nextaccount, + new: nextaccount, + }) } } @@ -295,7 +306,7 @@ pub fn recover_validator_secret( ) -> Result<(PlainText, ValidatorPath), Error> { let path = ValidatorPath::new(index, key_type); let secret = wallet.decrypt_seed(wallet_password)?; - let master = DerivedKey::from_seed(secret.as_bytes()).map_err(|()| Error::EmptyPassword)?; + let master = DerivedKey::from_seed(secret.as_bytes()).map_err(Error::from)?; let destination = path.iter_nodes().fold(master, |dk, i| dk.child(*i)); @@ -311,7 +322,7 @@ pub fn recover_validator_secret_from_mnemonic( key_type: KeyType, ) -> Result<(PlainText, ValidatorPath), Error> { let path = ValidatorPath::new(index, key_type); - let master = DerivedKey::from_seed(secret).map_err(|()| Error::EmptyPassword)?; + let master = DerivedKey::from_seed(secret).map_err(Error::from)?; let destination = path.iter_nodes().fold(master, |dk, i| dk.child(*i)); diff --git a/lcli/src/generate_bootnode_enr.rs b/lcli/src/generate_bootnode_enr.rs index da79a1fa2..e2eace268 100644 --- a/lcli/src/generate_bootnode_enr.rs +++ b/lcli/src/generate_bootnode_enr.rs @@ -25,10 +25,12 @@ pub fn run(matches: &ArgMatches) -> Result<(), String> { )); } - let mut config = NetworkConfig::default(); - config.enr_address = Some(ip); - config.enr_udp_port = Some(udp_port); - config.enr_tcp_port = Some(tcp_port); + let config = NetworkConfig { + enr_address: Some(ip), + enr_udp_port: Some(udp_port), + enr_tcp_port: Some(tcp_port), + ..Default::default() + }; let local_keypair = Keypair::generate_secp256k1(); let enr_key = CombinedKey::from_libp2p(&local_keypair)?; diff --git a/slasher/src/test_utils.rs b/slasher/src/test_utils.rs index bd3b06c52..46ce23da5 100644 --- a/slasher/src/test_utils.rs +++ b/slasher/src/test_utils.rs @@ -1,7 +1,6 @@ use slog::Logger; use sloggers::Build; use std::collections::HashSet; -use std::iter::FromIterator; use types::{ AggregateSignature, AttestationData, AttesterSlashing, BeaconBlockHeader, Checkpoint, Epoch, Hash256, IndexedAttestation, MainnetEthSpec, Signature, SignedBeaconBlockHeader, Slot, @@ -59,8 +58,14 @@ pub fn hashset_intersection( attestation_1_indices: &[u64], attestation_2_indices: &[u64], ) -> HashSet { - &HashSet::from_iter(attestation_1_indices.iter().copied()) - & &HashSet::from_iter(attestation_2_indices.iter().copied()) + &attestation_1_indices + .iter() + .copied() + .collect::>() + & &attestation_2_indices + .iter() + .copied() + .collect::>() } pub fn slashed_validators_from_slashings(slashings: &HashSet>) -> HashSet { diff --git a/testing/remote_signer_test/src/utils.rs b/testing/remote_signer_test/src/utils.rs index 6b9586b36..858f4d602 100644 --- a/testing/remote_signer_test/src/utils.rs +++ b/testing/remote_signer_test/src/utils.rs @@ -102,11 +102,8 @@ pub fn get_block(seed: u64) -> BeaconBlock { signature: Signature::empty(), }; let indexed_attestation: IndexedAttestation = IndexedAttestation { - attesting_indices: VariableList::new(vec![ - 0 as u64; - E::MaxValidatorsPerCommittee::to_usize() - ]) - .unwrap(), + attesting_indices: VariableList::new(vec![0_u64; E::MaxValidatorsPerCommittee::to_usize()]) + .unwrap(), data: AttestationData::default(), signature: AggregateSignature::empty(), }; diff --git a/validator_client/slashing_protection/src/interchange.rs b/validator_client/slashing_protection/src/interchange.rs index 542807d0d..1a73f6d00 100644 --- a/validator_client/slashing_protection/src/interchange.rs +++ b/validator_client/slashing_protection/src/interchange.rs @@ -1,6 +1,5 @@ use serde_derive::{Deserialize, Serialize}; use std::collections::HashSet; -use std::iter::FromIterator; use types::{Epoch, Hash256, PublicKey, Slot}; #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] @@ -60,8 +59,8 @@ impl Interchange { /// Do these two `Interchange`s contain the same data (ignoring ordering)? pub fn equiv(&self, other: &Self) -> bool { - let self_set = HashSet::<_>::from_iter(self.data.iter()); - let other_set = HashSet::<_>::from_iter(other.data.iter()); + let self_set = self.data.iter().collect::>(); + let other_set = other.data.iter().collect::>(); self.metadata == other.metadata && self_set == other_set } diff --git a/validator_client/src/http_api/create_validator.rs b/validator_client/src/http_api/create_validator.rs index bc4f21561..2834a1839 100644 --- a/validator_client/src/http_api/create_validator.rs +++ b/validator_client/src/http_api/create_validator.rs @@ -43,8 +43,11 @@ pub async fn create_validators, T: 'static + SlotClock, E: EthSpe })?; if let Some(nextaccount) = key_derivation_path_offset { - wallet.set_nextaccount(nextaccount).map_err(|()| { - warp_utils::reject::custom_server_error("unable to set wallet nextaccount".to_string()) + wallet.set_nextaccount(nextaccount).map_err(|e| { + warp_utils::reject::custom_server_error(format!( + "unable to set wallet nextaccount: {:?}", + e + )) })?; }