Fix naive import, greedy aggregation

This commit is contained in:
Michael Sproul
2022-07-07 10:59:19 +10:00
parent d948e9764f
commit 24fdd56baf
8 changed files with 84 additions and 36 deletions

View File

@@ -6,7 +6,7 @@ use types::*;
pub fn get_attesting_indices<T: EthSpec>(
committee: &[usize],
bitlist: &BitList<T::MaxValidatorsPerCommittee>,
) -> Result<Vec<usize>, BeaconStateError> {
) -> Result<Vec<u64>, BeaconStateError> {
if bitlist.len() != committee.len() {
return Err(BeaconStateError::InvalidBitfield);
}
@@ -15,7 +15,7 @@ pub fn get_attesting_indices<T: EthSpec>(
for (i, validator_index) in committee.iter().enumerate() {
if let Ok(true) = bitlist.get(i) {
indices.push(*validator_index)
indices.push(*validator_index as u64)
}
}

View File

@@ -14,9 +14,7 @@ pub fn get_indexed_attestation<T: EthSpec>(
let attesting_indices = get_attesting_indices::<T>(committee, &attestation.aggregation_bits)?;
Ok(IndexedAttestation {
attesting_indices: VariableList::new(
attesting_indices.into_iter().map(|x| x as u64).collect(),
)?,
attesting_indices: VariableList::new(attesting_indices)?,
data: attestation.data.clone(),
signature: attestation.signature.clone(),
})

View File

@@ -278,8 +278,8 @@ impl ValidatorStatuses {
// Loop through the participating validator indices and update the status vec.
for validator_index in attesting_indices {
self.statuses
.get_mut(validator_index)
.ok_or(BeaconStateError::UnknownValidator(validator_index))?
.get_mut(validator_index as usize)
.ok_or(BeaconStateError::UnknownValidator(validator_index as usize))?
.update(&status);
}
}

View File

@@ -32,8 +32,8 @@ pub fn translate_participation<E: EthSpec>(
for index in attesting_indices {
for flag_index in &participation_flag_indices {
epoch_participation
.get_mut(index)
.ok_or(Error::UnknownValidator(index))?
.get_mut(index as usize)
.ok_or(Error::UnknownValidator(index as usize))?
.add_flag(*flag_index)?;
}
}