Superstruct AggregateAndProof (#5715)

* Upgrade `superstruct` to `0.8.0`

* superstruct `AggregateAndProof`
This commit is contained in:
ethDreamer
2024-05-06 10:09:22 -05:00
committed by GitHub
parent 7c6526d978
commit 19a9479234
28 changed files with 410 additions and 225 deletions

View File

@@ -31,8 +31,8 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use store::hot_cold_store::HotColdDBError;
use tokio::sync::mpsc;
use types::{
Attestation, AttesterSlashing, BlobSidecar, EthSpec, Hash256, IndexedAttestation,
LightClientFinalityUpdate, LightClientOptimisticUpdate, ProposerSlashing,
Attestation, AttestationRef, AttesterSlashing, BlobSidecar, EthSpec, Hash256,
IndexedAttestation, LightClientFinalityUpdate, LightClientOptimisticUpdate, ProposerSlashing,
SignedAggregateAndProof, SignedBeaconBlock, SignedBlsToExecutionChange,
SignedContributionAndProof, SignedVoluntaryExit, Slot, SubnetId, SyncCommitteeMessage,
SyncSubnetId,
@@ -62,8 +62,8 @@ struct VerifiedUnaggregate<T: BeaconChainTypes> {
/// This implementation allows `Self` to be imported to fork choice and other functions on the
/// `BeaconChain`.
impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedUnaggregate<T> {
fn attestation(&self) -> &Attestation<T::EthSpec> {
&self.attestation
fn attestation(&self) -> AttestationRef<T::EthSpec> {
self.attestation.to_ref()
}
fn indexed_attestation(&self) -> &IndexedAttestation<T::EthSpec> {
@@ -95,8 +95,8 @@ struct VerifiedAggregate<T: BeaconChainTypes> {
/// This implementation allows `Self` to be imported to fork choice and other functions on the
/// `BeaconChain`.
impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregate<T> {
fn attestation(&self) -> &Attestation<T::EthSpec> {
&self.signed_aggregate.message.aggregate
fn attestation(&self) -> AttestationRef<T::EthSpec> {
self.signed_aggregate.message().aggregate()
}
fn indexed_attestation(&self) -> &IndexedAttestation<T::EthSpec> {
@@ -105,7 +105,12 @@ impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregate<T> {
/// Efficient clone-free implementation that moves out of the `Box`.
fn into_attestation_and_indices(self) -> (Attestation<T::EthSpec>, Vec<u64>) {
let attestation = self.signed_aggregate.message.aggregate;
// TODO(electra): technically we shouldn't have to clone..
let attestation = self
.signed_aggregate
.message()
.aggregate()
.clone_as_attestation();
let attesting_indices = self.indexed_attestation.attesting_indices_to_vec();
(attestation, attesting_indices)
}
@@ -143,10 +148,10 @@ impl<E: EthSpec> FailedAtt<E> {
}
}
pub fn attestation(&self) -> &Attestation<E> {
pub fn attestation(&self) -> AttestationRef<E> {
match self {
FailedAtt::Unaggregate { attestation, .. } => attestation,
FailedAtt::Aggregate { attestation, .. } => &attestation.message.aggregate,
FailedAtt::Unaggregate { attestation, .. } => attestation.to_ref(),
FailedAtt::Aggregate { attestation, .. } => attestation.message().aggregate(),
}
}
}
@@ -412,7 +417,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
reprocess_tx: Option<mpsc::Sender<ReprocessQueueMessage>>,
seen_timestamp: Duration,
) {
let beacon_block_root = aggregate.message.aggregate.data().beacon_block_root;
let beacon_block_root = aggregate.message().aggregate().data().beacon_block_root;
let result = match self
.chain
@@ -2727,7 +2732,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
/// timely), propagate it on gossip. Otherwise, ignore it.
fn propagate_attestation_if_timely(
&self,
attestation: &Attestation<T::EthSpec>,
attestation: AttestationRef<T::EthSpec>,
message_id: MessageId,
peer_id: PeerId,
) {

View File

@@ -144,7 +144,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
processor.process_gossip_aggregate_batch(aggregates, Some(reprocess_tx))
};
let beacon_block_root = aggregate.message.aggregate.data().beacon_block_root;
let beacon_block_root = aggregate.message().aggregate().data().beacon_block_root;
self.try_send(BeaconWorkEvent {
drop_during_sync: true,
work: Work::GossipAggregate {