diff --git a/.github/custom/config.toml b/.github/custom/config.toml new file mode 100644 index 000000000..283d6e207 --- /dev/null +++ b/.github/custom/config.toml @@ -0,0 +1,3 @@ +# Custom Cargo config to be used for the udeps CI job +[http] +multiplexing = false diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 5c46cee66..674a68a78 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -12,7 +12,7 @@ env: # Deny warnings in CI RUSTFLAGS: "-D warnings" # The Nightly version used for cargo-udeps, might need updating from time to time. - PINNED_NIGHTLY: nightly-2021-03-01 + PINNED_NIGHTLY: nightly-2021-06-09 jobs: target-branch-check: name: target-branch-check @@ -198,6 +198,10 @@ jobs: run: rustup toolchain install $PINNED_NIGHTLY - name: Install cargo-udeps run: cargo install cargo-udeps --locked + - name: Create Cargo config dir + run: mkdir -p .cargo + - name: Install custom Cargo config + run: cp -f .github/custom/config.toml .cargo/config.toml - name: Run cargo udeps to identify unused crates in the dependency graph run: make udeps env: diff --git a/account_manager/src/validator/create.rs b/account_manager/src/validator/create.rs index 5099c2de5..bbd2cbc99 100644 --- a/account_manager/src/validator/create.rs +++ b/account_manager/src/validator/create.rs @@ -236,7 +236,7 @@ pub fn cli_run( .map_err(|e| { format!( "Error registering validator {}: {:?}", - voting_pubkey.to_hex_string(), + voting_pubkey.as_hex_string(), e ) })?; @@ -250,7 +250,7 @@ pub fn cli_run( .build() .map_err(|e| format!("Unable to build validator directory: {:?}", e))?; - println!("{}/{}\t{}", i + 1, n, voting_pubkey.to_hex_string()); + println!("{}/{}\t{}", i + 1, n, voting_pubkey.as_hex_string()); } Ok(()) diff --git a/account_manager/src/validator/import.rs b/account_manager/src/validator/import.rs index 96da15403..6eb791113 100644 --- a/account_manager/src/validator/import.rs +++ b/account_manager/src/validator/import.rs @@ -242,7 +242,7 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin .map_err(|e| { format!( "Error registering validator {}: {:?}", - voting_pubkey.to_hex_string(), + voting_pubkey.as_hex_string(), e ) })?; diff --git a/beacon_node/beacon_chain/src/eth1_chain.rs b/beacon_node/beacon_chain/src/eth1_chain.rs index c269b8c51..f054796b7 100644 --- a/beacon_node/beacon_chain/src/eth1_chain.rs +++ b/beacon_node/beacon_chain/src/eth1_chain.rs @@ -762,8 +762,8 @@ mod test { let eth1_chain = get_eth1_chain(); - assert_eq!( - eth1_chain.use_dummy_backend, false, + assert!( + !eth1_chain.use_dummy_backend, "test should not use dummy backend" ); @@ -795,8 +795,8 @@ mod test { let eth1_chain = get_eth1_chain(); let max_deposits = ::MaxDeposits::to_u64(); - assert_eq!( - eth1_chain.use_dummy_backend, false, + assert!( + !eth1_chain.use_dummy_backend, "test should not use dummy backend" ); @@ -877,8 +877,8 @@ mod test { let eth1_chain = get_eth1_chain(); - assert_eq!( - eth1_chain.use_dummy_backend, false, + assert!( + !eth1_chain.use_dummy_backend, "test should not use dummy backend" ); @@ -901,8 +901,8 @@ mod test { let eth1_chain = get_eth1_chain(); - assert_eq!( - eth1_chain.use_dummy_backend, false, + assert!( + !eth1_chain.use_dummy_backend, "test should not use dummy backend" ); diff --git a/beacon_node/beacon_chain/src/state_advance_timer.rs b/beacon_node/beacon_chain/src/state_advance_timer.rs index fe6e05a8b..d8603570b 100644 --- a/beacon_node/beacon_chain/src/state_advance_timer.rs +++ b/beacon_node/beacon_chain/src/state_advance_timer.rs @@ -353,11 +353,11 @@ mod tests { #[test] fn lock() { let lock = Lock::new(); - assert_eq!(lock.lock(), false); - assert_eq!(lock.lock(), true); - assert_eq!(lock.lock(), true); + assert!(!lock.lock()); + assert!(lock.lock()); + assert!(lock.lock()); lock.unlock(); - assert_eq!(lock.lock(), false); - assert_eq!(lock.lock(), true); + assert!(!lock.lock()); + assert!(lock.lock()); } } diff --git a/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs b/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs index deb554c7f..a6f718abb 100644 --- a/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs +++ b/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs @@ -88,14 +88,14 @@ impl EnrExt for Enr { if let Some(udp) = self.udp() { let mut multiaddr: Multiaddr = ip.into(); multiaddr.push(Protocol::Udp(udp)); - multiaddr.push(Protocol::P2p(peer_id.clone().into())); + multiaddr.push(Protocol::P2p(peer_id.into())); multiaddrs.push(multiaddr); } if let Some(tcp) = self.tcp() { let mut multiaddr: Multiaddr = ip.into(); multiaddr.push(Protocol::Tcp(tcp)); - multiaddr.push(Protocol::P2p(peer_id.clone().into())); + multiaddr.push(Protocol::P2p(peer_id.into())); multiaddrs.push(multiaddr); } } @@ -103,7 +103,7 @@ impl EnrExt for Enr { if let Some(udp6) = self.udp6() { let mut multiaddr: Multiaddr = ip6.into(); multiaddr.push(Protocol::Udp(udp6)); - multiaddr.push(Protocol::P2p(peer_id.clone().into())); + multiaddr.push(Protocol::P2p(peer_id.into())); multiaddrs.push(multiaddr); } @@ -128,7 +128,7 @@ impl EnrExt for Enr { if let Some(tcp) = self.tcp() { let mut multiaddr: Multiaddr = ip.into(); multiaddr.push(Protocol::Tcp(tcp)); - multiaddr.push(Protocol::P2p(peer_id.clone().into())); + multiaddr.push(Protocol::P2p(peer_id.into())); multiaddrs.push(multiaddr); } } @@ -154,7 +154,7 @@ impl EnrExt for Enr { if let Some(udp) = self.udp() { let mut multiaddr: Multiaddr = ip.into(); multiaddr.push(Protocol::Udp(udp)); - multiaddr.push(Protocol::P2p(peer_id.clone().into())); + multiaddr.push(Protocol::P2p(peer_id.into())); multiaddrs.push(multiaddr); } } diff --git a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs index d2763669e..5f87015a0 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs @@ -556,20 +556,18 @@ impl PeerManager { if known_meta_data.seq_number < meta_data.seq_number { debug!(self.log, "Updating peer's metadata"; "peer_id" => %peer_id, "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number); - peer_info.meta_data = Some(meta_data); } else { debug!(self.log, "Received old metadata"; "peer_id" => %peer_id, "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number); // Updating metadata even in this case to prevent storing // incorrect `metadata.attnets` for a peer - peer_info.meta_data = Some(meta_data); } } else { // we have no meta-data for this peer, update debug!(self.log, "Obtained peer's metadata"; "peer_id" => %peer_id, "new_seq_no" => meta_data.seq_number); - peer_info.meta_data = Some(meta_data); } + peer_info.meta_data = Some(meta_data); } else { crit!(self.log, "Received METADATA from an unknown peer"; "peer_id" => %peer_id); @@ -583,11 +581,7 @@ impl PeerManager { // port is removed, which is assumed to be associated with the discv5 protocol (and // therefore irrelevant for other libp2p components). let mut out_list = enr.multiaddr(); - out_list.retain(|addr| { - addr.iter() - .find(|v| matches!(v, MProtocol::Udp(_))) - .is_none() - }); + out_list.retain(|addr| !addr.iter().any(|v| matches!(v, MProtocol::Udp(_)))); out_list } else { 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 d282c03f0..1aab570d3 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 @@ -62,14 +62,14 @@ impl PeerSyncStatus { matches!(self, PeerSyncStatus::Behind { .. }) } + /// Updates the peer's sync status, returning whether the status transitioned. + /// + /// E.g. returns `true` if the state changed from `Synced` to `Advanced`, but not if + /// the status remained `Synced` with different `SyncInfo` within. pub fn update(&mut self, new_state: PeerSyncStatus) -> bool { - if *self == new_state { - *self = new_state; - false // state was not updated - } else { - *self = new_state; - true - } + let changed_status = *self != new_state; + *self = new_state; + changed_status } pub fn as_str(&self) -> &'static str { diff --git a/beacon_node/eth2_libp2p/src/rpc/handler.rs b/beacon_node/eth2_libp2p/src/rpc/handler.rs index 4761d8599..55b401822 100644 --- a/beacon_node/eth2_libp2p/src/rpc/handler.rs +++ b/beacon_node/eth2_libp2p/src/rpc/handler.rs @@ -587,7 +587,7 @@ where match std::mem::replace(&mut info.state, InboundState::Poisoned) { InboundState::Idle(substream) if !deactivated => { if !info.pending_items.is_empty() { - let to_send = std::mem::replace(&mut info.pending_items, vec![]); + let to_send = std::mem::take(&mut info.pending_items); let fut = process_inbound_substream( substream, info.remaining_chunks, @@ -665,8 +665,7 @@ where // elements if !deactivated && !info.pending_items.is_empty() { - let to_send = - std::mem::replace(&mut info.pending_items, vec![]); + let to_send = std::mem::take(&mut info.pending_items); let fut = process_inbound_substream( substream, info.remaining_chunks, diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 74789496c..d6b805107 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -1254,7 +1254,6 @@ pub fn serve( // GET config/fork_schedule let get_config_fork_schedule = config_path - .clone() .and(warp::path("fork_schedule")) .and(warp::path::end()) .and(chain_filter.clone()) @@ -1268,7 +1267,6 @@ pub fn serve( // GET config/spec let get_config_spec = config_path - .clone() .and(warp::path("spec")) .and(warp::path::end()) .and(chain_filter.clone()) @@ -1284,7 +1282,6 @@ pub fn serve( // GET config/deposit_contract let get_config_deposit_contract = config_path - .clone() .and(warp::path("deposit_contract")) .and(warp::path::end()) .and(chain_filter.clone()) diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 22c4a88a9..fb9e74cec 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -1,4 +1,5 @@ #![cfg(not(debug_assertions))] // Tests are too slow in debug. +#![recursion_limit = "256"] use beacon_chain::{ test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType}, @@ -2333,7 +2334,7 @@ async fn poll_events, eth2::Error>> + Unpin }; tokio::select! { - _ = collect_stream_fut => {return events} + _ = collect_stream_fut => {events} _ = tokio::time::sleep(timeout) => { return events; } } } diff --git a/beacon_node/network/src/attestation_service/mod.rs b/beacon_node/network/src/attestation_service/mod.rs index b560e4e3f..09c0ff895 100644 --- a/beacon_node/network/src/attestation_service/mod.rs +++ b/beacon_node/network/src/attestation_service/mod.rs @@ -559,11 +559,10 @@ impl AttestationService { return; } // If there are no unsubscription events for `subnet_id`, we unsubscribe immediately. - if self + if !self .unsubscriptions .keys() - .find(|s| s.subnet_id == subnet_id) - .is_none() + .any(|s| s.subnet_id == subnet_id) { // we are not at capacity, unsubscribe from the current subnet. debug!(self.log, "Unsubscribing from random subnet"; "subnet_id" => *subnet_id); @@ -601,11 +600,10 @@ impl AttestationService { for subnet_id in to_remove_subnets { // If there are no unsubscription events for `subnet_id`, we unsubscribe immediately. - if self + if !self .unsubscriptions .keys() - .find(|s| s.subnet_id == *subnet_id) - .is_none() + .any(|s| s.subnet_id == *subnet_id) { self.events .push_back(AttServiceMessage::Unsubscribe(*subnet_id)); diff --git a/beacon_node/network/src/attestation_service/tests/mod.rs b/beacon_node/network/src/attestation_service/tests/mod.rs index de094e15f..55811a191 100644 --- a/beacon_node/network/src/attestation_service/tests/mod.rs +++ b/beacon_node/network/src/attestation_service/tests/mod.rs @@ -147,10 +147,10 @@ async fn get_events + Unpin>( }; tokio::select! { - _ = collect_stream_fut => {return events} + _ = collect_stream_fut => {events} _ = tokio::time::sleep( Duration::from_millis(SLOT_DURATION_MILLIS) * num_slots_before_timeout, - ) => { return events; } + ) => { events } } } diff --git a/beacon_node/network/src/nat.rs b/beacon_node/network/src/nat.rs index 4067fd2bc..a2fbe5761 100644 --- a/beacon_node/network/src/nat.rs +++ b/beacon_node/network/src/nat.rs @@ -83,7 +83,7 @@ pub fn construct_upnp_mappings( "tcp", &log, ).and_then(|_| { - let external_socket = external_ip.as_ref().map(|ip| SocketAddr::new(ip.clone().into(), config.tcp_port)).map_err(|_| ()); + let external_socket = external_ip.as_ref().map(|ip| SocketAddr::new((*ip).into(), config.tcp_port)).map_err(|_| ()); info!(log, "UPnP TCP route established"; "external_socket" => format!("{}:{}", external_socket.as_ref().map(|ip| ip.to_string()).unwrap_or_else(|_| "".into()), config.tcp_port)); external_socket }).ok(); diff --git a/beacon_node/network/src/sync/range_sync/chain.rs b/beacon_node/network/src/sync/range_sync/chain.rs index e28f01881..87c2f2762 100644 --- a/beacon_node/network/src/sync/range_sync/chain.rs +++ b/beacon_node/network/src/sync/range_sync/chain.rs @@ -933,10 +933,10 @@ impl SyncingChain { // check if we have the batch for our optimistic start. If not, request it first. // We wait for this batch before requesting any other batches. if let Some(epoch) = self.optimistic_start { - if !self.batches.contains_key(&epoch) { + if let Entry::Vacant(entry) = self.batches.entry(epoch) { if let Some(peer) = idle_peers.pop() { let optimistic_batch = BatchInfo::new(&epoch, EPOCHS_PER_BATCH); - self.batches.insert(epoch, optimistic_batch); + entry.insert(optimistic_batch); self.send_batch(network, epoch, peer)?; } } diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index 02a88b331..97c954c99 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -285,12 +285,11 @@ impl, Cold: ItemStore> HotColdDB /// Store a state in the store. pub fn put_state(&self, state_root: &Hash256, state: &BeaconState) -> Result<(), Error> { + let mut ops: Vec = Vec::new(); if state.slot < self.get_split_slot() { - let mut ops: Vec = Vec::new(); self.store_cold_state(state_root, &state, &mut ops)?; self.cold_db.do_atomically(ops) } else { - let mut ops: Vec = Vec::new(); self.store_hot_state(state_root, state, &mut ops)?; self.hot_db.do_atomically(ops) } diff --git a/beacon_node/store/src/lib.rs b/beacon_node/store/src/lib.rs index a9e3fc69d..045b87eba 100644 --- a/beacon_node/store/src/lib.rs +++ b/beacon_node/store/src/lib.rs @@ -251,18 +251,18 @@ mod tests { let key = Hash256::random(); let item = StorableThing { a: 1, b: 42 }; - assert_eq!(store.exists::(&key).unwrap(), false); + assert!(!store.exists::(&key).unwrap()); store.put(&key, &item).unwrap(); - assert_eq!(store.exists::(&key).unwrap(), true); + assert!(store.exists::(&key).unwrap()); let retrieved = store.get(&key).unwrap().unwrap(); assert_eq!(item, retrieved); store.delete::(&key).unwrap(); - assert_eq!(store.exists::(&key).unwrap(), false); + assert!(!store.exists::(&key).unwrap()); assert_eq!(store.get::(&key).unwrap(), None); } @@ -289,14 +289,14 @@ mod tests { let key = Hash256::random(); let item = StorableThing { a: 1, b: 42 }; - assert_eq!(store.exists::(&key).unwrap(), false); + assert!(!store.exists::(&key).unwrap()); store.put(&key, &item).unwrap(); - assert_eq!(store.exists::(&key).unwrap(), true); + assert!(store.exists::(&key).unwrap()); store.delete::(&key).unwrap(); - assert_eq!(store.exists::(&key).unwrap(), false); + assert!(!store.exists::(&key).unwrap()); } } diff --git a/beacon_node/tests/test.rs b/beacon_node/tests/test.rs index 0d5c6c9fb..516f05bfb 100644 --- a/beacon_node/tests/test.rs +++ b/beacon_node/tests/test.rs @@ -1,4 +1,5 @@ #![cfg(test)] +#![recursion_limit = "256"] use beacon_chain::StateSkipConfig; use node_test_rig::{ diff --git a/common/validator_dir/src/builder.rs b/common/validator_dir/src/builder.rs index d284e2d67..bfdf35ff3 100644 --- a/common/validator_dir/src/builder.rs +++ b/common/validator_dir/src/builder.rs @@ -231,7 +231,7 @@ impl<'a> Builder<'a> { if self.store_withdrawal_keystore { // Write the withdrawal password to file. write_password_to_file( - password_dir.join(withdrawal_keypair.pk.to_hex_string()), + password_dir.join(withdrawal_keypair.pk.as_hex_string()), withdrawal_password.as_bytes(), )?; diff --git a/consensus/cached_tree_hash/src/cache_arena.rs b/consensus/cached_tree_hash/src/cache_arena.rs index 44ba89927..daaef266b 100644 --- a/consensus/cached_tree_hash/src/cache_arena.rs +++ b/consensus/cached_tree_hash/src/cache_arena.rs @@ -294,9 +294,8 @@ mod tests { "after first push sub should have len {}", len ); - assert_eq!( - sub.is_empty(arena).expect("should exist"), - false, + assert!( + !sub.is_empty(arena).expect("should exist"), "new sub should not be empty" ); @@ -375,9 +374,8 @@ mod tests { 0, "new sub should have len 0" ); - assert_eq!( + assert!( sub.is_empty(arena).expect("should exist"), - true, "new sub should be empty" ); @@ -397,9 +395,8 @@ mod tests { 0, "new sub should have len 0" ); - assert_eq!( + assert!( sub_01.is_empty(arena).expect("should exist"), - true, "new sub should be empty" ); @@ -409,9 +406,8 @@ mod tests { 0, "new sub should have len 0" ); - assert_eq!( + assert!( sub_02.is_empty(arena).expect("should exist"), - true, "new sub should be empty" ); @@ -432,9 +428,8 @@ mod tests { 0, "new sub should have len 0" ); - assert_eq!( + assert!( sub_01.is_empty(arena).expect("should exist"), - true, "new sub should be empty" ); @@ -446,9 +441,8 @@ mod tests { 0, "new sub should have len 0" ); - assert_eq!( + assert!( sub_02.is_empty(arena).expect("should exist"), - true, "new sub should be empty" ); @@ -474,9 +468,8 @@ mod tests { 0, "new sub should have len 0" ); - assert_eq!( + assert!( sub.is_empty(arena).expect("should exist"), - true, "new sub should be empty" ); subs.push(sub); @@ -492,9 +485,8 @@ mod tests { 0, "new sub should have len 0" ); - assert_eq!( + assert!( sub.is_empty(arena).expect("should exist"), - true, "new sub should be empty" ); subs.push(sub); diff --git a/consensus/types/src/beacon_state/committee_cache/tests.rs b/consensus/types/src/beacon_state/committee_cache/tests.rs index e1256cb48..94e6c2c84 100644 --- a/consensus/types/src/beacon_state/committee_cache/tests.rs +++ b/consensus/types/src/beacon_state/committee_cache/tests.rs @@ -6,7 +6,7 @@ use crate::{test_utils::*, *}; fn default_values() { let cache = CommitteeCache::default(); - assert_eq!(cache.is_initialized_at(Epoch::new(0)), false); + assert!(!cache.is_initialized_at(Epoch::new(0))); assert!(&cache.active_validator_indices().is_empty()); assert_eq!(cache.get_beacon_committee(Slot::new(0), 0), None); assert_eq!(cache.get_attestation_duties(0), None); diff --git a/consensus/types/src/indexed_attestation.rs b/consensus/types/src/indexed_attestation.rs index ed6ae212c..a1976853b 100644 --- a/consensus/types/src/indexed_attestation.rs +++ b/consensus/types/src/indexed_attestation.rs @@ -105,10 +105,7 @@ mod tests { let indexed_vote_first = create_indexed_attestation(3, 1); let indexed_vote_second = create_indexed_attestation(3, 2); - assert_eq!( - indexed_vote_first.is_double_vote(&indexed_vote_second), - true - ) + assert!(indexed_vote_first.is_double_vote(&indexed_vote_second)) } #[test] @@ -116,10 +113,7 @@ mod tests { let indexed_vote_first = create_indexed_attestation(1, 1); let indexed_vote_second = create_indexed_attestation(2, 1); - assert_eq!( - indexed_vote_first.is_double_vote(&indexed_vote_second), - false - ); + assert!(!indexed_vote_first.is_double_vote(&indexed_vote_second)); } #[test] @@ -127,10 +121,7 @@ mod tests { let indexed_vote_first = create_indexed_attestation(2, 1); let indexed_vote_second = create_indexed_attestation(1, 2); - assert_eq!( - indexed_vote_first.is_surround_vote(&indexed_vote_second), - true - ); + assert!(indexed_vote_first.is_surround_vote(&indexed_vote_second)); } #[test] @@ -138,10 +129,7 @@ mod tests { let indexed_vote_first = create_indexed_attestation(4, 1); let indexed_vote_second = create_indexed_attestation(3, 2); - assert_eq!( - indexed_vote_first.is_surround_vote(&indexed_vote_second), - true - ); + assert!(indexed_vote_first.is_surround_vote(&indexed_vote_second)); } #[test] @@ -149,10 +137,7 @@ mod tests { let indexed_vote_first = create_indexed_attestation(2, 2); let indexed_vote_second = create_indexed_attestation(1, 1); - assert_eq!( - indexed_vote_first.is_surround_vote(&indexed_vote_second), - false - ); + assert!(!indexed_vote_first.is_surround_vote(&indexed_vote_second)); } #[test] @@ -160,10 +145,7 @@ mod tests { let indexed_vote_first = create_indexed_attestation(1, 1); let indexed_vote_second = create_indexed_attestation(2, 2); - assert_eq!( - indexed_vote_first.is_surround_vote(&indexed_vote_second), - false - ); + assert!(!indexed_vote_first.is_surround_vote(&indexed_vote_second)); } ssz_and_tree_hash_tests!(IndexedAttestation); diff --git a/consensus/types/src/validator.rs b/consensus/types/src/validator.rs index e80fb8522..87ffa8ada 100644 --- a/consensus/types/src/validator.rs +++ b/consensus/types/src/validator.rs @@ -93,10 +93,10 @@ mod tests { let epoch = Epoch::new(0); - assert_eq!(v.is_active_at(epoch), false); - assert_eq!(v.is_exited_at(epoch), false); - assert_eq!(v.is_withdrawable_at(epoch), false); - assert_eq!(v.slashed, false); + assert!(!v.is_active_at(epoch)); + assert!(!v.is_exited_at(epoch)); + assert!(!v.is_withdrawable_at(epoch)); + assert!(!v.slashed); } #[test] @@ -108,9 +108,9 @@ mod tests { ..Validator::default() }; - assert_eq!(v.is_active_at(epoch - 1), false); - assert_eq!(v.is_active_at(epoch), true); - assert_eq!(v.is_active_at(epoch + 1), true); + assert!(!v.is_active_at(epoch - 1)); + assert!(v.is_active_at(epoch)); + assert!(v.is_active_at(epoch + 1)); } #[test] @@ -122,9 +122,9 @@ mod tests { ..Validator::default() }; - assert_eq!(v.is_exited_at(epoch - 1), false); - assert_eq!(v.is_exited_at(epoch), true); - assert_eq!(v.is_exited_at(epoch + 1), true); + assert!(!v.is_exited_at(epoch - 1)); + assert!(v.is_exited_at(epoch)); + assert!(v.is_exited_at(epoch + 1)); } #[test] @@ -136,9 +136,9 @@ mod tests { ..Validator::default() }; - assert_eq!(v.is_withdrawable_at(epoch - 1), false); - assert_eq!(v.is_withdrawable_at(epoch), true); - assert_eq!(v.is_withdrawable_at(epoch + 1), true); + assert!(!v.is_withdrawable_at(epoch - 1)); + assert!(v.is_withdrawable_at(epoch)); + assert!(v.is_withdrawable_at(epoch + 1)); } ssz_and_tree_hash_tests!(Validator); diff --git a/crypto/bls/src/generic_public_key.rs b/crypto/bls/src/generic_public_key.rs index 2e4833b4e..face79a4b 100644 --- a/crypto/bls/src/generic_public_key.rs +++ b/crypto/bls/src/generic_public_key.rs @@ -51,7 +51,7 @@ where } /// Returns `self.serialize()` as a `0x`-prefixed hex string. - pub fn to_hex_string(&self) -> String { + pub fn as_hex_string(&self) -> String { format!("{:?}", self) } diff --git a/crypto/bls/src/generic_public_key_bytes.rs b/crypto/bls/src/generic_public_key_bytes.rs index d341e907a..a60065bbc 100644 --- a/crypto/bls/src/generic_public_key_bytes.rs +++ b/crypto/bls/src/generic_public_key_bytes.rs @@ -70,7 +70,7 @@ impl GenericPublicKeyBytes { } /// Returns `self.serialize()` as a `0x`-prefixed hex string. - pub fn to_hex_string(&self) -> String { + pub fn as_hex_string(&self) -> String { format!("{:?}", self) } diff --git a/crypto/eth2_keystore/src/keystore.rs b/crypto/eth2_keystore/src/keystore.rs index 1ed9fbbf4..d36fd3a5f 100644 --- a/crypto/eth2_keystore/src/keystore.rs +++ b/crypto/eth2_keystore/src/keystore.rs @@ -230,7 +230,7 @@ impl Keystore { }, uuid, path: Some(path), - pubkey: keypair.pk.to_hex_string()[2..].to_string(), + pubkey: keypair.pk.as_hex_string()[2..].to_string(), version: Version::four(), description: Some(description), name: None, @@ -261,7 +261,7 @@ impl Keystore { let keypair = keypair_from_secret(plain_text.as_bytes())?; // Verify that the derived `PublicKey` matches `self`. - if keypair.pk.to_hex_string()[2..] != self.json.pubkey { + if keypair.pk.as_hex_string()[2..] != self.json.pubkey { return Err(Error::PublicKeyMismatch); } diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 7c4effe83..e49e29f3f 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -1,3 +1,5 @@ +#![recursion_limit = "256"] + mod metrics; use beacon_node::{get_eth2_network_config, ProductionBeaconNode}; diff --git a/slasher/src/block_queue.rs b/slasher/src/block_queue.rs index 10086ce37..3d2472c18 100644 --- a/slasher/src/block_queue.rs +++ b/slasher/src/block_queue.rs @@ -13,7 +13,7 @@ impl BlockQueue { pub fn dequeue(&self) -> Vec { let mut blocks = self.blocks.lock(); - std::mem::replace(&mut *blocks, vec![]) + std::mem::take(&mut *blocks) } pub fn len(&self) -> usize { diff --git a/testing/simulator/src/main.rs b/testing/simulator/src/main.rs index 742f11087..4fb9a235b 100644 --- a/testing/simulator/src/main.rs +++ b/testing/simulator/src/main.rs @@ -1,3 +1,5 @@ +#![recursion_limit = "256"] + //! This crate provides a simluation that creates `n` beacon node and validator clients, each with //! `v` validators. A deposit contract is deployed at the start of the simulation using a local //! `ganache-cli` instance (you must have `ganache-cli` installed and avaliable on your path). All diff --git a/validator_client/slashing_protection/src/slashing_database.rs b/validator_client/slashing_protection/src/slashing_database.rs index 23de7d300..1ade97fc7 100644 --- a/validator_client/slashing_protection/src/slashing_database.rs +++ b/validator_client/slashing_protection/src/slashing_database.rs @@ -160,7 +160,7 @@ impl SlashingDatabase { let mut stmt = txn.prepare("INSERT INTO validators (public_key) VALUES (?1)")?; for pubkey in public_keys { if self.get_validator_id_opt(&txn, pubkey)?.is_none() { - stmt.execute(&[pubkey.to_hex_string()])?; + stmt.execute(&[pubkey.as_hex_string()])?; } } Ok(()) @@ -205,7 +205,7 @@ impl SlashingDatabase { Ok(txn .query_row( "SELECT id FROM validators WHERE public_key = ?1", - params![&public_key.to_hex_string()], + params![&public_key.as_hex_string()], |row| row.get(0), ) .optional()?) @@ -990,11 +990,9 @@ mod tests { assert_eq!(db.conn_pool.max_size(), POOL_SIZE); assert_eq!(db.conn_pool.connection_timeout(), CONNECTION_TIMEOUT); let conn = db.conn_pool.get().unwrap(); - assert_eq!( - conn.pragma_query_value(None, "foreign_keys", |row| { row.get::<_, bool>(0) }) - .unwrap(), - true - ); + assert!(conn + .pragma_query_value(None, "foreign_keys", |row| { row.get::<_, bool>(0) }) + .unwrap()); assert_eq!( conn.pragma_query_value(None, "locking_mode", |row| { row.get::<_, String>(0) }) .unwrap() diff --git a/validator_client/src/graffiti_file.rs b/validator_client/src/graffiti_file.rs index ecb294f0f..0df2cdb10 100644 --- a/validator_client/src/graffiti_file.rs +++ b/validator_client/src/graffiti_file.rs @@ -129,13 +129,13 @@ mod tests { .write_all(format!("default: {}\n", DEFAULT_GRAFFITI).as_bytes()) .unwrap(); graffiti_file - .write_all(format!("{}: {}\n", pk1.to_hex_string(), CUSTOM_GRAFFITI1).as_bytes()) + .write_all(format!("{}: {}\n", pk1.as_hex_string(), CUSTOM_GRAFFITI1).as_bytes()) .unwrap(); graffiti_file - .write_all(format!("{}: {}\n", pk2.to_hex_string(), CUSTOM_GRAFFITI2).as_bytes()) + .write_all(format!("{}: {}\n", pk2.as_hex_string(), CUSTOM_GRAFFITI2).as_bytes()) .unwrap(); graffiti_file - .write_all(format!("{}:{}\n", pk3.to_hex_string(), EMPTY_GRAFFITI).as_bytes()) + .write_all(format!("{}:{}\n", pk3.as_hex_string(), EMPTY_GRAFFITI).as_bytes()) .unwrap(); graffiti_file.flush().unwrap(); file_name