mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-22 07:18:25 +00:00
fix get attesting indices (#5742)
* fix get attesting indices * better errors * fix compile * only get committee index once
This commit is contained in:
@@ -1309,10 +1309,11 @@ pub fn obtain_indexed_attestation_and_committees_per_slot<T: BeaconChainTypes>(
|
|||||||
attesting_indices_electra::get_indexed_attestation(&committees, att)
|
attesting_indices_electra::get_indexed_attestation(&committees, att)
|
||||||
.map(|attestation| (attestation, committees_per_slot))
|
.map(|attestation| (attestation, committees_per_slot))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
if e == BlockOperationError::BeaconStateError(NoCommitteeFound) {
|
let index = att.committee_index();
|
||||||
|
if e == BlockOperationError::BeaconStateError(NoCommitteeFound(index)) {
|
||||||
Error::NoCommitteeForSlotAndIndex {
|
Error::NoCommitteeForSlotAndIndex {
|
||||||
slot: att.data.slot,
|
slot: att.data.slot,
|
||||||
index: att.committee_index(),
|
index,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Error::Invalid(e)
|
Error::Invalid(e)
|
||||||
|
|||||||
@@ -113,11 +113,15 @@ pub mod attesting_indices_electra {
|
|||||||
.map(|committee| (committee.index, committee))
|
.map(|committee| (committee.index, committee))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let committee_count_per_slot = committees.len() as u64;
|
||||||
|
let mut participant_count = 0;
|
||||||
for index in committee_indices {
|
for index in committee_indices {
|
||||||
if let Some(&beacon_committee) = committees_map.get(&index) {
|
if let Some(&beacon_committee) = committees_map.get(&index) {
|
||||||
if aggregation_bits.len() != beacon_committee.committee.len() {
|
// This check is new to the spec's `process_attestation` in Electra.
|
||||||
return Err(BeaconStateError::InvalidBitfield);
|
if index >= committee_count_per_slot {
|
||||||
|
return Err(BeaconStateError::InvalidCommitteeIndex(index));
|
||||||
}
|
}
|
||||||
|
participant_count.safe_add_assign(beacon_committee.committee.len() as u64)?;
|
||||||
let committee_attesters = beacon_committee
|
let committee_attesters = beacon_committee
|
||||||
.committee
|
.committee
|
||||||
.iter()
|
.iter()
|
||||||
@@ -136,10 +140,13 @@ pub mod attesting_indices_electra {
|
|||||||
|
|
||||||
committee_offset.safe_add(beacon_committee.committee.len())?;
|
committee_offset.safe_add(beacon_committee.committee.len())?;
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::NoCommitteeFound);
|
return Err(Error::NoCommitteeFound(index));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(electra) what should we do when theres no committee found for a given index?
|
// This check is new to the spec's `process_attestation` in Electra.
|
||||||
|
if participant_count as usize != aggregation_bits.len() {
|
||||||
|
return Err(BeaconStateError::InvalidBitfield);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut indices = output.into_iter().collect_vec();
|
let mut indices = output.into_iter().collect_vec();
|
||||||
|
|||||||
@@ -159,7 +159,8 @@ pub enum Error {
|
|||||||
IndexNotSupported(usize),
|
IndexNotSupported(usize),
|
||||||
InvalidFlagIndex(usize),
|
InvalidFlagIndex(usize),
|
||||||
MerkleTreeError(merkle_proof::MerkleTreeError),
|
MerkleTreeError(merkle_proof::MerkleTreeError),
|
||||||
NoCommitteeFound,
|
NoCommitteeFound(CommitteeIndex),
|
||||||
|
InvalidCommitteeIndex(CommitteeIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Control whether an epoch-indexed field can be indexed at the next epoch or not.
|
/// Control whether an epoch-indexed field can be indexed at the next epoch or not.
|
||||||
|
|||||||
Reference in New Issue
Block a user