mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-18 04:13:00 +00:00
Attestation superstruct changes for EIP 7549 (#5644)
* update * experiment * superstruct changes * revert * superstruct changes * fix tests * indexed attestation * indexed attestation superstruct * updated TODOs
This commit is contained in:
@@ -2,8 +2,8 @@ use crate::AttestationStats;
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashMap;
|
||||
use types::{
|
||||
AggregateSignature, Attestation, AttestationData, BeaconState, BitList, Checkpoint, Epoch,
|
||||
EthSpec, Hash256, Slot,
|
||||
attestation::{AttestationBase, AttestationElectra}, superstruct, AggregateSignature, Attestation, AttestationData,
|
||||
BeaconState, BitList, BitVector, Checkpoint, Epoch, EthSpec, Hash256, Slot,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
@@ -20,11 +20,18 @@ pub struct CompactAttestationData {
|
||||
pub target_root: Hash256,
|
||||
}
|
||||
|
||||
#[superstruct(variants(Base, Electra), variant_attributes(derive(Debug, PartialEq,)))]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct CompactIndexedAttestation<E: EthSpec> {
|
||||
pub attesting_indices: Vec<u64>,
|
||||
#[superstruct(only(Base), partial_getter(rename = "aggregation_bits_base"))]
|
||||
pub aggregation_bits: BitList<E::MaxValidatorsPerCommittee>,
|
||||
#[superstruct(only(Electra), partial_getter(rename = "aggregation_bits_electra"))]
|
||||
pub aggregation_bits: BitList<E::MaxValidatorsPerCommitteePerSlot>,
|
||||
pub signature: AggregateSignature,
|
||||
pub index: u64,
|
||||
#[superstruct(only(Electra))]
|
||||
pub committee_bits: BitVector<E::MaxCommitteesPerSlot>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -54,20 +61,29 @@ pub struct AttestationDataMap<E: EthSpec> {
|
||||
impl<E: EthSpec> SplitAttestation<E> {
|
||||
pub fn new(attestation: Attestation<E>, attesting_indices: Vec<u64>) -> Self {
|
||||
let checkpoint = CheckpointKey {
|
||||
source: attestation.data.source,
|
||||
target_epoch: attestation.data.target.epoch,
|
||||
source: attestation.data().source,
|
||||
target_epoch: attestation.data().target.epoch,
|
||||
};
|
||||
let data = CompactAttestationData {
|
||||
slot: attestation.data.slot,
|
||||
index: attestation.data.index,
|
||||
beacon_block_root: attestation.data.beacon_block_root,
|
||||
target_root: attestation.data.target.root,
|
||||
slot: attestation.data().slot,
|
||||
index: attestation.data().index,
|
||||
beacon_block_root: attestation.data().beacon_block_root,
|
||||
target_root: attestation.data().target.root,
|
||||
};
|
||||
let indexed = CompactIndexedAttestation {
|
||||
attesting_indices,
|
||||
aggregation_bits: attestation.aggregation_bits,
|
||||
signature: attestation.signature,
|
||||
|
||||
let indexed = match attestation.clone() {
|
||||
Attestation::Base(attn) => {
|
||||
CompactIndexedAttestation::Base(CompactIndexedAttestationBase {
|
||||
attesting_indices,
|
||||
aggregation_bits: attn.aggregation_bits,
|
||||
signature: attestation.signature().clone(),
|
||||
index: data.index,
|
||||
})
|
||||
}
|
||||
// TODO(electra) implement electra variant
|
||||
Attestation::Electra(_) => todo!(),
|
||||
};
|
||||
|
||||
Self {
|
||||
checkpoint,
|
||||
data,
|
||||
@@ -99,10 +115,18 @@ impl<'a, E: EthSpec> AttestationRef<'a, E> {
|
||||
}
|
||||
|
||||
pub fn clone_as_attestation(&self) -> Attestation<E> {
|
||||
Attestation {
|
||||
aggregation_bits: self.indexed.aggregation_bits.clone(),
|
||||
data: self.attestation_data(),
|
||||
signature: self.indexed.signature.clone(),
|
||||
match self.indexed {
|
||||
CompactIndexedAttestation::Base(indexed_att) => Attestation::Base(AttestationBase {
|
||||
aggregation_bits: indexed_att.aggregation_bits.clone(),
|
||||
data: self.attestation_data(),
|
||||
signature: indexed_att.signature.clone(),
|
||||
}),
|
||||
CompactIndexedAttestation::Electra(indexed_att) => Attestation::Electra(AttestationElectra {
|
||||
aggregation_bits: indexed_att.aggregation_bits.clone(),
|
||||
data: self.attestation_data(),
|
||||
signature: indexed_att.signature.clone(),
|
||||
committee_bits: indexed_att.committee_bits.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,6 +149,34 @@ impl CheckpointKey {
|
||||
}
|
||||
|
||||
impl<E: EthSpec> CompactIndexedAttestation<E> {
|
||||
pub fn signers_disjoint_from(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(CompactIndexedAttestation::Base(this), CompactIndexedAttestation::Base(other)) => {
|
||||
this.signers_disjoint_from(other)
|
||||
}
|
||||
(CompactIndexedAttestation::Electra(_), CompactIndexedAttestation::Electra(_)) => {
|
||||
todo!()
|
||||
}
|
||||
// TODO(electra) is a mix of electra and base compact indexed attestations an edge case we need to deal with?
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn aggregate(&mut self, other: &Self) {
|
||||
match (self, other) {
|
||||
(CompactIndexedAttestation::Base(this), CompactIndexedAttestation::Base(other)) => {
|
||||
this.aggregate(other)
|
||||
}
|
||||
(CompactIndexedAttestation::Electra(_), CompactIndexedAttestation::Electra(_)) => {
|
||||
todo!()
|
||||
}
|
||||
// TODO(electra) is a mix of electra and base compact indexed attestations an edge case we need to deal with?
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> CompactIndexedAttestationBase<E> {
|
||||
pub fn signers_disjoint_from(&self, other: &Self) -> bool {
|
||||
self.aggregation_bits
|
||||
.intersection(&other.aggregation_bits)
|
||||
|
||||
Reference in New Issue
Block a user