mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 22:08:30 +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:
@@ -5,6 +5,7 @@ use derivative::Derivative;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::BitVector;
|
||||
use std::collections::HashSet;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use superstruct::superstruct;
|
||||
use test_random_derive::TestRandom;
|
||||
@@ -209,6 +210,13 @@ impl<E: EthSpec> Attestation<E> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_committee_indices_map(&self) -> HashSet<u64> {
|
||||
match self {
|
||||
Attestation::Base(att) => HashSet::from([att.data.index]),
|
||||
Attestation::Electra(att) => att.get_committee_indices().into_iter().collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_aggregation_bits_zero(&self) -> bool {
|
||||
match self {
|
||||
Attestation::Base(att) => att.aggregation_bits.is_zero(),
|
||||
@@ -292,7 +300,11 @@ impl<E: EthSpec> AttestationRef<'_, E> {
|
||||
|
||||
impl<E: EthSpec> AttestationElectra<E> {
|
||||
pub fn committee_index(&self) -> Option<u64> {
|
||||
self.get_committee_indices().first().cloned()
|
||||
self.committee_bits
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|&(_, bit)| bit)
|
||||
.map(|(index, _)| index as u64)
|
||||
}
|
||||
|
||||
pub fn get_aggregation_bits(&self) -> Vec<u64> {
|
||||
|
||||
Reference in New Issue
Block a user