mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 12:58:31 +00:00
Ensure /eth/v2/beacon/pool/attestations honors committee_index (#7298)
#7294 Fix the filtering logic so that we actually filter by committee index for both `Base` and `Electra` attestations. Added a tiny optimization when calculating committee_index to prevent unneeded memory allocations Added a regression test
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::AttestationStats;
|
||||
use itertools::Itertools;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use types::{
|
||||
attestation::{AttestationBase, AttestationElectra},
|
||||
superstruct, AggregateSignature, Attestation, AttestationData, BeaconState, BitList, BitVector,
|
||||
@@ -119,6 +119,18 @@ impl<E: EthSpec> CompactAttestationRef<'_, E> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_committee_indices_map(&self) -> HashSet<u64> {
|
||||
match self.indexed {
|
||||
CompactIndexedAttestation::Base(_) => HashSet::from([self.data.index]),
|
||||
CompactIndexedAttestation::Electra(indexed_att) => indexed_att
|
||||
.committee_bits
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, bit)| if bit { Some(index as u64) } else { None })
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone_as_attestation(&self) -> Attestation<E> {
|
||||
match self.indexed {
|
||||
CompactIndexedAttestation::Base(indexed_att) => Attestation::Base(AttestationBase {
|
||||
@@ -268,7 +280,11 @@ impl<E: EthSpec> CompactIndexedAttestationElectra<E> {
|
||||
}
|
||||
|
||||
pub fn committee_index(&self) -> Option<u64> {
|
||||
self.get_committee_indices().first().copied()
|
||||
self.committee_bits
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|&(_, bit)| bit)
|
||||
.map(|(index, _)| index as u64)
|
||||
}
|
||||
|
||||
pub fn get_committee_indices(&self) -> Vec<u64> {
|
||||
|
||||
Reference in New Issue
Block a user