Skip to content

Commit

Permalink
Rust 1.84 lints (#6781)
Browse files Browse the repository at this point in the history
* Fix few lints

* Fix remaining lints

* Use fully qualified syntax
  • Loading branch information
pawanjay176 authored Jan 10, 2025
1 parent 87b72de commit 1f6850f
Show file tree
Hide file tree
Showing 61 changed files with 110 additions and 138 deletions.
10 changes: 5 additions & 5 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.start_slot(T::EthSpec::slots_per_epoch());
let is_canonical = self
.block_root_at_slot(block_slot, WhenSlotSkipped::None)?
.map_or(false, |canonical_root| block_root == &canonical_root);
.is_some_and(|canonical_root| block_root == &canonical_root);
Ok(block_slot <= finalized_slot && is_canonical)
}

Expand Down Expand Up @@ -604,7 +604,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let slot_is_finalized = state_slot <= finalized_slot;
let canonical = self
.state_root_at_slot(state_slot)?
.map_or(false, |canonical_root| state_root == &canonical_root);
.is_some_and(|canonical_root| state_root == &canonical_root);
Ok(FinalizationAndCanonicity {
slot_is_finalized,
canonical,
Expand Down Expand Up @@ -5118,9 +5118,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.start_of(slot)
.unwrap_or_else(|| Duration::from_secs(0)),
);
block_delays.observed.map_or(false, |delay| {
delay >= self.slot_clock.unagg_attestation_production_delay()
})
block_delays
.observed
.is_some_and(|delay| delay >= self.slot_clock.unagg_attestation_production_delay())
}

/// Produce a block for some `slot` upon the given `state`.
Expand Down
6 changes: 1 addition & 5 deletions beacon_node/beacon_chain/src/canonical_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,11 +1254,7 @@ pub fn find_reorg_slot<E: EthSpec>(
($state: ident, $block_root: ident) => {
std::iter::once(Ok(($state.slot(), $block_root)))
.chain($state.rev_iter_block_roots(spec))
.skip_while(|result| {
result
.as_ref()
.map_or(false, |(slot, _)| *slot > lowest_slot)
})
.skip_while(|result| result.as_ref().is_ok_and(|(slot, _)| *slot > lowest_slot))
};
}

Expand Down
6 changes: 3 additions & 3 deletions beacon_node/beacon_chain/src/data_availability_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,13 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
/// Returns true if the given epoch lies within the da boundary and false otherwise.
pub fn da_check_required_for_epoch(&self, block_epoch: Epoch) -> bool {
self.data_availability_boundary()
.map_or(false, |da_epoch| block_epoch >= da_epoch)
.is_some_and(|da_epoch| block_epoch >= da_epoch)
}

/// Returns `true` if the current epoch is greater than or equal to the `Deneb` epoch.
pub fn is_deneb(&self) -> bool {
self.slot_clock.now().map_or(false, |slot| {
self.spec.deneb_fork_epoch.map_or(false, |deneb_epoch| {
self.slot_clock.now().is_some_and(|slot| {
self.spec.deneb_fork_epoch.is_some_and(|deneb_epoch| {
let now_epoch = slot.epoch(T::EthSpec::slots_per_epoch());
now_epoch >= deneb_epoch
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,10 @@ impl<E: EthSpec> PendingComponents<E> {
);

let all_blobs_received = block_kzg_commitments_count_opt
.map_or(false, |num_expected_blobs| {
num_expected_blobs == num_received_blobs
});
.is_some_and(|num_expected_blobs| num_expected_blobs == num_received_blobs);

let all_columns_received = expected_columns_opt.map_or(false, |num_expected_columns| {
num_expected_columns == num_received_columns
});
let all_columns_received = expected_columns_opt
.is_some_and(|num_expected_columns| num_expected_columns == num_received_columns);

all_blobs_received || all_columns_received
}
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/early_attester_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<E: EthSpec> EarlyAttesterCache<E> {
self.item
.read()
.as_ref()
.map_or(false, |item| item.beacon_block_root == block_root)
.is_some_and(|item| item.beacon_block_root == block_root)
}

/// Returns the block, if `block_root` matches the cached item.
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/eth1_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn get_sync_status<E: EthSpec>(
// Lighthouse is "cached and ready" when it has cached enough blocks to cover the start of the
// current voting period.
let lighthouse_is_cached_and_ready =
latest_cached_block_timestamp.map_or(false, |t| t >= voting_target_timestamp);
latest_cached_block_timestamp.is_some_and(|t| t >= voting_target_timestamp);

Some(Eth1SyncStatusData {
head_block_number,
Expand Down
8 changes: 4 additions & 4 deletions beacon_node/beacon_chain/src/execution_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ impl<T: BeaconChainTypes> PayloadNotifier<T> {
/// contains a few extra checks by running `partially_verify_execution_payload` first:
///
/// https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/bellatrix/beacon-chain.md#notify_new_payload
async fn notify_new_payload<'a, T: BeaconChainTypes>(
async fn notify_new_payload<T: BeaconChainTypes>(
chain: &Arc<BeaconChain<T>>,
block: BeaconBlockRef<'a, T::EthSpec>,
block: BeaconBlockRef<'_, T::EthSpec>,
) -> Result<PayloadVerificationStatus, BlockError> {
let execution_layer = chain
.execution_layer
Expand Down Expand Up @@ -230,9 +230,9 @@ async fn notify_new_payload<'a, T: BeaconChainTypes>(
/// Equivalent to the `validate_merge_block` function in the merge Fork Choice Changes:
///
/// https://github.com/ethereum/consensus-specs/blob/v1.1.5/specs/merge/fork-choice.md#validate_merge_block
pub async fn validate_merge_block<'a, T: BeaconChainTypes>(
pub async fn validate_merge_block<T: BeaconChainTypes>(
chain: &Arc<BeaconChain<T>>,
block: BeaconBlockRef<'a, T::EthSpec>,
block: BeaconBlockRef<'_, T::EthSpec>,
allow_optimistic_import: AllowOptimisticImport,
) -> Result<(), BlockError> {
let spec = &chain.spec;
Expand Down
7 changes: 2 additions & 5 deletions beacon_node/beacon_chain/src/graffiti_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,7 @@ mod tests {
.await
.unwrap();

let version_bytes = std::cmp::min(
lighthouse_version::VERSION.as_bytes().len(),
GRAFFITI_BYTES_LEN,
);
let version_bytes = std::cmp::min(lighthouse_version::VERSION.len(), GRAFFITI_BYTES_LEN);
// grab the slice of the graffiti that corresponds to the lighthouse version
let graffiti_slice =
&harness.chain.graffiti_calculator.get_graffiti(None).await.0[..version_bytes];
Expand Down Expand Up @@ -361,7 +358,7 @@ mod tests {

let graffiti_str = "nice graffiti bro";
let mut graffiti_bytes = [0u8; GRAFFITI_BYTES_LEN];
graffiti_bytes[..graffiti_str.as_bytes().len()].copy_from_slice(graffiti_str.as_bytes());
graffiti_bytes[..graffiti_str.len()].copy_from_slice(graffiti_str.as_bytes());

let found_graffiti = harness
.chain
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/observed_aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<I> SlotHashSet<I> {
Ok(self
.map
.get(&root)
.map_or(false, |agg| agg.iter().any(|val| item.is_subset(val))))
.is_some_and(|agg| agg.iter().any(|val| item.is_subset(val))))
}

/// The number of observed items in `self`.
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/observed_attesters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Item<()> for EpochBitfield {
fn get(&self, validator_index: usize) -> Option<()> {
self.bitfield
.get(validator_index)
.map_or(false, |bit| *bit)
.is_some_and(|bit| *bit)
.then_some(())
}
}
Expand Down Expand Up @@ -336,7 +336,7 @@ impl<T: Item<()>, E: EthSpec> AutoPruningEpochContainer<T, E> {
let exists = self
.items
.get(&epoch)
.map_or(false, |item| item.get(validator_index).is_some());
.is_some_and(|item| item.get(validator_index).is_some());

Ok(exists)
}
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/observed_data_sidecars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<T: ObservableDataSidecar> ObservedDataSidecars<T> {
slot: data_sidecar.slot(),
proposer: data_sidecar.block_proposer_index(),
})
.map_or(false, |indices| indices.contains(&data_sidecar.index()));
.is_some_and(|indices| indices.contains(&data_sidecar.index()));
Ok(is_known)
}

Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/shuffling_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl BlockShufflingIds {
} else if self
.previous
.as_ref()
.map_or(false, |id| id.shuffling_epoch == epoch)
.is_some_and(|id| id.shuffling_epoch == epoch)
{
self.previous.clone()
} else if epoch == self.next.shuffling_epoch {
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ impl<E: EthSpec> BeaconProcessor<E> {
let can_spawn = self.current_workers < self.config.max_workers;
let drop_during_sync = work_event
.as_ref()
.map_or(false, |event| event.drop_during_sync);
.is_some_and(|event| event.drop_during_sync);

let idle_tx = idle_tx.clone();
let modified_queue_id = match work_event {
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ where
.forkchoice_update_parameters();
if params
.head_hash
.map_or(false, |hash| hash != ExecutionBlockHash::zero())
.is_some_and(|hash| hash != ExecutionBlockHash::zero())
{
// Spawn a new task to update the EE without waiting for it to complete.
let inner_chain = beacon_chain.clone();
Expand Down
8 changes: 3 additions & 5 deletions beacon_node/client/src/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
);

let speed = speedo.slots_per_second();
let display_speed = speed.map_or(false, |speed| speed != 0.0);
let display_speed = speed.is_some_and(|speed| speed != 0.0);

if display_speed {
info!(
Expand Down Expand Up @@ -233,7 +233,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
);

let speed = speedo.slots_per_second();
let display_speed = speed.map_or(false, |speed| speed != 0.0);
let display_speed = speed.is_some_and(|speed| speed != 0.0);

if display_speed {
info!(
Expand Down Expand Up @@ -339,9 +339,7 @@ async fn bellatrix_readiness_logging<T: BeaconChainTypes>(
.message()
.body()
.execution_payload()
.map_or(false, |payload| {
payload.parent_hash() != ExecutionBlockHash::zero()
});
.is_ok_and(|payload| payload.parent_hash() != ExecutionBlockHash::zero());

let has_execution_layer = beacon_chain.execution_layer.is_some();

Expand Down
10 changes: 4 additions & 6 deletions beacon_node/execution_layer/src/engine_api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ pub mod deposit_log {
};

let signature_is_valid = deposit_pubkey_signature_message(&deposit_data, spec)
.map_or(false, |(public_key, signature, msg)| {
signature.verify(&public_key, msg)
});
.is_some_and(|(public_key, signature, msg)| signature.verify(&public_key, msg));

Ok(DepositLog {
deposit_data,
Expand Down Expand Up @@ -592,7 +590,7 @@ impl<T: Clone> CachedResponse<T> {

/// returns `true` if the entry's age is >= age_limit
pub fn older_than(&self, age_limit: Option<Duration>) -> bool {
age_limit.map_or(false, |limit| self.age() >= limit)
age_limit.is_some_and(|limit| self.age() >= limit)
}
}

Expand Down Expand Up @@ -720,9 +718,9 @@ impl HttpJsonRpc {
.await
}

pub async fn get_block_by_number<'a>(
pub async fn get_block_by_number(
&self,
query: BlockByNumberQuery<'a>,
query: BlockByNumberQuery<'_>,
) -> Result<Option<ExecutionBlock>, Error> {
let params = json!([query, RETURN_FULL_TRANSACTION_OBJECTS]);

Expand Down
2 changes: 1 addition & 1 deletion beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,7 @@ fn verify_builder_bid<E: EthSpec>(
payload: header.timestamp(),
expected: payload_attributes.timestamp(),
}))
} else if block_number.map_or(false, |n| n != header.block_number()) {
} else if block_number.is_some_and(|n| n != header.block_number()) {
Err(Box::new(InvalidBuilderPayload::BlockNumber {
payload: header.block_number(),
expected: block_number,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/execution_layer/src/payload_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn process_payload_status(
PayloadStatusV1Status::Valid => {
if response
.latest_valid_hash
.map_or(false, |h| h == head_block_hash)
.is_some_and(|h| h == head_block_hash)
{
// The response is only valid if `latest_valid_hash` is not `null` and
// equal to the provided `block_hash`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<E: EthSpec> MockExecutionLayer<E> {
(self, block_hash)
}

pub async fn with_terminal_block<'a, U, V>(self, func: U) -> Self
pub async fn with_terminal_block<U, V>(self, func: U) -> Self
where
U: Fn(ChainSpec, ExecutionLayer<E>, Option<ExecutionBlock>) -> V,
V: Future<Output = ()>,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/genesis/src/eth1_genesis_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl Eth1GenesisService {

// Ignore any block that has already been processed or update the highest processed
// block.
if highest_processed_block.map_or(false, |highest| highest >= block.number) {
if highest_processed_block.is_some_and(|highest| highest >= block.number) {
continue;
} else {
self.stats
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ pub fn serve<T: BeaconChainTypes>(
.map_err(warp_utils::reject::beacon_chain_error)?
// Ignore any skip-slots immediately following the parent.
.find(|res| {
res.as_ref().map_or(false, |(root, _)| *root != parent_root)
res.as_ref().is_ok_and(|(root, _)| *root != parent_root)
})
.transpose()
.map_err(warp_utils::reject::beacon_chain_error)?
Expand Down Expand Up @@ -1249,7 +1249,7 @@ pub fn serve<T: BeaconChainTypes>(
let canonical = chain
.block_root_at_slot(block.slot(), WhenSlotSkipped::None)
.map_err(warp_utils::reject::beacon_chain_error)?
.map_or(false, |canonical| root == canonical);
.is_some_and(|canonical| root == canonical);

let data = api_types::BlockHeaderData {
root,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn pubkey_to_validator_index<T: BeaconChainTypes>(
state
.validators()
.get(index)
.map_or(false, |v| v.pubkey == *pubkey)
.is_some_and(|v| v.pubkey == *pubkey)
})
.map(Result::Ok)
.transpose()
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/tests/interactive_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl ForkChoiceUpdates {
update
.payload_attributes
.as_ref()
.map_or(false, |payload_attributes| {
.is_some_and(|payload_attributes| {
payload_attributes.timestamp() == proposal_timestamp
})
})
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ impl ApiTester {
.chain
.block_root_at_slot(block.slot(), WhenSlotSkipped::None)
.unwrap()
.map_or(false, |canonical| block_root == canonical);
.is_some_and(|canonical| block_root == canonical);

assert_eq!(result.canonical, canonical, "{:?}", block_id);
assert_eq!(result.root, block_root, "{:?}", block_id);
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/lighthouse_network/gossipsub/src/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl BackoffStorage {
pub(crate) fn is_backoff_with_slack(&self, topic: &TopicHash, peer: &PeerId) -> bool {
self.backoffs
.get(topic)
.map_or(false, |m| m.contains_key(peer))
.is_some_and(|m| m.contains_key(peer))
}

pub(crate) fn get_backoff_time(&self, topic: &TopicHash, peer: &PeerId) -> Option<Instant> {
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/lighthouse_network/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,8 +1770,7 @@ where
// reject messages claiming to be from ourselves but not locally published
let self_published = !self.config.allow_self_origin()
&& if let Some(own_id) = self.publish_config.get_own_id() {
own_id != propagation_source
&& raw_message.source.as_ref().map_or(false, |s| s == own_id)
own_id != propagation_source && raw_message.source.as_ref() == Some(own_id)
} else {
self.published_message_ids.contains(msg_id)
};
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/lighthouse_network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl Config {
tcp_port,
});
self.discv5_config.listen_config = discv5::ListenConfig::from_ip(addr.into(), disc_port);
self.discv5_config.table_filter = |enr| enr.ip4().as_ref().map_or(false, is_global_ipv4)
self.discv5_config.table_filter = |enr| enr.ip4().as_ref().is_some_and(is_global_ipv4)
}

/// Sets the listening address to use an ipv6 address. The discv5 ip_mode and table filter is
Expand All @@ -187,7 +187,7 @@ impl Config {
});

self.discv5_config.listen_config = discv5::ListenConfig::from_ip(addr.into(), disc_port);
self.discv5_config.table_filter = |enr| enr.ip6().as_ref().map_or(false, is_global_ipv6)
self.discv5_config.table_filter = |enr| enr.ip6().as_ref().is_some_and(is_global_ipv6)
}

/// Sets the listening address to use both an ipv4 and ipv6 address. The discv5 ip_mode and
Expand Down Expand Up @@ -317,7 +317,7 @@ impl Default for Config {
.filter_rate_limiter(filter_rate_limiter)
.filter_max_bans_per_ip(Some(5))
.filter_max_nodes_per_ip(Some(10))
.table_filter(|enr| enr.ip4().map_or(false, |ip| is_global_ipv4(&ip))) // Filter non-global IPs
.table_filter(|enr| enr.ip4().is_some_and(|ip| is_global_ipv4(&ip))) // Filter non-global IPs
.ban_duration(Some(Duration::from_secs(3600)))
.ping_interval(Duration::from_secs(300))
.build();
Expand Down
Loading

0 comments on commit 1f6850f

Please sign in to comment.