mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-30 19:34:37 +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:
@@ -10,8 +10,8 @@ use std::collections::{HashMap, HashSet};
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use types::{
|
||||
BeaconCommittee, BeaconState, BeaconStateError, BlindedPayload, ChainSpec, Epoch, EthSpec,
|
||||
Hash256, OwnedBeaconCommittee, RelativeEpoch, SignedBeaconBlock, Slot,
|
||||
Attestation, BeaconCommittee, BeaconState, BeaconStateError, BlindedPayload, ChainSpec, Epoch,
|
||||
EthSpec, Hash256, OwnedBeaconCommittee, RelativeEpoch, SignedBeaconBlock, Slot,
|
||||
};
|
||||
use warp_utils::reject::{beacon_chain_error, custom_bad_request, custom_server_error};
|
||||
|
||||
@@ -112,21 +112,29 @@ impl<E: EthSpec> PackingEfficiencyHandler<E> {
|
||||
|
||||
let mut attestations_in_block = HashMap::new();
|
||||
for attestation in attestations.iter() {
|
||||
for (position, voted) in attestation.aggregation_bits.iter().enumerate() {
|
||||
if voted {
|
||||
let unique_attestation = UniqueAttestation {
|
||||
slot: attestation.data.slot,
|
||||
committee_index: attestation.data.index,
|
||||
committee_position: position,
|
||||
};
|
||||
let inclusion_distance: u64 = block
|
||||
.slot()
|
||||
.as_u64()
|
||||
.checked_sub(attestation.data.slot.as_u64())
|
||||
.ok_or(PackingEfficiencyError::InvalidAttestationError)?;
|
||||
match attestation {
|
||||
Attestation::Base(attn) => {
|
||||
for (position, voted) in attn.aggregation_bits.iter().enumerate() {
|
||||
if voted {
|
||||
let unique_attestation = UniqueAttestation {
|
||||
slot: attn.data.slot,
|
||||
committee_index: attn.data.index,
|
||||
committee_position: position,
|
||||
};
|
||||
let inclusion_distance: u64 = block
|
||||
.slot()
|
||||
.as_u64()
|
||||
.checked_sub(attn.data.slot.as_u64())
|
||||
.ok_or(PackingEfficiencyError::InvalidAttestationError)?;
|
||||
|
||||
self.available_attestations.remove(&unique_attestation);
|
||||
attestations_in_block.insert(unique_attestation, inclusion_distance);
|
||||
self.available_attestations.remove(&unique_attestation);
|
||||
attestations_in_block.insert(unique_attestation, inclusion_distance);
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO(electra) implement electra variant
|
||||
Attestation::Electra(_) => {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1799,7 +1799,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.naive_aggregation_pool
|
||||
.read()
|
||||
.iter()
|
||||
.filter(|&att| query_filter(&att.data))
|
||||
.filter(|&att| query_filter(att.data()))
|
||||
.cloned(),
|
||||
);
|
||||
Ok(api_types::GenericResponse::from(attestations))
|
||||
@@ -3162,7 +3162,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
|
||||
chain
|
||||
.produce_unaggregated_attestation(query.slot, query.committee_index)
|
||||
.map(|attestation| attestation.data)
|
||||
.map(|attestation| attestation.data().clone())
|
||||
.map(api_types::GenericResponse::from)
|
||||
.map_err(warp_utils::reject::beacon_chain_error)
|
||||
})
|
||||
@@ -3364,8 +3364,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
"error" => format!("{:?}", e),
|
||||
"request_index" => index,
|
||||
"aggregator_index" => aggregate.message.aggregator_index,
|
||||
"attestation_index" => aggregate.message.aggregate.data.index,
|
||||
"attestation_slot" => aggregate.message.aggregate.data.slot,
|
||||
"attestation_index" => aggregate.message.aggregate.data().index,
|
||||
"attestation_slot" => aggregate.message.aggregate.data().slot,
|
||||
);
|
||||
failures.push(api_types::Failure::new(index, format!("Verification: {:?}", e)));
|
||||
}
|
||||
@@ -3385,8 +3385,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
"error" => format!("{:?}", e),
|
||||
"request_index" => index,
|
||||
"aggregator_index" => verified_aggregate.aggregate().message.aggregator_index,
|
||||
"attestation_index" => verified_aggregate.attestation().data.index,
|
||||
"attestation_slot" => verified_aggregate.attestation().data.slot,
|
||||
"attestation_index" => verified_aggregate.attestation().data().index,
|
||||
"attestation_slot" => verified_aggregate.attestation().data().slot,
|
||||
);
|
||||
failures.push(api_types::Failure::new(index, format!("Fork choice: {:?}", e)));
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ pub async fn publish_attestations<T: BeaconChainTypes>(
|
||||
// move the `attestations` vec into the blocking task, so this small overhead is unavoidable.
|
||||
let attestation_metadata = attestations
|
||||
.iter()
|
||||
.map(|att| (att.data.slot, att.data.index))
|
||||
.map(|att| (att.data().slot, att.data().index))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Gossip validate and publish attestations that can be immediately processed.
|
||||
|
||||
@@ -35,8 +35,8 @@ use tokio::time::Duration;
|
||||
use tree_hash::TreeHash;
|
||||
use types::application_domain::ApplicationDomain;
|
||||
use types::{
|
||||
AggregateSignature, BitList, Domain, EthSpec, ExecutionBlockHash, Hash256, Keypair,
|
||||
MainnetEthSpec, RelativeEpoch, SelectionProof, SignedRoot, Slot,
|
||||
attestation::AttestationBase, AggregateSignature, BitList, Domain, EthSpec, ExecutionBlockHash,
|
||||
Hash256, Keypair, MainnetEthSpec, RelativeEpoch, SelectionProof, SignedRoot, Slot,
|
||||
};
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
@@ -1669,7 +1669,7 @@ impl ApiTester {
|
||||
let mut attestations = Vec::new();
|
||||
for attestation in &self.attestations {
|
||||
let mut invalid_attestation = attestation.clone();
|
||||
invalid_attestation.data.slot += 1;
|
||||
invalid_attestation.data_mut().slot += 1;
|
||||
|
||||
// add both to ensure we only fail on invalid attestations
|
||||
attestations.push(attestation.clone());
|
||||
@@ -1793,7 +1793,7 @@ impl ApiTester {
|
||||
|
||||
pub async fn test_post_beacon_pool_attester_slashings_invalid(mut self) -> Self {
|
||||
let mut slashing = self.attester_slashing.clone();
|
||||
slashing.attestation_1.data.slot += 1;
|
||||
slashing.attestation_1.data_mut().slot += 1;
|
||||
|
||||
self.client
|
||||
.post_beacon_pool_attester_slashings(&slashing)
|
||||
@@ -3168,7 +3168,8 @@ impl ApiTester {
|
||||
.chain
|
||||
.produce_unaggregated_attestation(slot, index)
|
||||
.unwrap()
|
||||
.data;
|
||||
.data()
|
||||
.clone();
|
||||
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
@@ -3188,8 +3189,8 @@ impl ApiTester {
|
||||
let result = self
|
||||
.client
|
||||
.get_validator_aggregate_attestation(
|
||||
attestation.data.slot,
|
||||
attestation.data.tree_hash_root(),
|
||||
attestation.data().slot,
|
||||
attestation.data().tree_hash_root(),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
@@ -3269,11 +3270,11 @@ impl ApiTester {
|
||||
.unwrap()
|
||||
.data;
|
||||
|
||||
let mut attestation = Attestation {
|
||||
let mut attestation = Attestation::Base(AttestationBase {
|
||||
aggregation_bits: BitList::with_capacity(duty.committee_length as usize).unwrap(),
|
||||
data: attestation_data,
|
||||
signature: AggregateSignature::infinity(),
|
||||
};
|
||||
});
|
||||
|
||||
attestation
|
||||
.sign(
|
||||
@@ -3312,7 +3313,7 @@ impl ApiTester {
|
||||
pub async fn test_get_validator_aggregate_and_proofs_invalid(mut self) -> Self {
|
||||
let mut aggregate = self.get_aggregate().await;
|
||||
|
||||
aggregate.message.aggregate.data.slot += 1;
|
||||
aggregate.message.aggregate.data_mut().slot += 1;
|
||||
|
||||
self.client
|
||||
.post_validator_aggregate_and_proof::<E>(&[aggregate])
|
||||
|
||||
Reference in New Issue
Block a user