Skip to content

Commit

Permalink
Remove unnecessary expect call during attestation validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tumas committed Feb 5, 2025
1 parent dfc67fa commit 6471ae2
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions fork_choice_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ impl<P: Preset> Store<P> {
let message = aggregate_and_proof.message();
let aggregator_index = message.aggregator_index();
let selection_proof = message.selection_proof();
let aggregate = message.aggregate();
let aggregate = Arc::new(message.aggregate());

match self.validate_attestation_internal(&aggregate, false)? {
PartialAttestationAction::Accept => {}
Expand Down Expand Up @@ -1478,7 +1478,7 @@ impl<P: Preset> Store<P> {
/// [`validate_on_attestation`]: https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/fork-choice.md#validate_on_attestation
fn validate_attestation_internal(
&self,
attestation: &Attestation<P>,
attestation: &Arc<Attestation<P>>,
is_from_block: bool,
) -> Result<PartialAttestationAction> {
let AttestationData {
Expand Down Expand Up @@ -1514,24 +1514,21 @@ impl<P: Preset> Store<P> {
ensure!(
index == 0,
Error::AttestationDataIndexNotZero {
attestation: Arc::new(attestation.clone())
attestation: attestation.clone_arc()
}
);

// TODO(feature/electra): clone should not be necessary
let committee_indices = misc::get_committee_indices::<P>(
*attestation
.committee_bits()
.expect("post-Electra attestation must contain committee_bits field"),
)
.collect_vec();
if let Attestation::Electra(electra_attestation) = attestation.as_ref() {
let committee_indices =
misc::get_committee_indices::<P>(electra_attestation.committee_bits);

ensure!(
committee_indices.len() == 1,
Error::AttestationFromMultipleCommittees {
attestation: Arc::new(attestation.clone())
}
);
ensure!(
committee_indices.count() == 1,
Error::AttestationFromMultipleCommittees {
attestation: attestation.clone_arc()
}
);
}
}

// > Attestations must be from the current or previous epoch
Expand Down Expand Up @@ -1559,7 +1556,7 @@ impl<P: Preset> Store<P> {
ensure!(
target.epoch == Self::epoch_at_slot(slot),
Error::AttestationTargetsWrongEpoch {
attestation: Arc::new(attestation.clone()),
attestation: attestation.clone_arc(),
},
);

Expand Down Expand Up @@ -1590,7 +1587,7 @@ impl<P: Preset> Store<P> {
ensure!(
ghost_vote_block.message().slot() <= slot,
Error::AttestationForFutureBlock {
attestation: Arc::new(attestation.clone()),
attestation: attestation.clone_arc(),
block: ghost_vote_block.clone_arc(),
},
);
Expand All @@ -1606,7 +1603,7 @@ impl<P: Preset> Store<P> {
ensure!(
target.root == ancestor_at_target_epoch_start,
Error::LmdGhostInconsistentWithFfgTarget {
attestation: Arc::new(attestation.clone()),
attestation: attestation.clone_arc(),
},
);

Expand Down

0 comments on commit 6471ae2

Please sign in to comment.