superstruct the AttesterSlashing (#5636)

* `superstruct` Attester Fork Variants

* Push a little further

* Deal with Encode / Decode of AttesterSlashing

* not so sure about this..

* Stop Encode/Decode Bounds from Propagating Out

* Tons of Changes..

* More Conversions to AttestationRef

* Add AsReference trait (#15)

* Add AsReference trait

* Fix some snafus

* Got it Compiling! :D

* Got Tests Building

* Get beacon chain tests compiling

---------

Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
ethDreamer
2024-05-02 18:00:21 -05:00
committed by GitHub
parent 3b7132bc0d
commit e6c7f145dd
53 changed files with 1405 additions and 437 deletions

View File

@@ -4,8 +4,9 @@ use crate::EpochCacheError;
use std::collections::{hash_map::Entry, HashMap};
use tree_hash::TreeHash;
use types::{
AbstractExecPayload, Attestation, AttestationData, BeaconState, BeaconStateError, BitList,
ChainSpec, Epoch, EthSpec, Hash256, IndexedAttestation, SignedBeaconBlock, Slot,
AbstractExecPayload, AttestationData, AttestationRef, BeaconState, BeaconStateError, BitList,
ChainSpec, Epoch, EthSpec, Hash256, IndexedAttestation, IndexedAttestationRef,
SignedBeaconBlock, Slot,
};
#[derive(Debug, PartialEq, Clone)]
@@ -153,13 +154,13 @@ impl<E: EthSpec> ConsensusContext<E> {
}
}
pub fn get_indexed_attestation(
&mut self,
pub fn get_indexed_attestation<'a>(
&'a mut self,
state: &BeaconState<E>,
attestation: &Attestation<E>,
) -> Result<&IndexedAttestation<E>, BlockOperationError<AttestationInvalid>> {
attestation: AttestationRef<'a, E>,
) -> Result<IndexedAttestationRef<E>, BlockOperationError<AttestationInvalid>> {
let aggregation_bits = match attestation {
Attestation::Base(attn) => {
AttestationRef::Base(attn) => {
let mut extended_aggregation_bits: BitList<E::MaxValidatorsPerCommitteePerSlot> =
BitList::with_capacity(attn.aggregation_bits.len())
.map_err(BeaconStateError::from)?;
@@ -171,7 +172,7 @@ impl<E: EthSpec> ConsensusContext<E> {
}
extended_aggregation_bits
}
Attestation::Electra(attn) => attn.aggregation_bits.clone(),
AttestationRef::Electra(attn) => attn.aggregation_bits.clone(),
};
let key = (attestation.data().clone(), aggregation_bits);
@@ -186,6 +187,7 @@ impl<E: EthSpec> ConsensusContext<E> {
Ok(vacant.insert(indexed_attestation))
}
}
.map(|indexed_attestation| (*indexed_attestation).to_ref())
}
pub fn num_cached_indexed_attestations(&self) -> usize {