Skip to content

Commit

Permalink
Fix attestation validations before publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tumas committed May 15, 2024
1 parent 9b98c04 commit e6b5624
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
9 changes: 3 additions & 6 deletions fork_choice_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,12 +1333,9 @@ impl<P: Preset> Store<P> {
}
}

let AttestationData {
slot,
index,
target,
..
} = attestation.data();
let index = misc::committee_index(&attestation);

let AttestationData { slot, target, .. } = attestation.data();

// TODO(feature/deneb): Figure out why this validation is split over 2 methods.
// TODO(feature/deneb): This appears to be unfinished.
Expand Down
12 changes: 11 additions & 1 deletion helper_functions/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use typenum::Unsigned as _;
use types::{
altair::{consts::SyncCommitteeSubnetCount, primitives::SyncCommitteePeriod},
cache::PackedIndices,
combined::SignedBeaconBlock,
combined::{Attestation, SignedBeaconBlock},
config::Config,
deneb::{
consts::{BlobCommitmentTreeDepth, BlobSidecarSubnetCount, VERSIONED_HASH_VERSION_KZG},
Expand Down Expand Up @@ -506,6 +506,16 @@ pub fn construct_blob_sidecars<P: Preset>(
.collect()
}

#[must_use]
pub fn committee_index<P: Preset>(attestation: &Attestation<P>) -> CommitteeIndex {
match attestation {
Attestation::Phase0(attestation) => attestation.data.index,
Attestation::Electra(attestation) => get_committee_indices::<P>(attestation.committee_bits)
.next()
.unwrap_or_default(),
}
}

#[must_use]
pub fn get_committee_indices<P: Preset>(
committee_bits: BitVector<P::MaxCommitteesPerSlot>,
Expand Down
18 changes: 3 additions & 15 deletions validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ use types::{
SignedVoluntaryExit,
},
primitives::{
CommitteeIndex, Epoch, ExecutionAddress, ExecutionBlockHash, Slot, Uint256,
ValidatorIndex, H256,
Epoch, ExecutionAddress, ExecutionBlockHash, Slot, Uint256, ValidatorIndex, H256,
},
},
preset::Preset,
Expand Down Expand Up @@ -1755,7 +1754,7 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
..
} = own_attestation;

let committee_index = committee_index(attestation);
let committee_index = misc::committee_index(attestation);

debug!(
"validator {} of committee {} ({:?}) attesting in slot {}: {:?}",
Expand Down Expand Up @@ -1794,7 +1793,7 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
self.own_aggregators = accepted_attestations
.into_iter()
.filter_map(|own_attestation| {
let committee_index = committee_index(&own_attestation.attestation);
let committee_index = misc::committee_index(&own_attestation.attestation);

let member =
own_members.get(&(committee_index, own_attestation.validator_index))?;
Expand Down Expand Up @@ -3502,14 +3501,3 @@ async fn update_beacon_committee_subscriptions(
warn!("failed to update beacon committee subscriptions: {error:?}");
}
}

fn committee_index<P: Preset>(attestation: &Attestation<P>) -> CommitteeIndex {
match attestation {
Attestation::Phase0(attestation) => attestation.data.index,
Attestation::Electra(attestation) => {
misc::get_committee_indices::<P>(attestation.committee_bits)
.next()
.unwrap_or_default()
}
}
}

0 comments on commit e6b5624

Please sign in to comment.