From 4ad7e157329f9a8fa0825c51962673b6a582d90e Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 6 Oct 2023 17:53:57 +1100 Subject: [PATCH] Address Clippy 1.73 lints on Deneb branch (#4810) * Address Clippy 1.73 lints (#4809) ## Proposed Changes Fix Clippy lints enabled by default in Rust 1.73.0, released today. * Address Clippy 1.73 lints. --------- Co-authored-by: Michael Sproul --- .../beacon_chain/src/blob_verification.rs | 2 +- .../src/eth1_finalization_cache.rs | 2 +- .../beacon_chain/src/historical_blocks.rs | 25 ++++++++----------- .../test_utils/execution_block_generator.rs | 2 +- .../http_api/src/standard_block_rewards.rs | 4 +-- .../src/peer_manager/mod.rs | 2 +- .../src/peer_manager/peerdb/score.rs | 6 +++-- .../operation_pool/src/attestation_storage.rs | 10 ++------ beacon_node/store/src/memory_store.rs | 2 +- consensus/types/src/blob_sidecar.rs | 4 +-- validator_client/src/attestation_service.rs | 2 +- validator_client/src/duties_service/sync.rs | 2 +- 12 files changed, 28 insertions(+), 35 deletions(-) diff --git a/beacon_node/beacon_chain/src/blob_verification.rs b/beacon_node/beacon_chain/src/blob_verification.rs index d4264266e..b78859e10 100644 --- a/beacon_node/beacon_chain/src/blob_verification.rs +++ b/beacon_node/beacon_chain/src/blob_verification.rs @@ -451,7 +451,7 @@ pub struct KzgVerifiedBlob { impl PartialOrd for KzgVerifiedBlob { fn partial_cmp(&self, other: &Self) -> Option { - self.blob.partial_cmp(&other.blob) + Some(self.cmp(other)) } } diff --git a/beacon_node/beacon_chain/src/eth1_finalization_cache.rs b/beacon_node/beacon_chain/src/eth1_finalization_cache.rs index 17ac4e5b3..24b6542ea 100644 --- a/beacon_node/beacon_chain/src/eth1_finalization_cache.rs +++ b/beacon_node/beacon_chain/src/eth1_finalization_cache.rs @@ -67,7 +67,7 @@ impl CheckpointMap { pub fn insert(&mut self, checkpoint: Checkpoint, eth1_finalization_data: Eth1FinalizationData) { self.store .entry(checkpoint.epoch) - .or_insert_with(Vec::new) + .or_default() .push((checkpoint.root, eth1_finalization_data)); // faster to reduce size after the fact than do pre-checking to see diff --git a/beacon_node/beacon_chain/src/historical_blocks.rs b/beacon_node/beacon_chain/src/historical_blocks.rs index 8f02355e9..acf2ccc82 100644 --- a/beacon_node/beacon_chain/src/historical_blocks.rs +++ b/beacon_node/beacon_chain/src/historical_blocks.rs @@ -172,20 +172,17 @@ impl BeaconChain { let signature_set = signed_blocks .iter() .zip_eq(block_roots) - .filter_map(|(block, block_root)| { - (block_root != self.genesis_block_root).then(|| { - block_proposal_signature_set_from_parts( - block, - Some(block_root), - block.message().proposer_index(), - &self.spec.fork_at_epoch(block.message().epoch()), - self.genesis_validators_root, - |validator_index| { - pubkey_cache.get(validator_index).cloned().map(Cow::Owned) - }, - &self.spec, - ) - }) + .filter(|&(_block, block_root)| (block_root != self.genesis_block_root)) + .map(|(block, block_root)| { + block_proposal_signature_set_from_parts( + block, + Some(block_root), + block.message().proposer_index(), + &self.spec.fork_at_epoch(block.message().epoch()), + self.genesis_validators_root, + |validator_index| pubkey_cache.get(validator_index).cloned().map(Cow::Owned), + &self.spec, + ) }) .collect::, _>>() .map_err(HistoricalBlockError::SignatureSet) diff --git a/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs b/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs index baef27862..c191fb2a0 100644 --- a/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs +++ b/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs @@ -371,7 +371,7 @@ impl ExecutionBlockGenerator { let block_hash = block.block_hash(); self.block_hashes .entry(block.block_number()) - .or_insert_with(Vec::new) + .or_default() .push(block_hash); self.blocks.insert(block_hash, block); diff --git a/beacon_node/http_api/src/standard_block_rewards.rs b/beacon_node/http_api/src/standard_block_rewards.rs index de7e5eb7d..97e5a87fd 100644 --- a/beacon_node/http_api/src/standard_block_rewards.rs +++ b/beacon_node/http_api/src/standard_block_rewards.rs @@ -5,8 +5,8 @@ use beacon_chain::{BeaconChain, BeaconChainTypes}; use eth2::lighthouse::StandardBlockReward; use std::sync::Arc; use warp_utils::reject::beacon_chain_error; -//// The difference between block_rewards and beacon_block_rewards is the later returns block -//// reward format that satisfies beacon-api specs +/// The difference between block_rewards and beacon_block_rewards is the later returns block +/// reward format that satisfies beacon-api specs pub fn compute_beacon_block_rewards( chain: Arc>, block_id: BlockId, diff --git a/beacon_node/lighthouse_network/src/peer_manager/mod.rs b/beacon_node/lighthouse_network/src/peer_manager/mod.rs index 93e0f77f8..3459548ec 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/mod.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/mod.rs @@ -1055,7 +1055,7 @@ impl PeerManager { Subnet::Attestation(_) => { subnet_to_peer .entry(subnet) - .or_insert_with(Vec::new) + .or_default() .push((*peer_id, info.clone())); } Subnet::SyncCommittee(id) => { diff --git a/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs b/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs index bafa355d6..877d72581 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs @@ -330,13 +330,15 @@ impl Eq for Score {} impl PartialOrd for Score { fn partial_cmp(&self, other: &Score) -> Option { - self.score().partial_cmp(&other.score()) + Some(self.cmp(other)) } } impl Ord for Score { fn cmp(&self, other: &Score) -> std::cmp::Ordering { - self.partial_cmp(other).unwrap_or(std::cmp::Ordering::Equal) + self.score() + .partial_cmp(&other.score()) + .unwrap_or(std::cmp::Ordering::Equal) } } diff --git a/beacon_node/operation_pool/src/attestation_storage.rs b/beacon_node/operation_pool/src/attestation_storage.rs index 0fb9bafd8..dac5e25b3 100644 --- a/beacon_node/operation_pool/src/attestation_storage.rs +++ b/beacon_node/operation_pool/src/attestation_storage.rs @@ -151,14 +151,8 @@ impl AttestationMap { indexed, } = SplitAttestation::new(attestation, attesting_indices); - let attestation_map = self - .checkpoint_map - .entry(checkpoint) - .or_insert_with(AttestationDataMap::default); - let attestations = attestation_map - .attestations - .entry(data) - .or_insert_with(Vec::new); + let attestation_map = self.checkpoint_map.entry(checkpoint).or_default(); + let attestations = attestation_map.attestations.entry(data).or_default(); // Greedily aggregate the attestation with all existing attestations. // NOTE: this is sub-optimal and in future we will remove this in favour of max-clique diff --git a/beacon_node/store/src/memory_store.rs b/beacon_node/store/src/memory_store.rs index 1473f59a4..3f6a9e514 100644 --- a/beacon_node/store/src/memory_store.rs +++ b/beacon_node/store/src/memory_store.rs @@ -48,7 +48,7 @@ impl KeyValueStore for MemoryStore { self.col_keys .write() .entry(col.as_bytes().to_vec()) - .or_insert_with(HashSet::new) + .or_default() .insert(key.to_vec()); Ok(()) } diff --git a/consensus/types/src/blob_sidecar.rs b/consensus/types/src/blob_sidecar.rs index e82aab23c..e4da89ca2 100644 --- a/consensus/types/src/blob_sidecar.rs +++ b/consensus/types/src/blob_sidecar.rs @@ -38,7 +38,7 @@ impl BlobIdentifier { impl PartialOrd for BlobIdentifier { fn partial_cmp(&self, other: &Self) -> Option { - self.index.partial_cmp(&other.index) + Some(self.cmp(other)) } } @@ -109,7 +109,7 @@ impl From> for BlindedBlobSidecar { impl PartialOrd for BlobSidecar { fn partial_cmp(&self, other: &Self) -> Option { - self.index.partial_cmp(&other.index) + Some(self.cmp(other)) } } diff --git a/validator_client/src/attestation_service.rs b/validator_client/src/attestation_service.rs index 1b7b391a0..b5bb6702a 100644 --- a/validator_client/src/attestation_service.rs +++ b/validator_client/src/attestation_service.rs @@ -193,7 +193,7 @@ impl AttestationService { .into_iter() .fold(HashMap::new(), |mut map, duty_and_proof| { map.entry(duty_and_proof.duty.committee_index) - .or_insert_with(Vec::new) + .or_default() .push(duty_and_proof); map }); diff --git a/validator_client/src/duties_service/sync.rs b/validator_client/src/duties_service/sync.rs index cf63d8ac6..12623d346 100644 --- a/validator_client/src/duties_service/sync.rs +++ b/validator_client/src/duties_service/sync.rs @@ -163,7 +163,7 @@ impl SyncDutiesMap { committees_writer .entry(committee_period) - .or_insert_with(CommitteeDuties::default) + .or_default() .init(validator_indices); // Return shared reference