mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Merge branch 'beacon-api-electra' of https://github.com/sigp/lighthouse into p2p-electra
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use ssz_derive::{Decode, Encode};
|
use ssz_derive::{Decode, Encode};
|
||||||
use state_processing::ConsensusContext;
|
use state_processing::ConsensusContext;
|
||||||
use std::collections::HashMap;
|
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.
|
/// 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.
|
/// They are not part of the on-disk format.
|
||||||
#[ssz(skip_serializing, skip_deserializing)]
|
#[ssz(skip_serializing, skip_deserializing)]
|
||||||
indexed_attestations:
|
indexed_attestations: HashMap<Hash256, IndexedAttestation<E>>,
|
||||||
HashMap<(AttestationData, BitList<E::MaxValidatorsPerSlot>), IndexedAttestation<E>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: EthSpec> OnDiskConsensusContext<E> {
|
impl<E: EthSpec> OnDiskConsensusContext<E> {
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ use crate::EpochCacheError;
|
|||||||
use std::collections::{hash_map::Entry, HashMap};
|
use std::collections::{hash_map::Entry, HashMap};
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use types::{
|
use types::{
|
||||||
AbstractExecPayload, AttestationData, AttestationRef, BeaconState, BeaconStateError, BitList,
|
AbstractExecPayload, AttestationRef, BeaconState, BeaconStateError, ChainSpec, Epoch, EthSpec,
|
||||||
ChainSpec, Epoch, EthSpec, Hash256, IndexedAttestation, IndexedAttestationRef,
|
Hash256, IndexedAttestation, IndexedAttestationRef, SignedBeaconBlock, Slot,
|
||||||
SignedBeaconBlock, Slot,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@@ -22,8 +21,7 @@ pub struct ConsensusContext<E: EthSpec> {
|
|||||||
/// Block root of the block at `slot`.
|
/// Block root of the block at `slot`.
|
||||||
pub current_block_root: Option<Hash256>,
|
pub current_block_root: Option<Hash256>,
|
||||||
/// Cache of indexed attestations constructed during block processing.
|
/// Cache of indexed attestations constructed during block processing.
|
||||||
pub indexed_attestations:
|
pub indexed_attestations: HashMap<Hash256, IndexedAttestation<E>>,
|
||||||
HashMap<(AttestationData, BitList<E::MaxValidatorsPerSlot>), IndexedAttestation<E>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@@ -154,41 +152,25 @@ impl<E: EthSpec> ConsensusContext<E> {
|
|||||||
state: &BeaconState<E>,
|
state: &BeaconState<E>,
|
||||||
attestation: AttestationRef<'a, E>,
|
attestation: AttestationRef<'a, E>,
|
||||||
) -> Result<IndexedAttestationRef<E>, BlockOperationError<AttestationInvalid>> {
|
) -> Result<IndexedAttestationRef<E>, BlockOperationError<AttestationInvalid>> {
|
||||||
|
let key = attestation.tree_hash_root();
|
||||||
match attestation {
|
match attestation {
|
||||||
AttestationRef::Base(attn) => {
|
AttestationRef::Base(attn) => match self.indexed_attestations.entry(key) {
|
||||||
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::Occupied(occupied) => Ok(occupied.into_mut()),
|
||||||
Entry::Vacant(vacant) => {
|
Entry::Vacant(vacant) => {
|
||||||
let committee =
|
let committee = state.get_beacon_committee(attn.data.slot, attn.data.index)?;
|
||||||
state.get_beacon_committee(attn.data.slot, attn.data.index)?;
|
let indexed_attestation =
|
||||||
let indexed_attestation = attesting_indices_base::get_indexed_attestation(
|
attesting_indices_base::get_indexed_attestation(committee.committee, attn)?;
|
||||||
committee.committee,
|
|
||||||
attn,
|
|
||||||
)?;
|
|
||||||
Ok(vacant.insert(indexed_attestation))
|
Ok(vacant.insert(indexed_attestation))
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
AttestationRef::Electra(attn) => match self.indexed_attestations.entry(key) {
|
||||||
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::Occupied(occupied) => Ok(occupied.into_mut()),
|
||||||
Entry::Vacant(vacant) => {
|
Entry::Vacant(vacant) => {
|
||||||
let indexed_attestation =
|
let indexed_attestation =
|
||||||
attesting_indices_electra::get_indexed_attestation_from_state(
|
attesting_indices_electra::get_indexed_attestation_from_state(state, attn)?;
|
||||||
state, attn,
|
|
||||||
)?;
|
|
||||||
Ok(vacant.insert(indexed_attestation))
|
Ok(vacant.insert(indexed_attestation))
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.map(|indexed_attestation| (*indexed_attestation).to_ref())
|
.map(|indexed_attestation| (*indexed_attestation).to_ref())
|
||||||
}
|
}
|
||||||
@@ -200,10 +182,7 @@ impl<E: EthSpec> ConsensusContext<E> {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn set_indexed_attestations(
|
pub fn set_indexed_attestations(
|
||||||
mut self,
|
mut self,
|
||||||
attestations: HashMap<
|
attestations: HashMap<Hash256, IndexedAttestation<E>>,
|
||||||
(AttestationData, BitList<E::MaxValidatorsPerSlot>),
|
|
||||||
IndexedAttestation<E>,
|
|
||||||
>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.indexed_attestations = attestations;
|
self.indexed_attestations = attestations;
|
||||||
self
|
self
|
||||||
|
|||||||
Reference in New Issue
Block a user