Skip to content

Commit 3b7132b

Browse files
authored
Attestation superstruct changes for EIP 7549 (#5644)
* update * experiment * superstruct changes * revert * superstruct changes * fix tests * indexed attestation * indexed attestation superstruct * updated TODOs
1 parent 4a48d7b commit 3b7132b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+940
-426
lines changed

beacon_node/beacon_chain/src/attestation_simulator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn produce_unaggregated_attestation<T: BeaconChainTypes>(
8282
// Store the unaggregated attestation in the validator monitor for later processing
8383
match chain.produce_unaggregated_attestation(current_slot, beacon_committee_index) {
8484
Ok(unaggregated_attestation) => {
85-
let data = &unaggregated_attestation.data;
85+
let data = unaggregated_attestation.data();
8686

8787
debug!(
8888
chain.log,

beacon_node/beacon_chain/src/attestation_verification.rs

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ pub trait VerifiedAttestation<T: BeaconChainTypes>: Sized {
329329
// Inefficient default implementation. This is overridden for gossip verified attestations.
330330
fn into_attestation_and_indices(self) -> (Attestation<T::EthSpec>, Vec<u64>) {
331331
let attestation = self.attestation().clone();
332-
let attesting_indices = self.indexed_attestation().attesting_indices.clone().into();
332+
let attesting_indices = self.indexed_attestation().attesting_indices_to_vec();
333333
(attestation, attesting_indices)
334334
}
335335
}
@@ -455,17 +455,17 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
455455
verify_propagation_slot_range(&chain.slot_clock, attestation, &chain.spec)?;
456456

457457
// Check the attestation's epoch matches its target.
458-
if attestation.data.slot.epoch(T::EthSpec::slots_per_epoch())
459-
!= attestation.data.target.epoch
458+
if attestation.data().slot.epoch(T::EthSpec::slots_per_epoch())
459+
!= attestation.data().target.epoch
460460
{
461461
return Err(Error::InvalidTargetEpoch {
462-
slot: attestation.data.slot,
463-
epoch: attestation.data.target.epoch,
462+
slot: attestation.data().slot,
463+
epoch: attestation.data().target.epoch,
464464
});
465465
}
466466

467467
// Ensure the valid aggregated attestation has not already been seen locally.
468-
let attestation_data = &attestation.data;
468+
let attestation_data = attestation.data();
469469
let attestation_data_root = attestation_data.tree_hash_root();
470470

471471
if chain
@@ -486,7 +486,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
486486
match chain
487487
.observed_aggregators
488488
.read()
489-
.validator_has_been_observed(attestation.data.target.epoch, aggregator_index as usize)
489+
.validator_has_been_observed(attestation.data().target.epoch, aggregator_index as usize)
490490
{
491491
Ok(true) => Err(Error::AggregatorAlreadyKnown(aggregator_index)),
492492
Ok(false) => Ok(()),
@@ -518,7 +518,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
518518
verify_attestation_target_root::<T::EthSpec>(&head_block, attestation)?;
519519

520520
// Ensure that the attestation has participants.
521-
if attestation.aggregation_bits.is_zero() {
521+
if attestation.is_aggregation_bits_zero() {
522522
Err(Error::EmptyAggregationBitfield)
523523
} else {
524524
Ok(attestation_data_root)
@@ -611,12 +611,12 @@ impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
611611
if chain
612612
.observed_aggregators
613613
.write()
614-
.observe_validator(attestation.data.target.epoch, aggregator_index as usize)
614+
.observe_validator(attestation.data().target.epoch, aggregator_index as usize)
615615
.map_err(BeaconChainError::from)?
616616
{
617617
return Err(Error::PriorAttestationKnown {
618618
validator_index: aggregator_index,
619-
epoch: attestation.data.target.epoch,
619+
epoch: attestation.data().target.epoch,
620620
});
621621
}
622622

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

717717
// Check the attestation's epoch matches its target.
718-
if attestation_epoch != attestation.data.target.epoch {
718+
if attestation_epoch != attestation.data().target.epoch {
719719
return Err(Error::InvalidTargetEpoch {
720-
slot: attestation.data.slot,
721-
epoch: attestation.data.target.epoch,
720+
slot: attestation.data().slot,
721+
epoch: attestation.data().target.epoch,
722722
});
723723
}
724724

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

731731
// Check to ensure that the attestation is "unaggregated". I.e., it has exactly one
732732
// aggregation bit set.
733-
let num_aggregation_bits = attestation.aggregation_bits.num_set_bits();
733+
let num_aggregation_bits = attestation.num_set_aggregation_bits();
734734
if num_aggregation_bits != 1 {
735735
return Err(Error::NotExactlyOneAggregationBitSet(num_aggregation_bits));
736736
}
@@ -757,7 +757,7 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
757757
chain: &BeaconChain<T>,
758758
) -> Result<(u64, SubnetId), Error> {
759759
let expected_subnet_id = SubnetId::compute_subnet_for_attestation_data::<T::EthSpec>(
760-
&indexed_attestation.data,
760+
indexed_attestation.data(),
761761
committees_per_slot,
762762
&chain.spec,
763763
)
@@ -774,8 +774,7 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
774774
};
775775

776776
let validator_index = *indexed_attestation
777-
.attesting_indices
778-
.first()
777+
.attesting_indices_first()
779778
.ok_or(Error::NotExactlyOneAggregationBitSet(0))?;
780779

781780
/*
@@ -785,12 +784,12 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
785784
if chain
786785
.observed_gossip_attesters
787786
.read()
788-
.validator_has_been_observed(attestation.data.target.epoch, validator_index as usize)
787+
.validator_has_been_observed(attestation.data().target.epoch, validator_index as usize)
789788
.map_err(BeaconChainError::from)?
790789
{
791790
return Err(Error::PriorAttestationKnown {
792791
validator_index,
793-
epoch: attestation.data.target.epoch,
792+
epoch: attestation.data().target.epoch,
794793
});
795794
}
796795

@@ -881,12 +880,12 @@ impl<'a, T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'a, T> {
881880
if chain
882881
.observed_gossip_attesters
883882
.write()
884-
.observe_validator(attestation.data.target.epoch, validator_index as usize)
883+
.observe_validator(attestation.data().target.epoch, validator_index as usize)
885884
.map_err(BeaconChainError::from)?
886885
{
887886
return Err(Error::PriorAttestationKnown {
888887
validator_index,
889-
epoch: attestation.data.target.epoch,
888+
epoch: attestation.data().target.epoch,
890889
});
891890
}
892891
Ok(())
@@ -998,28 +997,28 @@ fn verify_head_block_is_known<T: BeaconChainTypes>(
998997
let block_opt = chain
999998
.canonical_head
1000999
.fork_choice_read_lock()
1001-
.get_block(&attestation.data.beacon_block_root)
1000+
.get_block(&attestation.data().beacon_block_root)
10021001
.or_else(|| {
10031002
chain
10041003
.early_attester_cache
1005-
.get_proto_block(attestation.data.beacon_block_root)
1004+
.get_proto_block(attestation.data().beacon_block_root)
10061005
});
10071006

10081007
if let Some(block) = block_opt {
10091008
// Reject any block that exceeds our limit on skipped slots.
10101009
if let Some(max_skip_slots) = max_skip_slots {
1011-
if attestation.data.slot > block.slot + max_skip_slots {
1010+
if attestation.data().slot > block.slot + max_skip_slots {
10121011
return Err(Error::TooManySkippedSlots {
10131012
head_block_slot: block.slot,
1014-
attestation_slot: attestation.data.slot,
1013+
attestation_slot: attestation.data().slot,
10151014
});
10161015
}
10171016
}
10181017

10191018
Ok(block)
1020-
} else if chain.is_pre_finalization_block(attestation.data.beacon_block_root)? {
1019+
} else if chain.is_pre_finalization_block(attestation.data().beacon_block_root)? {
10211020
Err(Error::HeadBlockFinalized {
1022-
beacon_block_root: attestation.data.beacon_block_root,
1021+
beacon_block_root: attestation.data().beacon_block_root,
10231022
})
10241023
} else {
10251024
// The block is either:
@@ -1029,7 +1028,7 @@ fn verify_head_block_is_known<T: BeaconChainTypes>(
10291028
// 2) A post-finalization block that we don't know about yet. We'll queue
10301029
// the attestation until the block becomes available (or we time out).
10311030
Err(Error::UnknownHeadBlock {
1032-
beacon_block_root: attestation.data.beacon_block_root,
1031+
beacon_block_root: attestation.data().beacon_block_root,
10331032
})
10341033
}
10351034
}
@@ -1043,7 +1042,7 @@ pub fn verify_propagation_slot_range<S: SlotClock, E: EthSpec>(
10431042
attestation: &Attestation<E>,
10441043
spec: &ChainSpec,
10451044
) -> Result<(), Error> {
1046-
let attestation_slot = attestation.data.slot;
1045+
let attestation_slot = attestation.data().slot;
10471046
let latest_permissible_slot = slot_clock
10481047
.now_with_future_tolerance(spec.maximum_gossip_clock_disparity())
10491048
.ok_or(BeaconChainError::UnableToReadSlot)?;
@@ -1095,11 +1094,11 @@ pub fn verify_attestation_signature<T: BeaconChainTypes>(
10951094

10961095
let fork = chain
10971096
.spec
1098-
.fork_at_epoch(indexed_attestation.data.target.epoch);
1097+
.fork_at_epoch(indexed_attestation.data().target.epoch);
10991098

11001099
let signature_set = indexed_attestation_signature_set_from_pubkeys(
11011100
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
1102-
&indexed_attestation.signature,
1101+
indexed_attestation.signature(),
11031102
indexed_attestation,
11041103
&fork,
11051104
chain.genesis_validators_root,
@@ -1127,7 +1126,7 @@ pub fn verify_attestation_target_root<E: EthSpec>(
11271126
) -> Result<(), Error> {
11281127
// Check the attestation target root.
11291128
let head_block_epoch = head_block.slot.epoch(E::slots_per_epoch());
1130-
let attestation_epoch = attestation.data.slot.epoch(E::slots_per_epoch());
1129+
let attestation_epoch = attestation.data().slot.epoch(E::slots_per_epoch());
11311130
if head_block_epoch > attestation_epoch {
11321131
// The epoch references an invalid head block from a future epoch.
11331132
//
@@ -1140,7 +1139,7 @@ pub fn verify_attestation_target_root<E: EthSpec>(
11401139
// Reference:
11411140
// https://github.com/ethereum/eth2.0-specs/pull/2001#issuecomment-699246659
11421141
return Err(Error::InvalidTargetRoot {
1143-
attestation: attestation.data.target.root,
1142+
attestation: attestation.data().target.root,
11441143
// It is not clear what root we should expect in this case, since the attestation is
11451144
// fundamentally invalid.
11461145
expected: None,
@@ -1159,9 +1158,9 @@ pub fn verify_attestation_target_root<E: EthSpec>(
11591158
};
11601159

11611160
// Reject any attestation with an invalid target root.
1162-
if target_root != attestation.data.target.root {
1161+
if target_root != attestation.data().target.root {
11631162
return Err(Error::InvalidTargetRoot {
1164-
attestation: attestation.data.target.root,
1163+
attestation: attestation.data().target.root,
11651164
expected: Some(target_root),
11661165
});
11671166
}
@@ -1199,7 +1198,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
11991198

12001199
let fork = chain
12011200
.spec
1202-
.fork_at_epoch(indexed_attestation.data.target.epoch);
1201+
.fork_at_epoch(indexed_attestation.data().target.epoch);
12031202

12041203
let signature_sets = vec![
12051204
signed_aggregate_selection_proof_signature_set(
@@ -1220,7 +1219,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
12201219
.map_err(BeaconChainError::SignatureSetError)?,
12211220
indexed_attestation_signature_set_from_pubkeys(
12221221
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
1223-
&indexed_attestation.signature,
1222+
indexed_attestation.signature(),
12241223
indexed_attestation,
12251224
&fork,
12261225
chain.genesis_validators_root,
@@ -1266,8 +1265,8 @@ where
12661265
T: BeaconChainTypes,
12671266
F: Fn((BeaconCommittee, CommitteesPerSlot)) -> Result<R, Error>,
12681267
{
1269-
let attestation_epoch = attestation.data.slot.epoch(T::EthSpec::slots_per_epoch());
1270-
let target = &attestation.data.target;
1268+
let attestation_epoch = attestation.data().slot.epoch(T::EthSpec::slots_per_epoch());
1269+
let target = &attestation.data().target;
12711270

12721271
// Attestation target must be for a known block.
12731272
//
@@ -1290,12 +1289,12 @@ where
12901289
let committees_per_slot = committee_cache.committees_per_slot();
12911290

12921291
Ok(committee_cache
1293-
.get_beacon_committee(attestation.data.slot, attestation.data.index)
1292+
.get_beacon_committee(attestation.data().slot, attestation.data().index)
12941293
.map(|committee| map_fn((committee, committees_per_slot)))
12951294
.unwrap_or_else(|| {
12961295
Err(Error::NoCommitteeForSlotAndIndex {
1297-
slot: attestation.data.slot,
1298-
index: attestation.data.index,
1296+
slot: attestation.data().slot,
1297+
index: attestation.data().index,
12991298
})
13001299
}))
13011300
})

beacon_node/beacon_chain/src/attestation_verification/batch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ where
7373
let indexed_attestation = &indexed.indexed_attestation;
7474
let fork = chain
7575
.spec
76-
.fork_at_epoch(indexed_attestation.data.target.epoch);
76+
.fork_at_epoch(indexed_attestation.data().target.epoch);
7777

7878
signature_sets.push(
7979
signed_aggregate_selection_proof_signature_set(
@@ -98,7 +98,7 @@ where
9898
signature_sets.push(
9999
indexed_attestation_signature_set_from_pubkeys(
100100
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
101-
&indexed_attestation.signature,
101+
indexed_attestation.signature(),
102102
indexed_attestation,
103103
&fork,
104104
chain.genesis_validators_root,
@@ -182,11 +182,11 @@ where
182182
let indexed_attestation = &partially_verified.indexed_attestation;
183183
let fork = chain
184184
.spec
185-
.fork_at_epoch(indexed_attestation.data.target.epoch);
185+
.fork_at_epoch(indexed_attestation.data().target.epoch);
186186

187187
let signature_set = indexed_attestation_signature_set_from_pubkeys(
188188
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
189-
&indexed_attestation.signature,
189+
indexed_attestation.signature(),
190190
indexed_attestation,
191191
&fork,
192192
chain.genesis_validators_root,

beacon_node/beacon_chain/src/beacon_block_reward.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
202202
let mut previous_epoch_participation = state.previous_epoch_participation()?.clone();
203203

204204
for attestation in block.body().attestations() {
205-
let data = &attestation.data;
205+
let data = attestation.data();
206206
let inclusion_delay = state.slot().safe_sub(data.slot)?.as_u64();
207207
// [Modified in Deneb:EIP7045]
208208
let participation_flag_indices = get_attestation_participation_flag_indices(

0 commit comments

Comments
 (0)