From e27f5b00aff145f58960faff26343e6f707075bd Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 6 Sep 2024 10:42:24 +1000 Subject: [PATCH] Fix lints for Rust 1.81 --- .../src/attestation_verification.rs | 6 ++--- beacon_node/beacon_chain/src/beacon_chain.rs | 27 +++++++------------ .../beacon_chain/src/block_verification.rs | 3 +-- beacon_node/eth1/src/inner.rs | 5 +--- beacon_node/store/src/leveldb_store.rs | 3 +-- common/account_utils/src/lib.rs | 2 +- common/logging/src/lib.rs | 5 +--- 7 files changed, 16 insertions(+), 35 deletions(-) diff --git a/beacon_node/beacon_chain/src/attestation_verification.rs b/beacon_node/beacon_chain/src/attestation_verification.rs index 5a730719bfb..491271d6a9e 100644 --- a/beacon_node/beacon_chain/src/attestation_verification.rs +++ b/beacon_node/beacon_chain/src/attestation_verification.rs @@ -456,11 +456,10 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> { chain: &BeaconChain, ) -> Result { Self::verify_slashable(signed_aggregate, chain) - .map(|verified_aggregate| { + .inspect(|verified_aggregate| { if let Some(slasher) = chain.slasher.as_ref() { slasher.accept_attestation(verified_aggregate.indexed_attestation.clone()); } - verified_aggregate }) .map_err(|slash_info| process_slash_info(slash_info, chain)) } @@ -892,11 +891,10 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> { chain: &BeaconChain, ) -> Result { Self::verify_slashable(attestation.to_ref(), subnet_id, chain) - .map(|verified_unaggregated| { + .inspect(|verified_unaggregated| { if let Some(slasher) = chain.slasher.as_ref() { slasher.accept_attestation(verified_unaggregated.indexed_attestation.clone()); } - verified_unaggregated }) .map_err(|slash_info| process_slash_info(slash_info, chain)) } diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 2ba0ba7cb02..322a2caa673 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -2035,7 +2035,7 @@ impl BeaconChain { let _timer = metrics::start_timer(&metrics::UNAGGREGATED_ATTESTATION_GOSSIP_VERIFICATION_TIMES); - VerifiedUnaggregatedAttestation::verify(unaggregated_attestation, subnet_id, self).map( + VerifiedUnaggregatedAttestation::verify(unaggregated_attestation, subnet_id, self).inspect( |v| { // This method is called for API and gossip attestations, so this covers all unaggregated attestation events if let Some(event_handler) = self.event_handler.as_ref() { @@ -2046,7 +2046,6 @@ impl BeaconChain { } } metrics::inc_counter(&metrics::UNAGGREGATED_ATTESTATION_PROCESSING_SUCCESSES); - v }, ) } @@ -2074,7 +2073,7 @@ impl BeaconChain { let _timer = metrics::start_timer(&metrics::AGGREGATED_ATTESTATION_GOSSIP_VERIFICATION_TIMES); - VerifiedAggregatedAttestation::verify(signed_aggregate, self).map(|v| { + VerifiedAggregatedAttestation::verify(signed_aggregate, self).inspect(|v| { // This method is called for API and gossip attestations, so this covers all aggregated attestation events if let Some(event_handler) = self.event_handler.as_ref() { if event_handler.has_attestation_subscribers() { @@ -2084,7 +2083,6 @@ impl BeaconChain { } } metrics::inc_counter(&metrics::AGGREGATED_ATTESTATION_PROCESSING_SUCCESSES); - v }) } @@ -2098,9 +2096,8 @@ impl BeaconChain { metrics::inc_counter(&metrics::SYNC_MESSAGE_PROCESSING_REQUESTS); let _timer = metrics::start_timer(&metrics::SYNC_MESSAGE_GOSSIP_VERIFICATION_TIMES); - VerifiedSyncCommitteeMessage::verify(sync_message, subnet_id, self).map(|v| { + VerifiedSyncCommitteeMessage::verify(sync_message, subnet_id, self).inspect(|_| { metrics::inc_counter(&metrics::SYNC_MESSAGE_PROCESSING_SUCCESSES); - v }) } @@ -2112,7 +2109,7 @@ impl BeaconChain { ) -> Result, SyncCommitteeError> { metrics::inc_counter(&metrics::SYNC_CONTRIBUTION_PROCESSING_REQUESTS); let _timer = metrics::start_timer(&metrics::SYNC_CONTRIBUTION_GOSSIP_VERIFICATION_TIMES); - VerifiedSyncContribution::verify(sync_contribution, self).map(|v| { + VerifiedSyncContribution::verify(sync_contribution, self).inspect(|v| { if let Some(event_handler) = self.event_handler.as_ref() { if event_handler.has_contribution_subscribers() { event_handler.register(EventKind::ContributionAndProof(Box::new( @@ -2121,7 +2118,6 @@ impl BeaconChain { } } metrics::inc_counter(&metrics::SYNC_CONTRIBUTION_PROCESSING_SUCCESSES); - v }) } @@ -2136,9 +2132,8 @@ impl BeaconChain { self, seen_timestamp, ) - .map(|v| { + .inspect(|_| { metrics::inc_counter(&metrics::FINALITY_UPDATE_PROCESSING_SUCCESSES); - v }) } @@ -2149,9 +2144,8 @@ impl BeaconChain { ) -> Result, GossipDataColumnError> { metrics::inc_counter(&metrics::DATA_COLUMN_SIDECAR_PROCESSING_REQUESTS); let _timer = metrics::start_timer(&metrics::DATA_COLUMN_SIDECAR_GOSSIP_VERIFICATION_TIMES); - GossipVerifiedDataColumn::new(data_column_sidecar, subnet_id, self).map(|v| { + GossipVerifiedDataColumn::new(data_column_sidecar, subnet_id, self).inspect(|_| { metrics::inc_counter(&metrics::DATA_COLUMN_SIDECAR_PROCESSING_SUCCESSES); - v }) } @@ -2162,9 +2156,8 @@ impl BeaconChain { ) -> Result, GossipBlobError> { metrics::inc_counter(&metrics::BLOBS_SIDECAR_PROCESSING_REQUESTS); let _timer = metrics::start_timer(&metrics::BLOBS_SIDECAR_GOSSIP_VERIFICATION_TIMES); - GossipVerifiedBlob::new(blob_sidecar, subnet_id, self).map(|v| { + GossipVerifiedBlob::new(blob_sidecar, subnet_id, self).inspect(|_| { metrics::inc_counter(&metrics::BLOBS_SIDECAR_PROCESSING_SUCCESSES); - v }) } @@ -2179,9 +2172,8 @@ impl BeaconChain { self, seen_timestamp, ) - .map(|v| { + .inspect(|_| { metrics::inc_counter(&metrics::OPTIMISTIC_UPDATE_PROCESSING_SUCCESSES); - v }) } @@ -2485,7 +2477,7 @@ impl BeaconChain { .observed_voluntary_exits .lock() .verify_and_observe_at(exit, wall_clock_epoch, head_state, &self.spec) - .map(|exit| { + .inspect(|exit| { // this method is called for both API and gossip exits, so this covers all exit events if let Some(event_handler) = self.event_handler.as_ref() { if event_handler.has_exit_subscribers() { @@ -2494,7 +2486,6 @@ impl BeaconChain { } } } - exit })?) } diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index 976388a4f5a..55547aaa18c 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -834,12 +834,11 @@ pub trait IntoExecutionPendingBlock: Sized { notify_execution_layer: NotifyExecutionLayer, ) -> Result, BlockError> { self.into_execution_pending_block_slashable(block_root, chain, notify_execution_layer) - .map(|execution_pending| { + .inspect(|execution_pending| { // Supply valid block to slasher. if let Some(slasher) = chain.slasher.as_ref() { slasher.accept_block_header(execution_pending.block.signed_block_header()); } - execution_pending }) .map_err(|slash_info| process_block_slash_info::<_, BlockError>(chain, slash_info)) } diff --git a/beacon_node/eth1/src/inner.rs b/beacon_node/eth1/src/inner.rs index 452922b173c..7387642bf4c 100644 --- a/beacon_node/eth1/src/inner.rs +++ b/beacon_node/eth1/src/inner.rs @@ -75,10 +75,7 @@ impl Inner { SszEth1Cache::from_ssz_bytes(bytes) .map_err(|e| format!("Ssz decoding error: {:?}", e))? .to_inner(config, spec) - .map(|inner| { - inner.block_cache.write().rebuild_by_hash_map(); - inner - }) + .inspect(|inner| inner.block_cache.write().rebuild_by_hash_map()) } /// Returns a reference to the specification. diff --git a/beacon_node/store/src/leveldb_store.rs b/beacon_node/store/src/leveldb_store.rs index 28e04f56205..720afd0f3f6 100644 --- a/beacon_node/store/src/leveldb_store.rs +++ b/beacon_node/store/src/leveldb_store.rs @@ -98,14 +98,13 @@ impl KeyValueStore for LevelDB { .get(self.read_options(), BytesKey::from_vec(column_key)) .map_err(Into::into) .map(|opt| { - opt.map(|bytes| { + opt.inspect(|bytes| { metrics::inc_counter_vec_by( &metrics::DISK_DB_READ_BYTES, &[col], bytes.len() as u64, ); metrics::stop_timer(timer); - bytes }) }) } diff --git a/common/account_utils/src/lib.rs b/common/account_utils/src/lib.rs index 665953fa522..2c8bbbf4b4e 100644 --- a/common/account_utils/src/lib.rs +++ b/common/account_utils/src/lib.rs @@ -228,7 +228,7 @@ impl ZeroizeString { /// Remove any number of newline or carriage returns from the end of a vector of bytes. pub fn without_newlines(&self) -> ZeroizeString { - let stripped_string = self.0.trim_end_matches(|c| c == '\r' || c == '\n').into(); + let stripped_string = self.0.trim_end_matches(['\r', '\n']).into(); Self(stripped_string) } } diff --git a/common/logging/src/lib.rs b/common/logging/src/lib.rs index d3d91497ccb..a4a1acabd48 100644 --- a/common/logging/src/lib.rs +++ b/common/logging/src/lib.rs @@ -100,10 +100,7 @@ impl<'a> AlignedRecordDecorator<'a> { self.ignore_comma = false; Ok(buf.len()) } else if self.message_active { - self.wrapped.write(buf).map(|n| { - self.message_count += n; - n - }) + self.wrapped.write(buf).inspect(|n| self.message_count += n) } else { self.wrapped.write(buf) }