Merge branch 'ef-tests-electra' of https://github.com/sigp/lighthouse into ef-tests-electra

This commit is contained in:
realbigsean
2024-05-12 06:58:00 -04:00
2 changed files with 22 additions and 44 deletions

View File

@@ -1,7 +1,7 @@
use ssz_derive::{Decode, Encode};
use state_processing::ConsensusContext;
use std::collections::HashMap;
use types::{AttestationData, BitList, EthSpec, Hash256, IndexedAttestation, Slot};
use types::{EthSpec, Hash256, IndexedAttestation, Slot};
/// The consensus context is stored on disk as part of the data availability overflow cache.
///
@@ -21,8 +21,7 @@ pub struct OnDiskConsensusContext<E: EthSpec> {
///
/// They are not part of the on-disk format.
#[ssz(skip_serializing, skip_deserializing)]
indexed_attestations:
HashMap<(AttestationData, BitList<E::MaxValidatorsPerSlot>), IndexedAttestation<E>>,
indexed_attestations: HashMap<Hash256, IndexedAttestation<E>>,
}
impl<E: EthSpec> OnDiskConsensusContext<E> {

View File

@@ -4,9 +4,8 @@ use crate::EpochCacheError;
use std::collections::{hash_map::Entry, HashMap};
use tree_hash::TreeHash;
use types::{
AbstractExecPayload, AttestationData, AttestationRef, BeaconState, BeaconStateError, BitList,
ChainSpec, Epoch, EthSpec, Hash256, IndexedAttestation, IndexedAttestationRef,
SignedBeaconBlock, Slot,
AbstractExecPayload, AttestationRef, BeaconState, BeaconStateError, ChainSpec, Epoch, EthSpec,
Hash256, IndexedAttestation, IndexedAttestationRef, SignedBeaconBlock, Slot,
};
#[derive(Debug, PartialEq, Clone)]
@@ -22,8 +21,7 @@ pub struct ConsensusContext<E: EthSpec> {
/// Block root of the block at `slot`.
pub current_block_root: Option<Hash256>,
/// Cache of indexed attestations constructed during block processing.
pub indexed_attestations:
HashMap<(AttestationData, BitList<E::MaxValidatorsPerSlot>), IndexedAttestation<E>>,
pub indexed_attestations: HashMap<Hash256, IndexedAttestation<E>>,
}
#[derive(Debug, PartialEq, Clone)]
@@ -154,41 +152,25 @@ impl<E: EthSpec> ConsensusContext<E> {
state: &BeaconState<E>,
attestation: AttestationRef<'a, E>,
) -> Result<IndexedAttestationRef<E>, BlockOperationError<AttestationInvalid>> {
let key = attestation.tree_hash_root();
match attestation {
AttestationRef::Base(attn) => {
let extended_aggregation_bits = attn
.extend_aggregation_bits()
.map_err(BeaconStateError::from)?;
let key = (attn.data.clone(), extended_aggregation_bits);
match self.indexed_attestations.entry(key) {
Entry::Occupied(occupied) => Ok(occupied.into_mut()),
Entry::Vacant(vacant) => {
let committee =
state.get_beacon_committee(attn.data.slot, attn.data.index)?;
let indexed_attestation = attesting_indices_base::get_indexed_attestation(
committee.committee,
attn,
)?;
Ok(vacant.insert(indexed_attestation))
}
AttestationRef::Base(attn) => match self.indexed_attestations.entry(key) {
Entry::Occupied(occupied) => Ok(occupied.into_mut()),
Entry::Vacant(vacant) => {
let committee = state.get_beacon_committee(attn.data.slot, attn.data.index)?;
let indexed_attestation =
attesting_indices_base::get_indexed_attestation(committee.committee, attn)?;
Ok(vacant.insert(indexed_attestation))
}
}
AttestationRef::Electra(attn) => {
let key = (attn.data.clone(), attn.aggregation_bits.clone());
match self.indexed_attestations.entry(key) {
Entry::Occupied(occupied) => Ok(occupied.into_mut()),
Entry::Vacant(vacant) => {
let indexed_attestation =
attesting_indices_electra::get_indexed_attestation_from_state(
state, attn,
)?;
Ok(vacant.insert(indexed_attestation))
}
},
AttestationRef::Electra(attn) => match self.indexed_attestations.entry(key) {
Entry::Occupied(occupied) => Ok(occupied.into_mut()),
Entry::Vacant(vacant) => {
let indexed_attestation =
attesting_indices_electra::get_indexed_attestation_from_state(state, attn)?;
Ok(vacant.insert(indexed_attestation))
}
}
},
}
.map(|indexed_attestation| (*indexed_attestation).to_ref())
}
@@ -200,10 +182,7 @@ impl<E: EthSpec> ConsensusContext<E> {
#[must_use]
pub fn set_indexed_attestations(
mut self,
attestations: HashMap<
(AttestationData, BitList<E::MaxValidatorsPerSlot>),
IndexedAttestation<E>,
>,
attestations: HashMap<Hash256, IndexedAttestation<E>>,
) -> Self {
self.indexed_attestations = attestations;
self