Skip to content

Commit 268809a

Browse files
authored
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?
1 parent c4182e3 commit 268809a

File tree

24 files changed

+223
-195
lines changed

24 files changed

+223
-195
lines changed

beacon_node/beacon_chain/src/attestation_verification.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ pub enum Error {
272272
///
273273
/// We were unable to process this attestation due to an internal error. It's unclear if the
274274
/// attestation is valid.
275-
BeaconChainError(BeaconChainError),
275+
BeaconChainError(Box<BeaconChainError>),
276276
}
277277

278278
impl From<BeaconChainError> for Error {
279279
fn from(e: BeaconChainError) -> Self {
280-
Self::BeaconChainError(e)
280+
Self::BeaconChainError(Box::new(e))
281281
}
282282
}
283283

@@ -525,7 +525,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
525525
.observed_attestations
526526
.write()
527527
.is_known_subset(attestation, observed_attestation_key_root)
528-
.map_err(|e| Error::BeaconChainError(e.into()))?
528+
.map_err(|e| Error::BeaconChainError(Box::new(e.into())))?
529529
{
530530
metrics::inc_counter(&metrics::AGGREGATED_ATTESTATION_SUBSETS);
531531
return Err(Error::AttestationSupersetKnown(
@@ -628,7 +628,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
628628

629629
if !SelectionProof::from(selection_proof)
630630
.is_aggregator(committee.committee.len(), &chain.spec)
631-
.map_err(|e| Error::BeaconChainError(e.into()))?
631+
.map_err(|e| Error::BeaconChainError(Box::new(e.into())))?
632632
{
633633
return Err(Error::InvalidSelectionProof { aggregator_index });
634634
}
@@ -698,7 +698,7 @@ impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
698698
.observed_attestations
699699
.write()
700700
.observe_item(attestation, Some(observed_attestation_key_root))
701-
.map_err(|e| Error::BeaconChainError(e.into()))?
701+
.map_err(|e| Error::BeaconChainError(Box::new(e.into())))?
702702
{
703703
metrics::inc_counter(&metrics::AGGREGATED_ATTESTATION_SUBSETS);
704704
return Err(Error::AttestationSupersetKnown(

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
27332733
pub fn filter_chain_segment(
27342734
self: &Arc<Self>,
27352735
chain_segment: Vec<RpcBlock<T::EthSpec>>,
2736-
) -> Result<Vec<HashBlockTuple<T::EthSpec>>, ChainSegmentResult> {
2736+
) -> Result<Vec<HashBlockTuple<T::EthSpec>>, Box<ChainSegmentResult>> {
27372737
// This function will never import any blocks.
27382738
let imported_blocks = vec![];
27392739
let mut filtered_chain_segment = Vec::with_capacity(chain_segment.len());
@@ -2750,10 +2750,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
27502750
for (i, block) in chain_segment.into_iter().enumerate() {
27512751
// Ensure the block is the correct structure for the fork at `block.slot()`.
27522752
if let Err(e) = block.as_block().fork_name(&self.spec) {
2753-
return Err(ChainSegmentResult::Failed {
2753+
return Err(Box::new(ChainSegmentResult::Failed {
27542754
imported_blocks,
27552755
error: BlockError::InconsistentFork(e),
2756-
});
2756+
}));
27572757
}
27582758

27592759
let block_root = block.block_root();
@@ -2765,18 +2765,18 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
27652765
// Without this check it would be possible to have a block verified using the
27662766
// incorrect shuffling. That would be bad, mmkay.
27672767
if block_root != *child_parent_root {
2768-
return Err(ChainSegmentResult::Failed {
2768+
return Err(Box::new(ChainSegmentResult::Failed {
27692769
imported_blocks,
27702770
error: BlockError::NonLinearParentRoots,
2771-
});
2771+
}));
27722772
}
27732773

27742774
// Ensure that the slots are strictly increasing throughout the chain segment.
27752775
if *child_slot <= block.slot() {
2776-
return Err(ChainSegmentResult::Failed {
2776+
return Err(Box::new(ChainSegmentResult::Failed {
27772777
imported_blocks,
27782778
error: BlockError::NonLinearSlots,
2779-
});
2779+
}));
27802780
}
27812781
}
27822782

@@ -2807,18 +2807,18 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
28072807
// The block has a known parent that does not descend from the finalized block.
28082808
// There is no need to process this block or any children.
28092809
Err(BlockError::NotFinalizedDescendant { block_parent_root }) => {
2810-
return Err(ChainSegmentResult::Failed {
2810+
return Err(Box::new(ChainSegmentResult::Failed {
28112811
imported_blocks,
28122812
error: BlockError::NotFinalizedDescendant { block_parent_root },
2813-
});
2813+
}));
28142814
}
28152815
// If there was an error whilst determining if the block was invalid, return that
28162816
// error.
28172817
Err(BlockError::BeaconChainError(e)) => {
2818-
return Err(ChainSegmentResult::Failed {
2818+
return Err(Box::new(ChainSegmentResult::Failed {
28192819
imported_blocks,
28202820
error: BlockError::BeaconChainError(e),
2821-
});
2821+
}));
28222822
}
28232823
// If the block was decided to be irrelevant for any other reason, don't include
28242824
// this block or any of it's children in the filtered chain segment.
@@ -2863,11 +2863,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
28632863
);
28642864
let mut filtered_chain_segment = match filtered_chain_segment_future.await {
28652865
Ok(Ok(filtered_segment)) => filtered_segment,
2866-
Ok(Err(segment_result)) => return segment_result,
2866+
Ok(Err(segment_result)) => return *segment_result,
28672867
Err(error) => {
28682868
return ChainSegmentResult::Failed {
28692869
imported_blocks,
2870-
error: BlockError::BeaconChainError(error),
2870+
error: BlockError::BeaconChainError(error.into()),
28712871
}
28722872
}
28732873
};
@@ -2906,7 +2906,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
29062906
Err(error) => {
29072907
return ChainSegmentResult::Failed {
29082908
imported_blocks,
2909-
error: BlockError::BeaconChainError(error),
2909+
error: BlockError::BeaconChainError(error.into()),
29102910
};
29112911
}
29122912
};
@@ -3444,20 +3444,23 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
34443444

34453445
Ok(status)
34463446
}
3447-
Err(e @ BlockError::BeaconChainError(BeaconChainError::TokioJoin(_))) => {
3448-
debug!(
3449-
error = ?e,
3450-
"Beacon block processing cancelled"
3451-
);
3452-
Err(e)
3453-
}
3454-
// There was an error whilst attempting to verify and import the block. The block might
3455-
// be partially verified or partially imported.
34563447
Err(BlockError::BeaconChainError(e)) => {
3457-
crit!(
3458-
error = ?e,
3459-
"Beacon block processing error"
3460-
);
3448+
match e.as_ref() {
3449+
BeaconChainError::TokioJoin(e) => {
3450+
debug!(
3451+
error = ?e,
3452+
"Beacon block processing cancelled"
3453+
);
3454+
}
3455+
_ => {
3456+
// There was an error whilst attempting to verify and import the block. The block might
3457+
// be partially verified or partially imported.
3458+
crit!(
3459+
error = ?e,
3460+
"Beacon block processing error"
3461+
);
3462+
}
3463+
};
34613464
Err(BlockError::BeaconChainError(e))
34623465
}
34633466
// The block failed verification.
@@ -3589,7 +3592,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
35893592
header.message.proposer_index,
35903593
block_root,
35913594
)
3592-
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
3595+
.map_err(|e| BlockError::BeaconChainError(Box::new(e.into())))?;
35933596
if let Some(slasher) = self.slasher.as_ref() {
35943597
slasher.accept_block_header(header);
35953598
}
@@ -3674,7 +3677,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
36743677
header.message.proposer_index,
36753678
block_root,
36763679
)
3677-
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
3680+
.map_err(|e| BlockError::BeaconChainError(Box::new(e.into())))?;
36783681
if let Some(slasher) = self.slasher.as_ref() {
36793682
slasher.accept_block_header(header.clone());
36803683
}
@@ -3857,7 +3860,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
38573860
payload_verification_status,
38583861
&self.spec,
38593862
)
3860-
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
3863+
.map_err(|e| BlockError::BeaconChainError(Box::new(e.into())))?;
38613864
}
38623865

38633866
// If the block is recent enough and it was not optimistically imported, check to see if it
@@ -4070,7 +4073,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40704073
warning = "The database is likely corrupt now, consider --purge-db",
40714074
"No stored fork choice found to restore from"
40724075
);
4073-
Err(BlockError::BeaconChainError(e))
4076+
Err(BlockError::BeaconChainError(Box::new(e)))
40744077
} else {
40754078
Ok(())
40764079
}
@@ -4125,9 +4128,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
41254128
Provided block root is not a checkpoint.",
41264129
))
41274130
.map_err(|err| {
4128-
BlockError::BeaconChainError(
4131+
BlockError::BeaconChainError(Box::new(
41294132
BeaconChainError::WeakSubjectivtyShutdownError(err),
4130-
)
4133+
))
41314134
})?;
41324135
return Err(BlockError::WeakSubjectivityConflict);
41334136
}
@@ -4901,7 +4904,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
49014904
canonical_forkchoice_params: ForkchoiceUpdateParameters,
49024905
) -> Result<ForkchoiceUpdateParameters, Error> {
49034906
self.overridden_forkchoice_update_params_or_failure_reason(&canonical_forkchoice_params)
4904-
.or_else(|e| match e {
4907+
.or_else(|e| match *e {
49054908
ProposerHeadError::DoNotReOrg(reason) => {
49064909
trace!(
49074910
%reason,
@@ -4916,19 +4919,19 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
49164919
pub fn overridden_forkchoice_update_params_or_failure_reason(
49174920
&self,
49184921
canonical_forkchoice_params: &ForkchoiceUpdateParameters,
4919-
) -> Result<ForkchoiceUpdateParameters, ProposerHeadError<Error>> {
4922+
) -> Result<ForkchoiceUpdateParameters, Box<ProposerHeadError<Error>>> {
49204923
let _timer = metrics::start_timer(&metrics::FORK_CHOICE_OVERRIDE_FCU_TIMES);
49214924

49224925
// Never override if proposer re-orgs are disabled.
49234926
let re_org_head_threshold = self
49244927
.config
49254928
.re_org_head_threshold
4926-
.ok_or(DoNotReOrg::ReOrgsDisabled)?;
4929+
.ok_or(Box::new(DoNotReOrg::ReOrgsDisabled.into()))?;
49274930

49284931
let re_org_parent_threshold = self
49294932
.config
49304933
.re_org_parent_threshold
4931-
.ok_or(DoNotReOrg::ReOrgsDisabled)?;
4934+
.ok_or(Box::new(DoNotReOrg::ReOrgsDisabled.into()))?;
49324935

49334936
let head_block_root = canonical_forkchoice_params.head_root;
49344937

@@ -4969,7 +4972,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
49694972
false
49704973
};
49714974
if !current_slot_ok {
4972-
return Err(DoNotReOrg::HeadDistance.into());
4975+
return Err(Box::new(DoNotReOrg::HeadDistance.into()));
49734976
}
49744977

49754978
// Only attempt a re-org if we have a proposer registered for the re-org slot.
@@ -4992,7 +4995,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
49924995
decision_root = ?shuffling_decision_root,
49934996
"Fork choice override proposer shuffling miss"
49944997
);
4995-
DoNotReOrg::NotProposing
4998+
Box::new(DoNotReOrg::NotProposing.into())
49964999
})?
49975000
.index as u64;
49985001

@@ -5002,7 +5005,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
50025005
.has_proposer_preparation_data_blocking(proposer_index)
50035006
};
50045007
if !proposing_at_re_org_slot {
5005-
return Err(DoNotReOrg::NotProposing.into());
5008+
return Err(Box::new(DoNotReOrg::NotProposing.into()));
50065009
}
50075010

50085011
// If the current slot is already equal to the proposal slot (or we are in the tail end of
@@ -5017,18 +5020,22 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
50175020
(true, true)
50185021
};
50195022
if !head_weak {
5020-
return Err(DoNotReOrg::HeadNotWeak {
5021-
head_weight: info.head_node.weight,
5022-
re_org_head_weight_threshold: info.re_org_head_weight_threshold,
5023-
}
5024-
.into());
5023+
return Err(Box::new(
5024+
DoNotReOrg::HeadNotWeak {
5025+
head_weight: info.head_node.weight,
5026+
re_org_head_weight_threshold: info.re_org_head_weight_threshold,
5027+
}
5028+
.into(),
5029+
));
50255030
}
50265031
if !parent_strong {
5027-
return Err(DoNotReOrg::ParentNotStrong {
5028-
parent_weight: info.parent_node.weight,
5029-
re_org_parent_weight_threshold: info.re_org_parent_weight_threshold,
5030-
}
5031-
.into());
5032+
return Err(Box::new(
5033+
DoNotReOrg::ParentNotStrong {
5034+
parent_weight: info.parent_node.weight,
5035+
re_org_parent_weight_threshold: info.re_org_parent_weight_threshold,
5036+
}
5037+
.into(),
5038+
));
50325039
}
50335040

50345041
// Check that the head block arrived late and is vulnerable to a re-org. This check is only
@@ -5039,7 +5046,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
50395046
let head_block_late =
50405047
self.block_observed_after_attestation_deadline(head_block_root, head_slot);
50415048
if !head_block_late {
5042-
return Err(DoNotReOrg::HeadNotLate.into());
5049+
return Err(Box::new(DoNotReOrg::HeadNotLate.into()));
50435050
}
50445051

50455052
let parent_head_hash = info.parent_node.execution_status.block_hash();
@@ -5253,16 +5260,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
52535260
.validators()
52545261
.get(proposer_index as usize)
52555262
.map(|v| v.pubkey)
5256-
.ok_or(BlockProductionError::BeaconChain(
5263+
.ok_or(BlockProductionError::BeaconChain(Box::new(
52575264
BeaconChainError::ValidatorIndexUnknown(proposer_index as usize),
5258-
))?;
5265+
)))?;
52595266

52605267
let builder_params = BuilderParams {
52615268
pubkey,
52625269
slot: state.slot(),
52635270
chain_health: self
52645271
.is_healthy(&parent_root)
5265-
.map_err(BlockProductionError::BeaconChain)?,
5272+
.map_err(|e| BlockProductionError::BeaconChain(Box::new(e)))?,
52665273
};
52675274

52685275
// If required, start the process of loading an execution payload from the EL early. This

beacon_node/beacon_chain/src/blob_verification.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub enum GossipBlobError {
4242
///
4343
/// We were unable to process this blob due to an internal error. It's
4444
/// unclear if the blob is valid.
45-
BeaconChainError(BeaconChainError),
45+
BeaconChainError(Box<BeaconChainError>),
4646

4747
/// The `BlobSidecar` was gossiped over an incorrect subnet.
4848
///
@@ -147,13 +147,13 @@ impl std::fmt::Display for GossipBlobError {
147147

148148
impl From<BeaconChainError> for GossipBlobError {
149149
fn from(e: BeaconChainError) -> Self {
150-
GossipBlobError::BeaconChainError(e)
150+
GossipBlobError::BeaconChainError(e.into())
151151
}
152152
}
153153

154154
impl From<BeaconStateError> for GossipBlobError {
155155
fn from(e: BeaconStateError) -> Self {
156-
GossipBlobError::BeaconChainError(BeaconChainError::BeaconStateError(e))
156+
GossipBlobError::BeaconChainError(BeaconChainError::BeaconStateError(e).into())
157157
}
158158
}
159159

@@ -446,7 +446,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes, O: ObservationStrat
446446
.observed_blob_sidecars
447447
.read()
448448
.proposer_is_known(&blob_sidecar)
449-
.map_err(|e| GossipBlobError::BeaconChainError(e.into()))?
449+
.map_err(|e| GossipBlobError::BeaconChainError(Box::new(e.into())))?
450450
{
451451
return Err(GossipBlobError::RepeatBlob {
452452
proposer: blob_proposer_index,
@@ -511,7 +511,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes, O: ObservationStrat
511511
let (parent_state_root, mut parent_state) = chain
512512
.store
513513
.get_advanced_hot_state(block_parent_root, blob_slot, parent_block.state_root)
514-
.map_err(|e| GossipBlobError::BeaconChainError(e.into()))?
514+
.map_err(|e| GossipBlobError::BeaconChainError(Box::new(e.into())))?
515515
.ok_or_else(|| {
516516
BeaconChainError::DBInconsistent(format!(
517517
"Missing state for parent block {block_parent_root:?}",
@@ -582,7 +582,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes, O: ObservationStrat
582582
blob_sidecar.block_proposer_index(),
583583
block_root,
584584
)
585-
.map_err(|e| GossipBlobError::BeaconChainError(e.into()))?;
585+
.map_err(|e| GossipBlobError::BeaconChainError(Box::new(e.into())))?;
586586

587587
if O::observe() {
588588
observe_gossip_blob(&kzg_verified_blob.blob, chain)?;
@@ -628,7 +628,7 @@ fn observe_gossip_blob<T: BeaconChainTypes>(
628628
.observed_blob_sidecars
629629
.write()
630630
.observe_sidecar(blob_sidecar)
631-
.map_err(|e| GossipBlobError::BeaconChainError(e.into()))?
631+
.map_err(|e| GossipBlobError::BeaconChainError(Box::new(e.into())))?
632632
{
633633
return Err(GossipBlobError::RepeatBlob {
634634
proposer: blob_sidecar.block_proposer_index(),

0 commit comments

Comments
 (0)