Rust clippy 1.87 lint fixes (#7471)

Fix clippy lints for `rustc` 1.87


  clippy complains about `BeaconChainError` being too large. I went on a bit of a boxing spree because of this. We may instead want to `Box` some of the `BeaconChainError` variants?
This commit is contained in:
Eitan Seri-Levi
2025-05-15 22:03:00 -07:00
committed by GitHub
parent c4182e362b
commit 268809a530
24 changed files with 223 additions and 195 deletions

View File

@@ -3241,13 +3241,14 @@ pub fn serve<T: BeaconChainTypes>(
let direction = dir.into();
let state = peer_info.connection_status().clone().into();
let state_matches = query.state.as_ref().is_none_or(|states| {
states.iter().any(|state_param| *state_param == state)
});
let direction_matches =
query.direction.as_ref().is_none_or(|directions| {
directions.iter().any(|dir_param| *dir_param == direction)
});
let state_matches = query
.state
.as_ref()
.is_none_or(|states| states.contains(&state));
let direction_matches = query
.direction
.as_ref()
.is_none_or(|directions| directions.contains(&direction));
if state_matches && direction_matches {
peers.push(api_types::PeerData {

View File

@@ -60,13 +60,13 @@ use types::{Attestation, EthSpec, ForkName, SingleAttestation};
pub enum Error {
Validation(AttestationError),
Publication,
ForkChoice(#[allow(dead_code)] BeaconChainError),
ForkChoice(#[allow(dead_code)] Box<BeaconChainError>),
AggregationPool(#[allow(dead_code)] AttestationError),
ReprocessDisabled,
ReprocessFull,
ReprocessTimeout,
InvalidJson(#[allow(dead_code)] serde_json::Error),
FailedConversion(#[allow(dead_code)] BeaconChainError),
FailedConversion(#[allow(dead_code)] Box<BeaconChainError>),
}
enum PublishAttestationResult {
@@ -164,7 +164,7 @@ fn verify_and_publish_attestation<T: BeaconChainTypes>(
}
if let Err(e) = fc_result {
Err(Error::ForkChoice(e))
Err(Error::ForkChoice(Box::new(e)))
} else if let Err(e) = naive_aggregation_result {
Err(Error::AggregationPool(e))
} else {
@@ -213,7 +213,7 @@ fn convert_to_attestation<'a, T: BeaconChainTypes>(
beacon_block_root,
}))
}
Err(e) => Err(Error::FailedConversion(e)),
Err(e) => Err(Error::FailedConversion(Box::new(e))),
}
}
}

View File

@@ -123,8 +123,9 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
"Signed block published to network via HTTP API"
);
crate::publish_pubsub_message(&sender, PubsubMessage::BeaconBlock(block.clone()))
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?;
crate::publish_pubsub_message(&sender, PubsubMessage::BeaconBlock(block.clone())).map_err(
|_| BlockError::BeaconChainError(Box::new(BeaconChainError::UnableToPublish)),
)?;
Ok(())
};
@@ -506,7 +507,7 @@ fn publish_blob_sidecars<T: BeaconChainTypes>(
) -> Result<(), BlockError> {
let pubsub_message = PubsubMessage::BlobSidecar(Box::new((blob.index(), blob.clone_blob())));
crate::publish_pubsub_message(sender_clone, pubsub_message)
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))
.map_err(|_| BlockError::BeaconChainError(Box::new(BeaconChainError::UnableToPublish)))
}
fn publish_column_sidecars<T: BeaconChainTypes>(
@@ -536,7 +537,7 @@ fn publish_column_sidecars<T: BeaconChainTypes>(
})
.collect::<Vec<_>>();
crate::publish_pubsub_messages(sender_clone, pubsub_messages)
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))
.map_err(|_| BlockError::BeaconChainError(Box::new(BeaconChainError::UnableToPublish)))
}
async fn post_block_import_logging_and_response<T: BeaconChainTypes>(
@@ -593,7 +594,9 @@ async fn post_block_import_logging_and_response<T: BeaconChainTypes>(
Err(warp_utils::reject::custom_bad_request(msg))
}
}
Err(BlockError::BeaconChainError(BeaconChainError::UnableToPublish)) => {
Err(BlockError::BeaconChainError(e))
if matches!(e.as_ref(), BeaconChainError::UnableToPublish) =>
{
Err(warp_utils::reject::custom_server_error(
"unable to publish to network channel".to_string(),
))
@@ -789,7 +792,7 @@ fn check_slashable<T: BeaconChainTypes>(
block_clone.message().proposer_index(),
block_root,
)
.map_err(|e| BlockError::BeaconChainError(e.into()))?
.map_err(|e| BlockError::BeaconChainError(Box::new(e.into())))?
{
warn!(
slot = %block_clone.slot(),

View File

@@ -59,7 +59,7 @@ pub fn sync_committee_duties<T: BeaconChainTypes>(
}
let duties = duties_from_state_load(request_epoch, request_indices, altair_fork_epoch, chain)
.map_err(|e| match e {
.map_err(|e| match *e {
BeaconChainError::SyncDutiesError(BeaconStateError::SyncCommitteeNotKnown {
current_epoch,
..
@@ -81,7 +81,7 @@ fn duties_from_state_load<T: BeaconChainTypes>(
request_indices: &[u64],
altair_fork_epoch: Epoch,
chain: &BeaconChain<T>,
) -> Result<Vec<Result<Option<SyncDuty>, BeaconStateError>>, BeaconChainError> {
) -> Result<Vec<Result<Option<SyncDuty>, BeaconStateError>>, Box<BeaconChainError>> {
// Determine what the current epoch would be if we fast-forward our system clock by
// `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
//
@@ -92,11 +92,17 @@ fn duties_from_state_load<T: BeaconChainTypes>(
let tolerant_current_epoch = chain
.slot_clock
.now_with_future_tolerance(chain.spec.maximum_gossip_clock_disparity())
.ok_or(BeaconChainError::UnableToReadSlot)?
.ok_or(BeaconChainError::UnableToReadSlot)
.map_err(Box::new)?
.epoch(T::EthSpec::slots_per_epoch());
let max_sync_committee_period = tolerant_current_epoch.sync_committee_period(&chain.spec)? + 1;
let sync_committee_period = request_epoch.sync_committee_period(&chain.spec)?;
let max_sync_committee_period = tolerant_current_epoch
.sync_committee_period(&chain.spec)
.map_err(|e| Box::new(e.into()))?
+ 1;
let sync_committee_period = request_epoch
.sync_committee_period(&chain.spec)
.map_err(|e| Box::new(e.into()))?;
if tolerant_current_epoch < altair_fork_epoch {
// Empty response if the epoch is pre-Altair.
@@ -119,13 +125,14 @@ fn duties_from_state_load<T: BeaconChainTypes>(
state
.get_sync_committee_duties(request_epoch, request_indices, &chain.spec)
.map_err(BeaconChainError::SyncDutiesError)
.map_err(Box::new)
} else {
Err(BeaconChainError::SyncDutiesError(
Err(Box::new(BeaconChainError::SyncDutiesError(
BeaconStateError::SyncCommitteeNotKnown {
current_epoch,
epoch: request_epoch,
},
))
)))
}
}

View File

@@ -7,9 +7,10 @@ pub fn pubkey_to_validator_index<T: BeaconChainTypes>(
chain: &BeaconChain<T>,
state: &BeaconState<T::EthSpec>,
pubkey: &PublicKeyBytes,
) -> Result<Option<usize>, BeaconChainError> {
) -> Result<Option<usize>, Box<BeaconChainError>> {
chain
.validator_index(pubkey)?
.validator_index(pubkey)
.map_err(Box::new)?
.filter(|&index| {
state
.validators()