Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attestation superstruct changes for EIP 7549 #5644

Merged
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/attestation_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn produce_unaggregated_attestation<T: BeaconChainTypes>(
// Store the unaggregated attestation in the validator monitor for later processing
match chain.produce_unaggregated_attestation(current_slot, beacon_committee_index) {
Ok(unaggregated_attestation) => {
let data = &unaggregated_attestation.data;
let data = unaggregated_attestation.data();

debug!(
chain.log,
Expand Down
70 changes: 35 additions & 35 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,17 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
verify_propagation_slot_range(&chain.slot_clock, attestation, &chain.spec)?;

// Check the attestation's epoch matches its target.
if attestation.data.slot.epoch(T::EthSpec::slots_per_epoch())
!= attestation.data.target.epoch
if attestation.data().slot.epoch(T::EthSpec::slots_per_epoch())
!= attestation.data().target.epoch
{
return Err(Error::InvalidTargetEpoch {
slot: attestation.data.slot,
epoch: attestation.data.target.epoch,
slot: attestation.data().slot,
epoch: attestation.data().target.epoch,
});
}

// Ensure the valid aggregated attestation has not already been seen locally.
let attestation_data = &attestation.data;
let attestation_data = attestation.data();
let attestation_data_root = attestation_data.tree_hash_root();

if chain
Expand All @@ -486,7 +486,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
match chain
.observed_aggregators
.read()
.validator_has_been_observed(attestation.data.target.epoch, aggregator_index as usize)
.validator_has_been_observed(attestation.data().target.epoch, aggregator_index as usize)
{
Ok(true) => Err(Error::AggregatorAlreadyKnown(aggregator_index)),
Ok(false) => Ok(()),
Expand Down Expand Up @@ -518,7 +518,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
verify_attestation_target_root::<T::EthSpec>(&head_block, attestation)?;

// Ensure that the attestation has participants.
if attestation.aggregation_bits.is_zero() {
if attestation.is_aggregation_bits_zero() {
Err(Error::EmptyAggregationBitfield)
} else {
Ok(attestation_data_root)
Expand Down Expand Up @@ -611,12 +611,12 @@ impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
if chain
.observed_aggregators
.write()
.observe_validator(attestation.data.target.epoch, aggregator_index as usize)
.observe_validator(attestation.data().target.epoch, aggregator_index as usize)
.map_err(BeaconChainError::from)?
{
return Err(Error::PriorAttestationKnown {
validator_index: aggregator_index,
epoch: attestation.data.target.epoch,
epoch: attestation.data().target.epoch,
});
}

Expand Down Expand Up @@ -712,13 +712,13 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
attestation: &Attestation<T::EthSpec>,
chain: &BeaconChain<T>,
) -> Result<(), Error> {
let attestation_epoch = attestation.data.slot.epoch(T::EthSpec::slots_per_epoch());
let attestation_epoch = attestation.data().slot.epoch(T::EthSpec::slots_per_epoch());

// Check the attestation's epoch matches its target.
if attestation_epoch != attestation.data.target.epoch {
if attestation_epoch != attestation.data().target.epoch {
return Err(Error::InvalidTargetEpoch {
slot: attestation.data.slot,
epoch: attestation.data.target.epoch,
slot: attestation.data().slot,
epoch: attestation.data().target.epoch,
});
}

Expand All @@ -730,7 +730,7 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {

// Check to ensure that the attestation is "unaggregated". I.e., it has exactly one
// aggregation bit set.
let num_aggregation_bits = attestation.aggregation_bits.num_set_bits();
let num_aggregation_bits = attestation.num_set_aggregation_bits();
if num_aggregation_bits != 1 {
return Err(Error::NotExactlyOneAggregationBitSet(num_aggregation_bits));
}
Expand Down Expand Up @@ -785,12 +785,12 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
if chain
.observed_gossip_attesters
.read()
.validator_has_been_observed(attestation.data.target.epoch, validator_index as usize)
.validator_has_been_observed(attestation.data().target.epoch, validator_index as usize)
.map_err(BeaconChainError::from)?
{
return Err(Error::PriorAttestationKnown {
validator_index,
epoch: attestation.data.target.epoch,
epoch: attestation.data().target.epoch,
});
}

Expand Down Expand Up @@ -881,12 +881,12 @@ impl<'a, T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'a, T> {
if chain
.observed_gossip_attesters
.write()
.observe_validator(attestation.data.target.epoch, validator_index as usize)
.observe_validator(attestation.data().target.epoch, validator_index as usize)
.map_err(BeaconChainError::from)?
{
return Err(Error::PriorAttestationKnown {
validator_index,
epoch: attestation.data.target.epoch,
epoch: attestation.data().target.epoch,
});
}
Ok(())
Expand Down Expand Up @@ -998,28 +998,28 @@ fn verify_head_block_is_known<T: BeaconChainTypes>(
let block_opt = chain
.canonical_head
.fork_choice_read_lock()
.get_block(&attestation.data.beacon_block_root)
.get_block(&attestation.data().beacon_block_root)
.or_else(|| {
chain
.early_attester_cache
.get_proto_block(attestation.data.beacon_block_root)
.get_proto_block(attestation.data().beacon_block_root)
});

if let Some(block) = block_opt {
// Reject any block that exceeds our limit on skipped slots.
if let Some(max_skip_slots) = max_skip_slots {
if attestation.data.slot > block.slot + max_skip_slots {
if attestation.data().slot > block.slot + max_skip_slots {
return Err(Error::TooManySkippedSlots {
head_block_slot: block.slot,
attestation_slot: attestation.data.slot,
attestation_slot: attestation.data().slot,
});
}
}

Ok(block)
} else if chain.is_pre_finalization_block(attestation.data.beacon_block_root)? {
} else if chain.is_pre_finalization_block(attestation.data().beacon_block_root)? {
Err(Error::HeadBlockFinalized {
beacon_block_root: attestation.data.beacon_block_root,
beacon_block_root: attestation.data().beacon_block_root,
})
} else {
// The block is either:
Expand All @@ -1029,7 +1029,7 @@ fn verify_head_block_is_known<T: BeaconChainTypes>(
// 2) A post-finalization block that we don't know about yet. We'll queue
// the attestation until the block becomes available (or we time out).
Err(Error::UnknownHeadBlock {
beacon_block_root: attestation.data.beacon_block_root,
beacon_block_root: attestation.data().beacon_block_root,
})
}
}
Expand All @@ -1043,7 +1043,7 @@ pub fn verify_propagation_slot_range<S: SlotClock, E: EthSpec>(
attestation: &Attestation<E>,
spec: &ChainSpec,
) -> Result<(), Error> {
let attestation_slot = attestation.data.slot;
let attestation_slot = attestation.data().slot;
let latest_permissible_slot = slot_clock
.now_with_future_tolerance(spec.maximum_gossip_clock_disparity())
.ok_or(BeaconChainError::UnableToReadSlot)?;
Expand Down Expand Up @@ -1127,7 +1127,7 @@ pub fn verify_attestation_target_root<E: EthSpec>(
) -> Result<(), Error> {
// Check the attestation target root.
let head_block_epoch = head_block.slot.epoch(E::slots_per_epoch());
let attestation_epoch = attestation.data.slot.epoch(E::slots_per_epoch());
let attestation_epoch = attestation.data().slot.epoch(E::slots_per_epoch());
if head_block_epoch > attestation_epoch {
// The epoch references an invalid head block from a future epoch.
//
Expand All @@ -1140,7 +1140,7 @@ pub fn verify_attestation_target_root<E: EthSpec>(
// Reference:
// https://github.com/ethereum/eth2.0-specs/pull/2001#issuecomment-699246659
return Err(Error::InvalidTargetRoot {
attestation: attestation.data.target.root,
attestation: attestation.data().target.root,
// It is not clear what root we should expect in this case, since the attestation is
// fundamentally invalid.
expected: None,
Expand All @@ -1159,9 +1159,9 @@ pub fn verify_attestation_target_root<E: EthSpec>(
};

// Reject any attestation with an invalid target root.
if target_root != attestation.data.target.root {
if target_root != attestation.data().target.root {
return Err(Error::InvalidTargetRoot {
attestation: attestation.data.target.root,
attestation: attestation.data().target.root,
expected: Some(target_root),
});
}
Expand Down Expand Up @@ -1266,8 +1266,8 @@ where
T: BeaconChainTypes,
F: Fn((BeaconCommittee, CommitteesPerSlot)) -> Result<R, Error>,
{
let attestation_epoch = attestation.data.slot.epoch(T::EthSpec::slots_per_epoch());
let target = &attestation.data.target;
let attestation_epoch = attestation.data().slot.epoch(T::EthSpec::slots_per_epoch());
let target = &attestation.data().target;

// Attestation target must be for a known block.
//
Expand All @@ -1290,12 +1290,12 @@ where
let committees_per_slot = committee_cache.committees_per_slot();

Ok(committee_cache
.get_beacon_committee(attestation.data.slot, attestation.data.index)
.get_beacon_committee(attestation.data().slot, attestation.data().index)
.map(|committee| map_fn((committee, committees_per_slot)))
.unwrap_or_else(|| {
Err(Error::NoCommitteeForSlotAndIndex {
slot: attestation.data.slot,
index: attestation.data.index,
slot: attestation.data().slot,
index: attestation.data().index,
})
}))
})
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/beacon_block_reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let mut previous_epoch_participation = state.previous_epoch_participation()?.clone();

for attestation in block.body().attestations() {
let data = &attestation.data;
let data = attestation.data();
let inclusion_delay = state.slot().safe_sub(data.slot)?.as_u64();
// [Modified in Deneb:EIP7045]
let participation_flag_indices = get_attestation_participation_flag_indices(
Expand Down
28 changes: 15 additions & 13 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ use store::{
use task_executor::{ShutdownReason, TaskExecutor};
use tokio_stream::Stream;
use tree_hash::TreeHash;
use types::attestation::AttestationBase;
use types::blob_sidecar::FixedBlobSidecarList;
use types::payload::BlockProductionVersion;
use types::*;
Expand Down Expand Up @@ -1670,7 +1671,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&self,
attestation: Attestation<T::EthSpec>,
) -> Result<Attestation<T::EthSpec>, Error> {
let beacon_block_root = attestation.data.beacon_block_root;
let beacon_block_root = attestation.data().beacon_block_root;
match self
.canonical_head
.fork_choice_read_lock()
Expand Down Expand Up @@ -1936,7 +1937,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
};
drop(cache_timer);

Ok(Attestation {
// TODO(eip7549) implement electra variant
eserilev marked this conversation as resolved.
Show resolved Hide resolved
Ok(Attestation::Base(AttestationBase {
aggregation_bits: BitList::with_capacity(committee_len)?,
data: AttestationData {
slot: request_slot,
Expand All @@ -1946,7 +1948,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
target,
},
signature: AggregateSignature::empty(),
})
}))
}

/// Performs the same validation as `Self::verify_unaggregated_attestation_for_gossip`, but for
Expand Down Expand Up @@ -2158,8 +2160,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.log,
"Stored unaggregated attestation";
"outcome" => ?outcome,
"index" => attestation.data.index,
"slot" => attestation.data.slot.as_u64(),
"index" => attestation.data().index,
"slot" => attestation.data().slot.as_u64(),
),
Err(NaiveAggregationError::SlotTooLow {
slot,
Expand All @@ -2177,8 +2179,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.log,
"Failed to store unaggregated attestation";
"error" => ?e,
"index" => attestation.data.index,
"slot" => attestation.data.slot.as_u64(),
"index" => attestation.data().index,
"slot" => attestation.data().slot.as_u64(),
);
return Err(Error::from(e).into());
}
Expand Down Expand Up @@ -3746,7 +3748,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.log,
"Failed to get indexed attestation";
"purpose" => "validator monitor",
"attestation_slot" => attestation.data.slot,
"attestation_slot" => attestation.data().slot,
"error" => ?e,
);
continue;
Expand Down Expand Up @@ -3802,7 +3804,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.log,
"Failed to register observed attestation";
"error" => ?e,
"epoch" => a.data.target.epoch
"epoch" => a.data().target.epoch
);
}
}
Expand All @@ -3814,7 +3816,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.log,
"Failed to get indexed attestation";
"purpose" => "observation",
"attestation_slot" => a.data.slot,
"attestation_slot" => a.data().slot,
"error" => ?e,
);
continue;
Expand All @@ -3825,13 +3827,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

for &validator_index in &indexed_attestation.attesting_indices {
if let Err(e) = observed_block_attesters
.observe_validator(a.data.target.epoch, validator_index as usize)
.observe_validator(a.data().target.epoch, validator_index as usize)
{
debug!(
self.log,
"Failed to register observed block attester";
"error" => ?e,
"epoch" => a.data.target.epoch,
"epoch" => a.data().target.epoch,
"validator_index" => validator_index,
)
}
Expand All @@ -3855,7 +3857,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.log,
"Failed to get indexed attestation";
"purpose" => "slasher",
"attestation_slot" => attestation.data.slot,
"attestation_slot" => attestation.data().slot,
"error" => ?e,
);
continue;
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/block_reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.body()
.attestations()
.iter()
.map(|a| a.data.clone())
.map(|a| a.data().clone())
.collect()
} else {
vec![]
Expand Down
5 changes: 3 additions & 2 deletions beacon_node/beacon_chain/src/early_attester_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
use parking_lot::RwLock;
use proto_array::Block as ProtoBlock;
use std::sync::Arc;
use types::attestation::AttestationBase;
use types::*;

pub struct CacheItem<E: EthSpec> {
Expand Down Expand Up @@ -122,7 +123,7 @@ impl<E: EthSpec> EarlyAttesterCache<E> {
item.committee_lengths
.get_committee_length::<E>(request_slot, request_index, spec)?;

let attestation = Attestation {
let attestation = Attestation::Base(AttestationBase {
eserilev marked this conversation as resolved.
Show resolved Hide resolved
aggregation_bits: BitList::with_capacity(committee_len)
.map_err(BeaconStateError::from)?,
data: AttestationData {
Expand All @@ -133,7 +134,7 @@ impl<E: EthSpec> EarlyAttesterCache<E> {
target: item.target,
},
signature: AggregateSignature::empty(),
};
});

metrics::inc_counter(&metrics::BEACON_EARLY_ATTESTER_CACHE_HITS);

Expand Down
Loading
Loading