From 4ce01ddd11b70bf6bdd6ac3896e2b33acbf00f72 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Tue, 31 Oct 2023 10:31:02 +0000 Subject: [PATCH] Activate `clippy::manual_let_else` lint (#4889) ## Issue Addressed #4888 ## Proposed Changes Enabled `clippy::manual_let_else` lint and resolved the warning messages. --- Makefile | 1 + beacon_node/beacon_chain/src/beacon_chain.rs | 58 ++++++++----------- .../src/data_availability_checker.rs | 14 ++--- .../overflow_lru_cache.rs | 10 ++-- .../beacon_chain/src/early_attester_cache.rs | 4 +- .../src/schema_change/migration_schema_v12.rs | 14 ++--- .../src/schema_change/migration_schema_v14.rs | 29 ++++------ .../src/schema_change/migration_schema_v15.rs | 14 ++--- .../src/schema_change/migration_schema_v18.rs | 15 ++--- .../beacon_chain/src/state_advance_timer.rs | 13 ++--- beacon_node/execution_layer/src/lib.rs | 6 +- .../test_utils/execution_block_generator.rs | 4 +- beacon_node/http_api/src/sync_committees.rs | 4 +- .../src/rpc/codec/ssz_snappy.rs | 15 ++--- .../lighthouse_network/src/rpc/handler.rs | 5 +- .../src/service/gossip_cache.rs | 5 +- .../network_beacon_processor/rpc_methods.rs | 19 +++--- .../network_beacon_processor/sync_methods.rs | 49 ++++++++-------- .../network/src/sync/backfill_sync/mod.rs | 22 +++---- .../network/src/sync/block_lookups/mod.rs | 22 +++---- .../network/src/sync/range_sync/chain.rs | 23 +++----- beacon_node/store/src/hot_cold_store.rs | 14 ++--- beacon_node/store/src/reconstruct.rs | 4 +- beacon_node/timer/src/lib.rs | 10 ++-- common/compare_fields_derive/src/lib.rs | 11 ++-- common/eth2/src/lib.rs | 15 ++--- common/test_random_derive/src/lib.rs | 5 +- consensus/proto_array/src/proto_array.rs | 6 +- crypto/bls/src/impls/blst.rs | 5 +- lighthouse/environment/src/lib.rs | 9 +-- slasher/src/array.rs | 21 +++---- .../src/cases/merkle_proof_validity.rs | 11 ++-- validator_client/src/doppelganger_service.rs | 4 +- validator_client/src/duties_service/sync.rs | 4 +- .../src/sync_committee_service.rs | 6 +- 35 files changed, 185 insertions(+), 286 deletions(-) diff --git a/Makefile b/Makefile index 6720d1433..e3d889bfe 100644 --- a/Makefile +++ b/Makefile @@ -208,6 +208,7 @@ test-full: cargo-fmt test-release test-debug test-ef test-exec-engine lint: cargo clippy --workspace --tests $(EXTRA_CLIPPY_OPTS) --features "$(TEST_FEATURES)" -- \ -D clippy::fn_to_numeric_cast_any \ + -D clippy::manual_let_else \ -D warnings \ -A clippy::derive_partial_eq_without_eq \ -A clippy::from-over-into \ diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 2640d5374..9f5973393 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -601,11 +601,11 @@ impl BeaconChain { spec: &ChainSpec, log: &Logger, ) -> Result>, Error> { - let persisted_fork_choice = - match store.get_item::(&FORK_CHOICE_DB_KEY)? { - Some(fc) => fc, - None => return Ok(None), - }; + let Some(persisted_fork_choice) = + store.get_item::(&FORK_CHOICE_DB_KEY)? + else { + return Ok(None); + }; let fc_store = BeaconForkChoiceStore::from_persisted(persisted_fork_choice.fork_choice_store, store)?; @@ -3485,9 +3485,7 @@ impl BeaconChain { state: &BeaconState, ) -> Result<(), BlockError> { // Only perform the weak subjectivity check if it was configured. - let wss_checkpoint = if let Some(checkpoint) = self.config.weak_subjectivity_checkpoint { - checkpoint - } else { + let Some(wss_checkpoint) = self.config.weak_subjectivity_checkpoint else { return Ok(()); }; // Note: we're using the finalized checkpoint from the head state, rather than fork @@ -5336,14 +5334,11 @@ impl BeaconChain { ) .await??; - let (forkchoice_update_params, pre_payload_attributes) = - if let Some((fcu, Some(pre_payload))) = maybe_prep_data { - (fcu, pre_payload) - } else { - // Appropriate log messages have already been logged above and in - // `get_pre_payload_attributes`. - return Ok(()); - }; + let Some((forkchoice_update_params, Some(pre_payload_attributes))) = maybe_prep_data else { + // Appropriate log messages have already been logged above and in + // `get_pre_payload_attributes`. + return Ok(()); + }; // If the execution layer doesn't have any proposer data for this validator then we assume // it's not connected to this BN and no action is required. @@ -5436,23 +5431,20 @@ impl BeaconChain { } } - let till_prepare_slot = - if let Some(duration) = self.slot_clock.duration_to_slot(prepare_slot) { - duration - } else { - // `SlotClock::duration_to_slot` will return `None` when we are past the start - // of `prepare_slot`. Don't bother sending a `forkchoiceUpdated` in that case, - // it's too late. - // - // This scenario might occur on an overloaded/under-resourced node. - warn!( - self.log, - "Delayed proposer preparation"; - "prepare_slot" => prepare_slot, - "validator" => proposer, - ); - return Ok(()); - }; + let Some(till_prepare_slot) = self.slot_clock.duration_to_slot(prepare_slot) else { + // `SlotClock::duration_to_slot` will return `None` when we are past the start + // of `prepare_slot`. Don't bother sending a `forkchoiceUpdated` in that case, + // it's too late. + // + // This scenario might occur on an overloaded/under-resourced node. + warn!( + self.log, + "Delayed proposer preparation"; + "prepare_slot" => prepare_slot, + "validator" => proposer, + ); + return Ok(()); + }; // If we are close enough to the proposal slot, send an fcU, which will have payload // attributes filled in by the execution layer cache we just primed. diff --git a/beacon_node/beacon_chain/src/data_availability_checker.rs b/beacon_node/beacon_chain/src/data_availability_checker.rs index d14afafbf..a8d077a6d 100644 --- a/beacon_node/beacon_chain/src/data_availability_checker.rs +++ b/beacon_node/beacon_chain/src/data_availability_checker.rs @@ -451,23 +451,21 @@ async fn availability_cache_maintenance_service( let additional_delay = (epoch_duration * 3) / 4; tokio::time::sleep(duration + additional_delay).await; - let deneb_fork_epoch = match chain.spec.deneb_fork_epoch { - Some(epoch) => epoch, - None => break, // shutdown service if deneb fork epoch not set + let Some(deneb_fork_epoch) = chain.spec.deneb_fork_epoch else { + // shutdown service if deneb fork epoch not set + break; }; debug!( chain.log, "Availability cache maintenance service firing"; ); - - let current_epoch = match chain + let Some(current_epoch) = chain .slot_clock .now() .map(|slot| slot.epoch(T::EthSpec::slots_per_epoch())) - { - Some(epoch) => epoch, - None => continue, // we'll have to try again next time I suppose.. + else { + continue; }; if current_epoch < deneb_fork_epoch { diff --git a/beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs b/beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs index aa7c5622e..e2eef45d2 100644 --- a/beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs +++ b/beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs @@ -547,9 +547,8 @@ impl OverflowLRUCache { .peek_lru() .map(|(key, value)| (*key, value.clone())); - let (lru_root, lru_pending_components) = match lru_entry { - Some((r, p)) => (r, p), - None => break, + let Some((lru_root, lru_pending_components)) = lru_entry else { + break; }; if lru_pending_components @@ -605,9 +604,8 @@ impl OverflowLRUCache { let delete_if_outdated = |cache: &OverflowLRUCache, block_data: Option| -> Result<(), AvailabilityCheckError> { - let block_data = match block_data { - Some(block_data) => block_data, - None => return Ok(()), + let Some(block_data) = block_data else { + return Ok(()); }; let not_in_store_keys = !cache.critical.read().store_keys.contains(&block_data.root); if not_in_store_keys { diff --git a/beacon_node/beacon_chain/src/early_attester_cache.rs b/beacon_node/beacon_chain/src/early_attester_cache.rs index c58b045cf..da3c2c8a1 100644 --- a/beacon_node/beacon_chain/src/early_attester_cache.rs +++ b/beacon_node/beacon_chain/src/early_attester_cache.rs @@ -99,9 +99,7 @@ impl EarlyAttesterCache { spec: &ChainSpec, ) -> Result>, Error> { let lock = self.item.read(); - let item = if let Some(item) = lock.as_ref() { - item - } else { + let Some(item) = lock.as_ref() else { return Ok(None); }; diff --git a/beacon_node/beacon_chain/src/schema_change/migration_schema_v12.rs b/beacon_node/beacon_chain/src/schema_change/migration_schema_v12.rs index c9aa2097f..ab267796e 100644 --- a/beacon_node/beacon_chain/src/schema_change/migration_schema_v12.rs +++ b/beacon_node/beacon_chain/src/schema_change/migration_schema_v12.rs @@ -16,15 +16,14 @@ pub fn upgrade_to_v12( let spec = db.get_chain_spec(); // Load a V5 op pool and transform it to V12. - let PersistedOperationPoolV5 { + let Some(PersistedOperationPoolV5 { attestations_v5, sync_contributions, attester_slashings_v5, proposer_slashings_v5, voluntary_exits_v5, - } = if let Some(op_pool) = db.get_item(&OP_POOL_DB_KEY)? { - op_pool - } else { + }) = db.get_item(&OP_POOL_DB_KEY)? + else { debug!(log, "Nothing to do, no operation pool stored"); return Ok(vec![]); }; @@ -168,15 +167,14 @@ pub fn downgrade_from_v12( log: Logger, ) -> Result, Error> { // Load a V12 op pool and transform it to V5. - let PersistedOperationPoolV12:: { + let Some(PersistedOperationPoolV12:: { attestations, sync_contributions, attester_slashings, proposer_slashings, voluntary_exits, - } = if let Some(op_pool_v12) = db.get_item(&OP_POOL_DB_KEY)? { - op_pool_v12 - } else { + }) = db.get_item(&OP_POOL_DB_KEY)? + else { debug!(log, "Nothing to do, no operation pool stored"); return Ok(vec![]); }; diff --git a/beacon_node/beacon_chain/src/schema_change/migration_schema_v14.rs b/beacon_node/beacon_chain/src/schema_change/migration_schema_v14.rs index be913d8cc..52a990dc6 100644 --- a/beacon_node/beacon_chain/src/schema_change/migration_schema_v14.rs +++ b/beacon_node/beacon_chain/src/schema_change/migration_schema_v14.rs @@ -18,19 +18,14 @@ fn get_slot_clock( log: &Logger, ) -> Result, Error> { let spec = db.get_chain_spec(); - let genesis_block = if let Some(block) = db.get_blinded_block(&Hash256::zero())? { - block - } else { + let Some(genesis_block) = db.get_blinded_block(&Hash256::zero())? else { error!(log, "Missing genesis block"); return Ok(None); }; - let genesis_state = - if let Some(state) = db.get_state(&genesis_block.state_root(), Some(Slot::new(0)))? { - state - } else { - error!(log, "Missing genesis state"; "state_root" => ?genesis_block.state_root()); - return Ok(None); - }; + let Some(genesis_state) = db.get_state(&genesis_block.state_root(), Some(Slot::new(0)))? else { + error!(log, "Missing genesis state"; "state_root" => ?genesis_block.state_root()); + return Ok(None); + }; Ok(Some(T::SlotClock::new( spec.genesis_slot, Duration::from_secs(genesis_state.genesis_time()), @@ -43,15 +38,14 @@ pub fn upgrade_to_v14( log: Logger, ) -> Result, Error> { // Load a V12 op pool and transform it to V14. - let PersistedOperationPoolV12:: { + let Some(PersistedOperationPoolV12:: { attestations, sync_contributions, attester_slashings, proposer_slashings, voluntary_exits, - } = if let Some(op_pool_v12) = db.get_item(&OP_POOL_DB_KEY)? { - op_pool_v12 - } else { + }) = db.get_item(&OP_POOL_DB_KEY)? + else { debug!(log, "Nothing to do, no operation pool stored"); return Ok(vec![]); }; @@ -94,16 +88,15 @@ pub fn downgrade_from_v14( } // Load a V14 op pool and transform it to V12. - let PersistedOperationPoolV14:: { + let Some(PersistedOperationPoolV14:: { attestations, sync_contributions, attester_slashings, proposer_slashings, voluntary_exits, bls_to_execution_changes, - } = if let Some(op_pool) = db.get_item(&OP_POOL_DB_KEY)? { - op_pool - } else { + }) = db.get_item(&OP_POOL_DB_KEY)? + else { debug!(log, "Nothing to do, no operation pool stored"); return Ok(vec![]); }; diff --git a/beacon_node/beacon_chain/src/schema_change/migration_schema_v15.rs b/beacon_node/beacon_chain/src/schema_change/migration_schema_v15.rs index 07c86bd93..0eb2c5fa3 100644 --- a/beacon_node/beacon_chain/src/schema_change/migration_schema_v15.rs +++ b/beacon_node/beacon_chain/src/schema_change/migration_schema_v15.rs @@ -11,16 +11,15 @@ pub fn upgrade_to_v15( log: Logger, ) -> Result, Error> { // Load a V14 op pool and transform it to V15. - let PersistedOperationPoolV14:: { + let Some(PersistedOperationPoolV14:: { attestations, sync_contributions, attester_slashings, proposer_slashings, voluntary_exits, bls_to_execution_changes, - } = if let Some(op_pool_v14) = db.get_item(&OP_POOL_DB_KEY)? { - op_pool_v14 - } else { + }) = db.get_item(&OP_POOL_DB_KEY)? + else { debug!(log, "Nothing to do, no operation pool stored"); return Ok(vec![]); }; @@ -43,7 +42,7 @@ pub fn downgrade_from_v15( log: Logger, ) -> Result, Error> { // Load a V15 op pool and transform it to V14. - let PersistedOperationPoolV15:: { + let Some(PersistedOperationPoolV15:: { attestations, sync_contributions, attester_slashings, @@ -51,9 +50,8 @@ pub fn downgrade_from_v15( voluntary_exits, bls_to_execution_changes, capella_bls_change_broadcast_indices, - } = if let Some(op_pool) = db.get_item(&OP_POOL_DB_KEY)? { - op_pool - } else { + }) = db.get_item(&OP_POOL_DB_KEY)? + else { debug!(log, "Nothing to do, no operation pool stored"); return Ok(vec![]); }; diff --git a/beacon_node/beacon_chain/src/schema_change/migration_schema_v18.rs b/beacon_node/beacon_chain/src/schema_change/migration_schema_v18.rs index 14a560f97..e7b68eb41 100644 --- a/beacon_node/beacon_chain/src/schema_change/migration_schema_v18.rs +++ b/beacon_node/beacon_chain/src/schema_change/migration_schema_v18.rs @@ -17,19 +17,14 @@ fn get_slot_clock( log: &Logger, ) -> Result, Error> { let spec = db.get_chain_spec(); - let genesis_block = if let Some(block) = db.get_blinded_block(&Hash256::zero())? { - block - } else { + let Some(genesis_block) = db.get_blinded_block(&Hash256::zero())? else { error!(log, "Missing genesis block"); return Ok(None); }; - let genesis_state = - if let Some(state) = db.get_state(&genesis_block.state_root(), Some(Slot::new(0)))? { - state - } else { - error!(log, "Missing genesis state"; "state_root" => ?genesis_block.state_root()); - return Ok(None); - }; + let Some(genesis_state) = db.get_state(&genesis_block.state_root(), Some(Slot::new(0)))? else { + error!(log, "Missing genesis state"; "state_root" => ?genesis_block.state_root()); + return Ok(None); + }; Ok(Some(T::SlotClock::new( spec.genesis_slot, Duration::from_secs(genesis_state.genesis_time()), diff --git a/beacon_node/beacon_chain/src/state_advance_timer.rs b/beacon_node/beacon_chain/src/state_advance_timer.rs index f73223fa5..f3e97168a 100644 --- a/beacon_node/beacon_chain/src/state_advance_timer.rs +++ b/beacon_node/beacon_chain/src/state_advance_timer.rs @@ -113,14 +113,11 @@ async fn state_advance_timer( let slot_duration = slot_clock.slot_duration(); loop { - let duration_to_next_slot = match beacon_chain.slot_clock.duration_to_next_slot() { - Some(duration) => duration, - None => { - error!(log, "Failed to read slot clock"); - // If we can't read the slot clock, just wait another slot. - sleep(slot_duration).await; - continue; - } + let Some(duration_to_next_slot) = beacon_chain.slot_clock.duration_to_next_slot() else { + error!(log, "Failed to read slot clock"); + // If we can't read the slot clock, just wait another slot. + sleep(slot_duration).await; + continue; }; // Run the state advance 3/4 of the way through the slot (9s on mainnet). diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index 034400487..623965ada 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -1799,13 +1799,11 @@ impl ExecutionLayer { }; } - let block = if let Some(block) = engine + let Some(block) = engine .api .get_block_by_hash_with_txns::(hash, fork) .await? - { - block - } else { + else { return Ok(None); }; 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 40e4f37aa..cf0faf655 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 @@ -426,9 +426,7 @@ impl ExecutionBlockGenerator { } pub fn new_payload(&mut self, payload: ExecutionPayload) -> PayloadStatusV1 { - let parent = if let Some(parent) = self.blocks.get(&payload.parent_hash()) { - parent - } else { + let Some(parent) = self.blocks.get(&payload.parent_hash()) else { return PayloadStatusV1 { status: PayloadStatusV1Status::Syncing, latest_valid_hash: None, diff --git a/beacon_node/http_api/src/sync_committees.rs b/beacon_node/http_api/src/sync_committees.rs index dcf41429f..8b0c7dc0e 100644 --- a/beacon_node/http_api/src/sync_committees.rs +++ b/beacon_node/http_api/src/sync_committees.rs @@ -30,9 +30,7 @@ pub fn sync_committee_duties( request_indices: &[u64], chain: &BeaconChain, ) -> Result { - let altair_fork_epoch = if let Some(altair_fork_epoch) = chain.spec.altair_fork_epoch { - altair_fork_epoch - } else { + let Some(altair_fork_epoch) = chain.spec.altair_fork_epoch else { // Empty response for networks with Altair disabled. return Ok(convert_to_response(vec![], false)); }; diff --git a/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs b/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs index 2bcaec147..f1b76674a 100644 --- a/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs +++ b/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs @@ -135,9 +135,8 @@ impl Decoder for SSZSnappyInboundCodec { if self.protocol.versioned_protocol == SupportedProtocol::MetaDataV2 { return Ok(Some(InboundRequest::MetaData(MetadataRequest::new_v2()))); } - let length = match handle_length(&mut self.inner, &mut self.len, src)? { - Some(len) => len, - None => return Ok(None), + let Some(length) = handle_length(&mut self.inner, &mut self.len, src)? else { + return Ok(None); }; // Should not attempt to decode rpc chunks with `length > max_packet_size` or not within bounds of @@ -277,9 +276,8 @@ impl Decoder for SSZSnappyOutboundCodec { return Ok(None); } } - let length = match handle_length(&mut self.inner, &mut self.len, src)? { - Some(len) => len, - None => return Ok(None), + let Some(length) = handle_length(&mut self.inner, &mut self.len, src)? else { + return Ok(None); }; // Should not attempt to decode rpc chunks with `length > max_packet_size` or not within bounds of @@ -324,9 +322,8 @@ impl OutboundCodec> for SSZSnappyOutbound &mut self, src: &mut BytesMut, ) -> Result, RPCError> { - let length = match handle_length(&mut self.inner, &mut self.len, src)? { - Some(len) => len, - None => return Ok(None), + let Some(length) = handle_length(&mut self.inner, &mut self.len, src)? else { + return Ok(None); }; // Should not attempt to decode rpc chunks with `length > max_packet_size` or not within bounds of diff --git a/beacon_node/lighthouse_network/src/rpc/handler.rs b/beacon_node/lighthouse_network/src/rpc/handler.rs index def60af8c..8d1563faf 100644 --- a/beacon_node/lighthouse_network/src/rpc/handler.rs +++ b/beacon_node/lighthouse_network/src/rpc/handler.rs @@ -286,9 +286,7 @@ where // wrong state a response will fail silently. fn send_response(&mut self, inbound_id: SubstreamId, response: RPCCodedResponse) { // check if the stream matching the response still exists - let inbound_info = if let Some(info) = self.inbound_substreams.get_mut(&inbound_id) { - info - } else { + let Some(inbound_info) = self.inbound_substreams.get_mut(&inbound_id) else { if !matches!(response, RPCCodedResponse::StreamTermination(..)) { // the stream is closed after sending the expected number of responses trace!(self.log, "Inbound stream has expired. Response not sent"; @@ -296,7 +294,6 @@ where } return; }; - // If the response we are sending is an error, report back for handling if let RPCCodedResponse::Error(ref code, ref reason) = response { self.events_out.push(Err(HandlerErr::Inbound { diff --git a/beacon_node/lighthouse_network/src/service/gossip_cache.rs b/beacon_node/lighthouse_network/src/service/gossip_cache.rs index a6e003934..5dc0d29ff 100644 --- a/beacon_node/lighthouse_network/src/service/gossip_cache.rs +++ b/beacon_node/lighthouse_network/src/service/gossip_cache.rs @@ -205,9 +205,8 @@ impl GossipCache { GossipKind::LightClientFinalityUpdate => self.light_client_finality_update, GossipKind::LightClientOptimisticUpdate => self.light_client_optimistic_update, }; - let expire_timeout = match expire_timeout { - Some(expire_timeout) => expire_timeout, - None => return, + let Some(expire_timeout) = expire_timeout else { + return; }; match self .topic_msgs diff --git a/beacon_node/network/src/network_beacon_processor/rpc_methods.rs b/beacon_node/network/src/network_beacon_processor/rpc_methods.rs index 6d569112f..0e6c76e22 100644 --- a/beacon_node/network/src/network_beacon_processor/rpc_methods.rs +++ b/beacon_node/network/src/network_beacon_processor/rpc_methods.rs @@ -350,17 +350,14 @@ impl NetworkBeaconProcessor { return; } }; - let bootstrap = match LightClientBootstrap::from_beacon_state(&mut beacon_state) { - Ok(bootstrap) => bootstrap, - Err(_) => { - self.send_error_response( - peer_id, - RPCResponseErrorCode::ResourceUnavailable, - "Bootstrap not available".into(), - request_id, - ); - return; - } + let Ok(bootstrap) = LightClientBootstrap::from_beacon_state(&mut beacon_state) else { + self.send_error_response( + peer_id, + RPCResponseErrorCode::ResourceUnavailable, + "Bootstrap not available".into(), + request_id, + ); + return; }; self.send_response( peer_id, diff --git a/beacon_node/network/src/network_beacon_processor/sync_methods.rs b/beacon_node/network/src/network_beacon_processor/sync_methods.rs index 0e74cb08c..7d6bde634 100644 --- a/beacon_node/network/src/network_beacon_processor/sync_methods.rs +++ b/beacon_node/network/src/network_beacon_processor/sync_methods.rs @@ -115,34 +115,31 @@ impl NetworkBeaconProcessor { duplicate_cache: DuplicateCache, ) { // Check if the block is already being imported through another source - let handle = match duplicate_cache.check_and_insert(block_root) { - Some(handle) => handle, - None => { - debug!( - self.log, - "Gossip block is being processed"; - "action" => "sending rpc block to reprocessing queue", - "block_root" => %block_root, - ); + let Some(handle) = duplicate_cache.check_and_insert(block_root) else { + debug!( + self.log, + "Gossip block is being processed"; + "action" => "sending rpc block to reprocessing queue", + "block_root" => %block_root, + ); - // Send message to work reprocess queue to retry the block - let (process_fn, ignore_fn) = self.clone().generate_rpc_beacon_block_fns( - block_root, - block, - seen_timestamp, - process_type, - ); - let reprocess_msg = ReprocessQueueMessage::RpcBlock(QueuedRpcBlock { - beacon_block_root: block_root, - process_fn, - ignore_fn, - }); + // Send message to work reprocess queue to retry the block + let (process_fn, ignore_fn) = self.clone().generate_rpc_beacon_block_fns( + block_root, + block, + seen_timestamp, + process_type, + ); + let reprocess_msg = ReprocessQueueMessage::RpcBlock(QueuedRpcBlock { + beacon_block_root: block_root, + process_fn, + ignore_fn, + }); - if reprocess_tx.try_send(reprocess_msg).is_err() { - error!(self.log, "Failed to inform block import"; "source" => "rpc", "block_root" => %block_root) - }; - return; - } + if reprocess_tx.try_send(reprocess_msg).is_err() { + error!(self.log, "Failed to inform block import"; "source" => "rpc", "block_root" => %block_root) + }; + return; }; // Returns `true` if the time now is after the 4s attestation deadline. diff --git a/beacon_node/network/src/sync/backfill_sync/mod.rs b/beacon_node/network/src/sync/backfill_sync/mod.rs index 0900e034f..e58084697 100644 --- a/beacon_node/network/src/sync/backfill_sync/mod.rs +++ b/beacon_node/network/src/sync/backfill_sync/mod.rs @@ -509,16 +509,13 @@ impl BackFillSync { return Ok(ProcessResult::Successful); } - let batch = match self.batches.get_mut(&batch_id) { - Some(batch) => batch, - None => { - return self - .fail_sync(BackFillError::InvalidSyncState(format!( - "Trying to process a batch that does not exist: {}", - batch_id - ))) - .map(|_| ProcessResult::Successful); - } + let Some(batch) = self.batches.get_mut(&batch_id) else { + return self + .fail_sync(BackFillError::InvalidSyncState(format!( + "Trying to process a batch that does not exist: {}", + batch_id + ))) + .map(|_| ProcessResult::Successful); }; // NOTE: We send empty batches to the processor in order to trigger the block processor @@ -909,9 +906,8 @@ impl BackFillSync { network: &mut SyncNetworkContext, batch_id: BatchId, ) -> Result<(), BackFillError> { - let batch = match self.batches.get_mut(&batch_id) { - Some(batch) => batch, - None => return Ok(()), + let Some(batch) = self.batches.get_mut(&batch_id) else { + return Ok(()); }; // Find a peer to request the batch diff --git a/beacon_node/network/src/sync/block_lookups/mod.rs b/beacon_node/network/src/sync/block_lookups/mod.rs index 92cb115f4..d13bb8cb8 100644 --- a/beacon_node/network/src/sync/block_lookups/mod.rs +++ b/beacon_node/network/src/sync/block_lookups/mod.rs @@ -1015,15 +1015,12 @@ impl BlockLookups { BlockProcessingResult::Ok(AvailabilityProcessingStatus::Imported(_)) | BlockProcessingResult::Err(BlockError::BlockIsAlreadyKnown { .. }) => { // Check if the beacon processor is available - let beacon_processor = match cx.beacon_processor_if_enabled() { - Some(beacon_processor) => beacon_processor, - None => { - return trace!( - self.log, - "Dropping parent chain segment that was ready for processing."; - parent_lookup - ); - } + let Some(beacon_processor) = cx.beacon_processor_if_enabled() else { + return trace!( + self.log, + "Dropping parent chain segment that was ready for processing."; + parent_lookup + ); }; let (chain_hash, blocks, hashes, block_request) = parent_lookup.parts_for_processing(); @@ -1195,11 +1192,8 @@ impl BlockLookups { result: BatchProcessResult, cx: &SyncNetworkContext, ) { - let request = match self.processing_parent_lookups.remove(&chain_hash) { - Some((_hashes, request)) => request, - None => { - return debug!(self.log, "Chain process response for a parent lookup request that was not found"; "chain_hash" => %chain_hash, "result" => ?result) - } + let Some((_hashes, request)) = self.processing_parent_lookups.remove(&chain_hash) else { + return debug!(self.log, "Chain process response for a parent lookup request that was not found"; "chain_hash" => %chain_hash, "result" => ?result); }; debug!(self.log, "Parent chain processed"; "chain_hash" => %chain_hash, "result" => ?result); diff --git a/beacon_node/network/src/sync/range_sync/chain.rs b/beacon_node/network/src/sync/range_sync/chain.rs index 9386d29e0..1e5bf09b3 100644 --- a/beacon_node/network/src/sync/range_sync/chain.rs +++ b/beacon_node/network/src/sync/range_sync/chain.rs @@ -294,19 +294,15 @@ impl SyncingChain { return Ok(KeepChain); } - let beacon_processor = match network.beacon_processor_if_enabled() { - Some(beacon_processor) => beacon_processor, - None => return Ok(KeepChain), + let Some(beacon_processor) = network.beacon_processor_if_enabled() else { + return Ok(KeepChain); }; - let batch = match self.batches.get_mut(&batch_id) { - Some(batch) => batch, - None => { - return Err(RemoveChain::WrongChainState(format!( - "Trying to process a batch that does not exist: {}", - batch_id - ))); - } + let Some(batch) = self.batches.get_mut(&batch_id) else { + return Err(RemoveChain::WrongChainState(format!( + "Trying to process a batch that does not exist: {}", + batch_id + ))); }; // NOTE: We send empty batches to the processor in order to trigger the block processor @@ -874,9 +870,8 @@ impl SyncingChain { network: &mut SyncNetworkContext, batch_id: BatchId, ) -> ProcessingResult { - let batch = match self.batches.get_mut(&batch_id) { - Some(batch) => batch, - None => return Ok(KeepChain), + let Some(batch) = self.batches.get_mut(&batch_id) else { + return Ok(KeepChain); }; // Find a peer to request the batch diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index 3ef5bf61e..640647db3 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -432,9 +432,8 @@ impl, Cold: ItemStore> HotColdDB } // Load the blinded block. - let blinded_block = match self.get_blinded_block(block_root)? { - Some(block) => block, - None => return Ok(None), + let Some(blinded_block) = self.get_blinded_block(block_root)? else { + return Ok(None); }; // If the block is after the split point then we should have the full execution payload @@ -2053,12 +2052,9 @@ impl, Cold: ItemStore> HotColdDB /// Try to prune blobs, approximating the current epoch from the split slot. pub fn try_prune_most_blobs(&self, force: bool) -> Result<(), Error> { - let deneb_fork_epoch = match self.spec.deneb_fork_epoch { - Some(epoch) => epoch, - None => { - debug!(self.log, "Deneb fork is disabled"); - return Ok(()); - } + let Some(deneb_fork_epoch) = self.spec.deneb_fork_epoch else { + debug!(self.log, "Deneb fork is disabled"); + return Ok(()); }; // The current epoch is >= split_epoch + 2. It could be greater if the database is // configured to delay updating the split or finalization has ceased. In this instance we diff --git a/beacon_node/store/src/reconstruct.rs b/beacon_node/store/src/reconstruct.rs index bac5d3cc8..8fe13777a 100644 --- a/beacon_node/store/src/reconstruct.rs +++ b/beacon_node/store/src/reconstruct.rs @@ -17,9 +17,7 @@ where Cold: ItemStore, { pub fn reconstruct_historic_states(self: &Arc) -> Result<(), Error> { - let mut anchor = if let Some(anchor) = self.get_anchor_info() { - anchor - } else { + let Some(mut anchor) = self.get_anchor_info() else { // Nothing to do, history is complete. return Ok(()); }; diff --git a/beacon_node/timer/src/lib.rs b/beacon_node/timer/src/lib.rs index 944846c86..7c2db6960 100644 --- a/beacon_node/timer/src/lib.rs +++ b/beacon_node/timer/src/lib.rs @@ -16,12 +16,10 @@ pub fn spawn_timer( let log = executor.log().clone(); let timer_future = async move { loop { - let duration_to_next_slot = match beacon_chain.slot_clock.duration_to_next_slot() { - Some(duration) => duration, - None => { - warn!(log, "Unable to determine duration to next slot"); - return; - } + let Some(duration_to_next_slot) = beacon_chain.slot_clock.duration_to_next_slot() + else { + warn!(log, "Unable to determine duration to next slot"); + return; }; sleep(duration_to_next_slot).await; diff --git a/common/compare_fields_derive/src/lib.rs b/common/compare_fields_derive/src/lib.rs index 099db8e79..01c5a8f6e 100644 --- a/common/compare_fields_derive/src/lib.rs +++ b/common/compare_fields_derive/src/lib.rs @@ -19,19 +19,16 @@ pub fn compare_fields_derive(input: TokenStream) -> TokenStream { let name = &item.ident; let (impl_generics, ty_generics, where_clause) = &item.generics.split_for_impl(); - let struct_data = match &item.data { - syn::Data::Struct(s) => s, - _ => panic!("compare_fields_derive only supports structs."), + let syn::Data::Struct(struct_data) = &item.data else { + panic!("compare_fields_derive only supports structs."); }; let mut quotes = vec![]; for field in struct_data.fields.iter() { - let ident_a = match &field.ident { - Some(ref ident) => ident, - _ => panic!("compare_fields_derive only supports named struct fields."), + let Some(ident_a) = &field.ident else { + panic!("compare_fields_derive only supports named struct fields."); }; - let field_name = ident_a.to_string(); let ident_b = ident_a.clone(); diff --git a/common/eth2/src/lib.rs b/common/eth2/src/lib.rs index 59d22d648..2a3e3242c 100644 --- a/common/eth2/src/lib.rs +++ b/common/eth2/src/lib.rs @@ -916,9 +916,8 @@ impl BeaconNodeHttpClient { Error, > { let path = self.get_beacon_blocks_path(block_id)?; - let response = match self.get_response(path, |b| b).await.optional()? { - Some(res) => res, - None => return Ok(None), + let Some(response) = self.get_response(path, |b| b).await.optional()? else { + return Ok(None); }; Ok(Some(response.json().await?)) @@ -932,9 +931,8 @@ impl BeaconNodeHttpClient { block_id: BlockId, ) -> Result>>, Error> { let path = self.get_blobs_path(block_id)?; - let response = match self.get_response(path, |b| b).await.optional()? { - Some(res) => res, - None => return Ok(None), + let Some(response) = self.get_response(path, |b| b).await.optional()? else { + return Ok(None); }; Ok(Some(response.json().await?)) @@ -951,9 +949,8 @@ impl BeaconNodeHttpClient { Error, > { let path = self.get_beacon_blinded_blocks_path(block_id)?; - let response = match self.get_response(path, |b| b).await.optional()? { - Some(res) => res, - None => return Ok(None), + let Some(response) = self.get_response(path, |b| b).await.optional()? else { + return Ok(None); }; Ok(Some(response.json().await?)) diff --git a/common/test_random_derive/src/lib.rs b/common/test_random_derive/src/lib.rs index 6c72ecb44..648c20121 100644 --- a/common/test_random_derive/src/lib.rs +++ b/common/test_random_derive/src/lib.rs @@ -20,9 +20,8 @@ pub fn test_random_derive(input: TokenStream) -> TokenStream { let name = &derived_input.ident; let (impl_generics, ty_generics, where_clause) = &derived_input.generics.split_for_impl(); - let struct_data = match &derived_input.data { - syn::Data::Struct(s) => s, - _ => panic!("test_random_derive only supports structs."), + let syn::Data::Struct(struct_data) = &derived_input.data else { + panic!("test_random_derive only supports structs."); }; // Build quotes for fields that should be generated and those that should be built from diff --git a/consensus/proto_array/src/proto_array.rs b/consensus/proto_array/src/proto_array.rs index 6b88e5e42..4726715a1 100644 --- a/consensus/proto_array/src/proto_array.rs +++ b/consensus/proto_array/src/proto_array.rs @@ -1035,13 +1035,11 @@ impl ProtoArray { .epoch .start_slot(E::slots_per_epoch()); - let mut node = if let Some(node) = self + let Some(mut node) = self .indices .get(&root) .and_then(|index| self.nodes.get(*index)) - { - node - } else { + else { // An unknown root is not a finalized descendant. This line can only // be reached if the user supplies a root that is not known to fork // choice. diff --git a/crypto/bls/src/impls/blst.rs b/crypto/bls/src/impls/blst.rs index bd28abff9..e831a175c 100644 --- a/crypto/bls/src/impls/blst.rs +++ b/crypto/bls/src/impls/blst.rs @@ -99,9 +99,8 @@ pub fn verify_signature_sets<'a>( // Aggregate all the public keys. // Public keys have already been checked for subgroup and infinity - let agg_pk = match blst_core::AggregatePublicKey::aggregate(&signing_keys, false) { - Ok(agg_pk) => agg_pk, - Err(_) => return false, + let Ok(agg_pk) = blst_core::AggregatePublicKey::aggregate(&signing_keys, false) else { + return false; }; pks.push(agg_pk.to_public_key()); } diff --git a/lighthouse/environment/src/lib.rs b/lighthouse/environment/src/lib.rs index 8e7c237a3..a1f6b26a9 100644 --- a/lighthouse/environment/src/lib.rs +++ b/lighthouse/environment/src/lib.rs @@ -254,12 +254,9 @@ impl EnvironmentBuilder { } // Disable file logging if no path is specified. - let path = match config.path { - Some(path) => path, - None => { - self.log = Some(stdout_logger); - return Ok(self); - } + let Some(path) = config.path else { + self.log = Some(stdout_logger); + return Ok(self); }; // Ensure directories are created becfore the logfile. diff --git a/slasher/src/array.rs b/slasher/src/array.rs index f3b11cccd..91c8f373f 100644 --- a/slasher/src/array.rs +++ b/slasher/src/array.rs @@ -159,9 +159,8 @@ pub trait TargetArrayChunk: Sized + serde::Serialize + serde::de::DeserializeOwn config: &Config, ) -> Result, Error> { let disk_key = config.disk_key(validator_chunk_index, chunk_index); - let chunk_bytes = match txn.get(Self::select_db(db), &disk_key.to_be_bytes())? { - Some(chunk_bytes) => chunk_bytes, - None => return Ok(None), + let Some(chunk_bytes) = txn.get(Self::select_db(db), &disk_key.to_be_bytes())? else { + return Ok(None); }; let chunk = bincode::deserialize_from(ZlibDecoder::new(chunk_bytes.borrow()))?; @@ -448,11 +447,9 @@ pub fn apply_attestation_for_validator( return Ok(slashing_status); } - let mut start_epoch = if let Some(start_epoch) = + let Some(mut start_epoch) = T::first_start_epoch(attestation.data.source.epoch, current_epoch, config) - { - start_epoch - } else { + else { return Ok(slashing_status); }; @@ -536,12 +533,10 @@ pub fn epoch_update_for_validator( current_epoch: Epoch, config: &Config, ) -> Result<(), Error> { - let previous_current_epoch = - if let Some(epoch) = db.get_current_epoch_for_validator(validator_index, txn)? { - epoch - } else { - return Ok(()); - }; + let Some(previous_current_epoch) = db.get_current_epoch_for_validator(validator_index, txn)? + else { + return Ok(()); + }; let mut epoch = previous_current_epoch; diff --git a/testing/ef_tests/src/cases/merkle_proof_validity.rs b/testing/ef_tests/src/cases/merkle_proof_validity.rs index 13c83a3b1..0ba2c9266 100644 --- a/testing/ef_tests/src/cases/merkle_proof_validity.rs +++ b/testing/ef_tests/src/cases/merkle_proof_validity.rs @@ -51,13 +51,10 @@ impl Case for MerkleProofValidity { fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> { let mut state = self.state.clone(); state.initialize_tree_hash_cache(); - let proof = match state.compute_merkle_proof(self.merkle_proof.leaf_index) { - Ok(proof) => proof, - Err(_) => { - return Err(Error::FailedToParseTest( - "Could not retrieve merkle proof".to_string(), - )) - } + let Ok(proof) = state.compute_merkle_proof(self.merkle_proof.leaf_index) else { + return Err(Error::FailedToParseTest( + "Could not retrieve merkle proof".to_string(), + )); }; let proof_len = proof.len(); let branch_len = self.merkle_proof.branch.len(); diff --git a/validator_client/src/doppelganger_service.rs b/validator_client/src/doppelganger_service.rs index 558b9e199..231cea86c 100644 --- a/validator_client/src/doppelganger_service.rs +++ b/validator_client/src/doppelganger_service.rs @@ -525,9 +525,7 @@ impl DoppelgangerService { } // Resolve the index from the server response back to a public key. - let pubkey = if let Some(pubkey) = indices_map.get(&response.index) { - pubkey - } else { + let Some(pubkey) = indices_map.get(&response.index) else { crit!( self.log, "Inconsistent indices map"; diff --git a/validator_client/src/duties_service/sync.rs b/validator_client/src/duties_service/sync.rs index 12623d346..de42fa587 100644 --- a/validator_client/src/duties_service/sync.rs +++ b/validator_client/src/duties_service/sync.rs @@ -607,9 +607,7 @@ pub async fn fill_in_aggregation_proofs( // Add to global storage (we add regularly so the proofs can be used ASAP). let sync_map = duties_service.sync_duties.committees.read(); - let committee_duties = if let Some(duties) = sync_map.get(&sync_committee_period) { - duties - } else { + let Some(committee_duties) = sync_map.get(&sync_committee_period) else { debug!( log, "Missing sync duties"; diff --git a/validator_client/src/sync_committee_service.rs b/validator_client/src/sync_committee_service.rs index e01bf09cf..8e904e5dd 100644 --- a/validator_client/src/sync_committee_service.rs +++ b/validator_client/src/sync_committee_service.rs @@ -158,13 +158,11 @@ impl SyncCommitteeService { .checked_sub(slot_duration / 3) .unwrap_or_else(|| Duration::from_secs(0)); - let slot_duties = if let Some(duties) = self + let Some(slot_duties) = self .duties_service .sync_duties .get_duties_for_slot::(slot, &self.duties_service.spec) - { - duties - } else { + else { debug!(log, "No duties known for slot {}", slot); return Ok(()); };