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:
Eitan Seri-Levi
2024-04-30 19:49:08 +03:00
committed by GitHub
parent 4a48d7b546
commit 3b7132bc0d
56 changed files with 943 additions and 429 deletions

View File

@@ -241,10 +241,10 @@ pub struct QueuedAttestation {
impl<E: EthSpec> From<&IndexedAttestation<E>> for QueuedAttestation {
fn from(a: &IndexedAttestation<E>) -> Self {
Self {
slot: a.data.slot,
attesting_indices: a.attesting_indices[..].to_vec(),
block_root: a.data.beacon_block_root,
target_epoch: a.data.target.epoch,
slot: a.data().slot,
attesting_indices: a.attesting_indices_to_vec(),
block_root: a.data().beacon_block_root,
target_epoch: a.data().target.epoch,
}
}
}
@@ -948,20 +948,20 @@ where
//
// This is not in the specification, however it should be transparent to other nodes. We
// return early here to avoid wasting precious resources verifying the rest of it.
if indexed_attestation.attesting_indices.is_empty() {
if indexed_attestation.attesting_indices_is_empty() {
return Err(InvalidAttestation::EmptyAggregationBitfield);
}
let target = indexed_attestation.data.target;
let target = indexed_attestation.data().target;
if matches!(is_from_block, AttestationFromBlock::False) {
self.validate_target_epoch_against_current_time(target.epoch)?;
}
if target.epoch != indexed_attestation.data.slot.epoch(E::slots_per_epoch()) {
if target.epoch != indexed_attestation.data().slot.epoch(E::slots_per_epoch()) {
return Err(InvalidAttestation::BadTargetEpoch {
target: target.epoch,
slot: indexed_attestation.data.slot,
slot: indexed_attestation.data().slot,
});
}
@@ -983,9 +983,9 @@ where
// attestation and do not delay consideration for later.
let block = self
.proto_array
.get_block(&indexed_attestation.data.beacon_block_root)
.get_block(&indexed_attestation.data().beacon_block_root)
.ok_or(InvalidAttestation::UnknownHeadBlock {
beacon_block_root: indexed_attestation.data.beacon_block_root,
beacon_block_root: indexed_attestation.data().beacon_block_root,
})?;
// If an attestation points to a block that is from an earlier slot than the attestation,
@@ -993,7 +993,7 @@ where
// is from a prior epoch to the attestation, then the target root must be equal to the root
// of the block that is being attested to.
let expected_target = if target.epoch > block.slot.epoch(E::slots_per_epoch()) {
indexed_attestation.data.beacon_block_root
indexed_attestation.data().beacon_block_root
} else {
block.target_root
};
@@ -1007,10 +1007,10 @@ where
// Attestations must not be for blocks in the future. If this is the case, the attestation
// should not be considered.
if block.slot > indexed_attestation.data.slot {
if block.slot > indexed_attestation.data().slot {
return Err(InvalidAttestation::AttestsToFutureBlock {
block: block.slot,
attestation: indexed_attestation.data.slot,
attestation: indexed_attestation.data().slot,
});
}
@@ -1055,18 +1055,18 @@ where
// (1) becomes weird once we hit finality and fork choice drops the genesis block. (2) is
// fine because votes to the genesis block are not useful; all validators implicitly attest
// to genesis just by being present in the chain.
if attestation.data.beacon_block_root == Hash256::zero() {
if attestation.data().beacon_block_root == Hash256::zero() {
return Ok(());
}
self.validate_on_attestation(attestation, is_from_block)?;
if attestation.data.slot < self.fc_store.get_current_slot() {
for validator_index in attestation.attesting_indices.iter() {
if attestation.data().slot < self.fc_store.get_current_slot() {
for validator_index in attestation.attesting_indices_iter() {
self.proto_array.process_attestation(
*validator_index as usize,
attestation.data.beacon_block_root,
attestation.data.target.epoch,
attestation.data().beacon_block_root,
attestation.data().target.epoch,
)?;
}
} else {
@@ -1088,8 +1088,7 @@ where
/// We assume that the attester slashing provided to this function has already been verified.
pub fn on_attester_slashing(&mut self, slashing: &AttesterSlashing<E>) {
let attesting_indices_set = |att: &IndexedAttestation<E>| {
att.attesting_indices
.iter()
att.attesting_indices_iter()
.copied()
.collect::<BTreeSet<_>>()
};

View File

@@ -435,7 +435,7 @@ impl ForkChoiceTest {
let validator_committee_index = 0;
let validator_index = *head
.beacon_state
.get_beacon_committee(current_slot, attestation.data.index)
.get_beacon_committee(current_slot, attestation.data().index)
.expect("should get committees")
.committee
.get(validator_committee_index)
@@ -831,7 +831,7 @@ async fn invalid_attestation_empty_bitfield() {
.apply_attestation_to_chain(
MutationDelay::NoDelay,
|attestation, _| {
attestation.attesting_indices = vec![].into();
*attestation.attesting_indices_base_mut().unwrap() = vec![].into();
},
|result| {
assert_invalid_attestation!(result, InvalidAttestation::EmptyAggregationBitfield)
@@ -853,7 +853,7 @@ async fn invalid_attestation_future_epoch() {
.apply_attestation_to_chain(
MutationDelay::NoDelay,
|attestation, _| {
attestation.data.target.epoch = Epoch::new(2);
attestation.data_mut().target.epoch = Epoch::new(2);
},
|result| {
assert_invalid_attestation!(
@@ -879,7 +879,7 @@ async fn invalid_attestation_past_epoch() {
.apply_attestation_to_chain(
MutationDelay::NoDelay,
|attestation, _| {
attestation.data.target.epoch = Epoch::new(0);
attestation.data_mut().target.epoch = Epoch::new(0);
},
|result| {
assert_invalid_attestation!(
@@ -903,7 +903,7 @@ async fn invalid_attestation_target_epoch() {
.apply_attestation_to_chain(
MutationDelay::NoDelay,
|attestation, _| {
attestation.data.slot = Slot::new(1);
attestation.data_mut().slot = Slot::new(1);
},
|result| {
assert_invalid_attestation!(
@@ -929,7 +929,7 @@ async fn invalid_attestation_unknown_target_root() {
.apply_attestation_to_chain(
MutationDelay::NoDelay,
|attestation, _| {
attestation.data.target.root = junk;
attestation.data_mut().target.root = junk;
},
|result| {
assert_invalid_attestation!(
@@ -955,7 +955,7 @@ async fn invalid_attestation_unknown_beacon_block_root() {
.apply_attestation_to_chain(
MutationDelay::NoDelay,
|attestation, _| {
attestation.data.beacon_block_root = junk;
attestation.data_mut().beacon_block_root = junk;
},
|result| {
assert_invalid_attestation!(
@@ -979,7 +979,7 @@ async fn invalid_attestation_future_block() {
.apply_attestation_to_chain(
MutationDelay::Blocks(1),
|attestation, chain| {
attestation.data.beacon_block_root = chain
attestation.data_mut().beacon_block_root = chain
.block_at_slot(chain.slot().unwrap(), WhenSlotSkipped::Prev)
.unwrap()
.unwrap()
@@ -1010,13 +1010,13 @@ async fn invalid_attestation_inconsistent_ffg_vote() {
.apply_attestation_to_chain(
MutationDelay::NoDelay,
|attestation, chain| {
attestation.data.target.root = chain
attestation.data_mut().target.root = chain
.block_at_slot(Slot::new(1), WhenSlotSkipped::Prev)
.unwrap()
.unwrap()
.canonical_root();
*attestation_opt.lock().unwrap() = Some(attestation.data.target.root);
*attestation_opt.lock().unwrap() = Some(attestation.data().target.root);
*local_opt.lock().unwrap() = Some(
chain
.block_at_slot(Slot::new(0), WhenSlotSkipped::Prev)
@@ -1069,8 +1069,8 @@ async fn valid_attestation_skip_across_epoch() {
MutationDelay::NoDelay,
|attestation, _chain| {
assert_eq!(
attestation.data.target.root,
attestation.data.beacon_block_root
attestation.data().target.root,
attestation.data().beacon_block_root
)
},
|result| result.unwrap(),