From cb47388ad7221cb8efa5ba04685a938f021f18b9 Mon Sep 17 00:00:00 2001 From: ethDreamer Date: Mon, 10 May 2021 00:53:09 +0000 Subject: [PATCH] Updated to comply with new clippy formatting rules (#2336) ## Issue Addressed The latest version of Rust has new clippy rules & the codebase isn't up to date with them. ## Proposed Changes Small formatting changes that clippy tells me are functionally equivalent --- beacon_node/beacon_chain/src/builder.rs | 2 +- beacon_node/beacon_chain/src/eth1_chain.rs | 8 +++----- beacon_node/eth1/src/http.rs | 2 +- beacon_node/eth2_libp2p/src/discovery/enr_ext.rs | 2 +- beacon_node/eth2_libp2p/src/service.rs | 4 ++-- beacon_node/eth2_libp2p/src/types/topics.rs | 9 ++++++--- beacon_node/http_api/src/lib.rs | 6 +++--- .../network/src/beacon_processor/worker/rpc_methods.rs | 5 +---- consensus/types/src/slot_epoch_macros.rs | 6 ++---- slasher/src/slasher.rs | 4 ++-- testing/eth1_test_rig/src/ganache.rs | 2 +- testing/eth1_test_rig/src/lib.rs | 2 +- testing/state_transition_vectors/src/exit.rs | 2 +- validator_client/src/http_api/api_secret.rs | 2 +- 14 files changed, 26 insertions(+), 30 deletions(-) diff --git a/beacon_node/beacon_chain/src/builder.rs b/beacon_node/beacon_chain/src/builder.rs index f905ef0ae6..237e61414b 100644 --- a/beacon_node/beacon_chain/src/builder.rs +++ b/beacon_node/beacon_chain/src/builder.rs @@ -306,8 +306,8 @@ where })?; let genesis = BeaconSnapshot { - beacon_block_root, beacon_block, + beacon_block_root, beacon_state, }; diff --git a/beacon_node/beacon_chain/src/eth1_chain.rs b/beacon_node/beacon_chain/src/eth1_chain.rs index ed74ff6e41..c269b8c513 100644 --- a/beacon_node/beacon_chain/src/eth1_chain.rs +++ b/beacon_node/beacon_chain/src/eth1_chain.rs @@ -612,11 +612,9 @@ fn collect_valid_votes( .eth1_data_votes .iter() .filter_map(|vote| { - if let Some(block_num) = votes_to_consider.get(vote) { - Some((vote.clone(), *block_num)) - } else { - None - } + votes_to_consider + .get(vote) + .map(|block_num| (vote.clone(), *block_num)) }) .for_each(|(eth1_data, block_number)| { valid_votes diff --git a/beacon_node/eth1/src/http.rs b/beacon_node/eth1/src/http.rs index 547715a063..9ec7576d28 100644 --- a/beacon_node/eth1/src/http.rs +++ b/beacon_node/eth1/src/http.rs @@ -73,7 +73,7 @@ impl FromStr for Eth1Id { type Err = String; fn from_str(s: &str) -> Result { - u64::from_str_radix(s, 10) + s.parse::() .map(Into::into) .map_err(|e| format!("Failed to parse eth1 network id {}", e)) } diff --git a/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs b/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs index 30ace623ce..deb554c7f1 100644 --- a/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs +++ b/beacon_node/eth2_libp2p/src/discovery/enr_ext.rs @@ -299,7 +299,7 @@ mod tests { let sk_bytes = hex::decode(sk_hex).unwrap(); let secret = discv5::enr::ed25519_dalek::SecretKey::from_bytes(&sk_bytes).unwrap(); let public = discv5::enr::ed25519_dalek::PublicKey::from(&secret); - let keypair = discv5::enr::ed25519_dalek::Keypair { public, secret }; + let keypair = discv5::enr::ed25519_dalek::Keypair { secret, public }; let libp2p_sk = libp2p::identity::ed25519::SecretKey::from_bytes(sk_bytes).unwrap(); let ed25519_kp: libp2p::identity::ed25519::Keypair = libp2p_sk.into(); diff --git a/beacon_node/eth2_libp2p/src/service.rs b/beacon_node/eth2_libp2p/src/service.rs index 079338b54f..21c75836eb 100644 --- a/beacon_node/eth2_libp2p/src/service.rs +++ b/beacon_node/eth2_libp2p/src/service.rs @@ -233,9 +233,9 @@ impl Service { } let service = Service { - local_peer_id, - bandwidth, swarm, + bandwidth, + local_peer_id, log, }; diff --git a/beacon_node/eth2_libp2p/src/types/topics.rs b/beacon_node/eth2_libp2p/src/types/topics.rs index 18efde3452..f8e2b67688 100644 --- a/beacon_node/eth2_libp2p/src/types/topics.rs +++ b/beacon_node/eth2_libp2p/src/types/topics.rs @@ -81,8 +81,8 @@ impl GossipTopic { pub fn new(kind: GossipKind, encoding: GossipEncoding, fork_digest: [u8; 4]) -> Self { GossipTopic { encoding, - kind, fork_digest, + kind, } } @@ -135,8 +135,8 @@ impl GossipTopic { return Ok(GossipTopic { encoding, - kind, fork_digest, + kind, }); } @@ -195,7 +195,10 @@ pub fn subnet_id_from_topic_hash(topic_hash: &TopicHash) -> Option { fn committee_topic_index(topic: &str) -> Option { if topic.starts_with(BEACON_ATTESTATION_PREFIX) { return Some(SubnetId::new( - u64::from_str_radix(topic.trim_start_matches(BEACON_ATTESTATION_PREFIX), 10).ok()?, + topic + .trim_start_matches(BEACON_ATTESTATION_PREFIX) + .parse::() + .ok()?, )); } None diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 653820367c..325b289886 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -1355,7 +1355,7 @@ pub fn serve( let heads = chain .heads() .into_iter() - .map(|(root, slot)| api_types::ChainHeadData { root, slot }) + .map(|(root, slot)| api_types::ChainHeadData { slot, root }) .collect::>(); Ok(api_types::GenericResponse::from(heads)) }) @@ -1623,10 +1623,10 @@ pub fn serve( }); Ok(api_types::GenericResponse::from(api_types::PeerCount { - disconnecting, - connecting, connected, + connecting, disconnected, + disconnecting, })) }) }); diff --git a/beacon_node/network/src/beacon_processor/worker/rpc_methods.rs b/beacon_node/network/src/beacon_processor/worker/rpc_methods.rs index 71b9b11395..d25590f7c7 100644 --- a/beacon_node/network/src/beacon_processor/worker/rpc_methods.rs +++ b/beacon_node/network/src/beacon_processor/worker/rpc_methods.rs @@ -197,10 +197,7 @@ impl Worker { }; // remove all skip slots - let block_roots = block_roots - .into_iter() - .filter_map(|root| root) - .collect::>(); + let block_roots = block_roots.into_iter().flatten().collect::>(); let mut blocks_sent = 0; for root in block_roots { diff --git a/consensus/types/src/slot_epoch_macros.rs b/consensus/types/src/slot_epoch_macros.rs index caf31417d6..b8e6202fe3 100644 --- a/consensus/types/src/slot_epoch_macros.rs +++ b/consensus/types/src/slot_epoch_macros.rs @@ -572,10 +572,8 @@ macro_rules! math_tests { #[test] fn checked_div() { let assert_checked_div = |a: u64, b: u64, result: Option| { - let division_result_as_u64 = match $type(a).safe_div($type(b)).ok() { - None => None, - Some(val) => Some(val.as_u64()), - }; + let division_result_as_u64 = + $type(a).safe_div($type(b)).ok().map(|val| val.as_u64()); assert_eq!(division_result_as_u64, result); }; diff --git a/slasher/src/slasher.rs b/slasher/src/slasher.rs index fab807fcfe..91cf84fc30 100644 --- a/slasher/src/slasher.rs +++ b/slasher/src/slasher.rs @@ -38,10 +38,10 @@ impl Slasher { let block_queue = BlockQueue::default(); Ok(Self { db, - attester_slashings, - proposer_slashings, attestation_queue, block_queue, + attester_slashings, + proposer_slashings, config, log, }) diff --git a/testing/eth1_test_rig/src/ganache.rs b/testing/eth1_test_rig/src/ganache.rs index 7b62db30b9..a890f7c713 100644 --- a/testing/eth1_test_rig/src/ganache.rs +++ b/testing/eth1_test_rig/src/ganache.rs @@ -62,8 +62,8 @@ impl GanacheInstance { child.stdout = Some(reader.into_inner()); Ok(Self { - child, port, + child, web3, network_id, chain_id, diff --git a/testing/eth1_test_rig/src/lib.rs b/testing/eth1_test_rig/src/lib.rs index e222de05eb..716ccd3571 100644 --- a/testing/eth1_test_rig/src/lib.rs +++ b/testing/eth1_test_rig/src/lib.rs @@ -104,7 +104,7 @@ impl DepositContract { })?; Contract::from_json(web3.clone().eth(), address, ABI) .map_err(|e| format!("Failed to init contract: {:?}", e)) - .map(move |contract| Self { contract, web3 }) + .map(move |contract| Self { web3, contract }) } /// The deposit contract's address in `0x00ab...` format. diff --git a/testing/state_transition_vectors/src/exit.rs b/testing/state_transition_vectors/src/exit.rs index 10843f9d26..99b8122acc 100644 --- a/testing/state_transition_vectors/src/exit.rs +++ b/testing/state_transition_vectors/src/exit.rs @@ -83,8 +83,8 @@ impl ExitTest { TestVector { title, - block, pre_state, + block, post_state, error, } diff --git a/validator_client/src/http_api/api_secret.rs b/validator_client/src/http_api/api_secret.rs index 7f2a81d196..d3e5c2d125 100644 --- a/validator_client/src/http_api/api_secret.rs +++ b/validator_client/src/http_api/api_secret.rs @@ -133,7 +133,7 @@ impl ApiSecret { )); } - Ok(Self { sk, pk }) + Ok(Self { pk, sk }) } /// Returns the public key of `self` as a 0x-prefixed hex string.