Activate clippy::manual_let_else lint (#4889)

## Issue Addressed

#4888

## Proposed Changes

Enabled `clippy::manual_let_else` lint and resolved the warning messages.
This commit is contained in:
Eitan Seri-Levi
2023-10-31 10:31:02 +00:00
parent a9f9dc241d
commit 4ce01ddd11
35 changed files with 185 additions and 286 deletions

View File

@@ -350,17 +350,14 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
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,

View File

@@ -115,34 +115,31 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
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.

View File

@@ -509,16 +509,13 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
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<T: BeaconChainTypes> BackFillSync<T> {
network: &mut SyncNetworkContext<T>,
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

View File

@@ -1015,15 +1015,12 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
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<T: BeaconChainTypes> BlockLookups<T> {
result: BatchProcessResult,
cx: &SyncNetworkContext<T>,
) {
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);

View File

@@ -294,19 +294,15 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
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<T: BeaconChainTypes> SyncingChain<T> {
network: &mut SyncNetworkContext<T>,
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