Merge branch 'electra-engine-api' of https://github.com/sigp/lighthouse into beacon-api-electra

This commit is contained in:
realbigsean
2024-06-20 10:46:51 -04:00
142 changed files with 1463 additions and 1485 deletions

View File

@@ -14,11 +14,7 @@ use std::ops::Deref;
use std::sync::Arc;
use tokio::time::{sleep, sleep_until, Duration, Instant};
use tree_hash::TreeHash;
use types::ForkName;
use types::{
attestation::AttestationBase, AggregateSignature, Attestation, AttestationData,
AttestationElectra, BitList, BitVector, ChainSpec, CommitteeIndex, EthSpec, Slot,
};
use types::{Attestation, AttestationData, ChainSpec, CommitteeIndex, EthSpec, Slot};
/// Builds an `AttestationService`.
pub struct AttestationServiceBuilder<T: SlotClock + 'static, E: EthSpec> {
@@ -367,17 +363,8 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
let duty = &duty_and_proof.duty;
let attestation_data = attestation_data_ref;
let fork_name = self
.context
.eth2_config
.spec
.fork_name_at_slot::<E>(attestation_data.slot);
// Ensure that the attestation matches the duties.
#[allow(clippy::suspicious_operation_groupings)]
if duty.slot != attestation_data.slot
|| (fork_name < ForkName::Electra && duty.committee_index != attestation_data.index)
{
if !duty.match_attestation_data::<E>(attestation_data, &self.context.eth2_config.spec) {
crit!(
log,
"Inconsistent validator duties during signing";
@@ -390,25 +377,26 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
return None;
}
let mut attestation = if fork_name >= ForkName::Electra {
let mut committee_bits: BitVector<E::MaxCommitteesPerSlot> = BitVector::default();
committee_bits
.set(duty.committee_index as usize, true)
.unwrap();
Attestation::Electra(AttestationElectra {
aggregation_bits: BitList::with_capacity(duty.committee_length as usize)
.unwrap(),
data: attestation_data.clone(),
committee_bits,
signature: AggregateSignature::infinity(),
})
} else {
Attestation::Base(AttestationBase {
aggregation_bits: BitList::with_capacity(duty.committee_length as usize)
.unwrap(),
data: attestation_data.clone(),
signature: AggregateSignature::infinity(),
})
let mut attestation = match Attestation::<E>::empty_for_signing(
duty.committee_index,
duty.committee_length as usize,
attestation_data.slot,
attestation_data.beacon_block_root,
attestation_data.source,
attestation_data.target,
&self.context.eth2_config.spec,
) {
Ok(attestation) => attestation,
Err(err) => {
crit!(
log,
"Invalid validator duties during signing";
"validator" => ?duty.pubkey,
"duty" => ?duty,
"err" => ?err,
);
return None;
}
};
match self
@@ -577,23 +565,12 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
.await
.map_err(|e| e.to_string())?;
let fork_name = self
.context
.eth2_config
.spec
.fork_name_at_slot::<E>(attestation_data.slot);
// Create futures to produce the signed aggregated attestations.
let signing_futures = validator_duties.iter().map(|duty_and_proof| async move {
let duty = &duty_and_proof.duty;
let selection_proof = duty_and_proof.selection_proof.as_ref()?;
let slot = attestation_data.slot;
let committee_index = attestation_data.index;
if duty.slot != slot
|| (fork_name < ForkName::Electra && duty.committee_index != committee_index)
{
if !duty.match_attestation_data::<E>(attestation_data, &self.context.eth2_config.spec) {
crit!(log, "Inconsistent validator duties during signing");
return None;
}

View File

@@ -1115,7 +1115,7 @@ mod test {
)
// All validators should still be disabled.
.assert_all_disabled()
// The states of all validators should be jammed with `u64::max_value()`.
// The states of all validators should be jammed with `u64:MAX`.
.assert_all_states(&DoppelgangerState {
next_check_epoch: starting_epoch + 1,
remaining_epochs: u64::MAX,
@@ -1347,7 +1347,7 @@ mod test {
)
.assert_all_states(&DoppelgangerState {
next_check_epoch: initial_epoch + 1,
remaining_epochs: u64::max_value(),
remaining_epochs: u64::MAX,
});
}

View File

@@ -18,16 +18,12 @@ use std::sync::Arc;
use task_executor::TaskExecutor;
use types::{
attestation::Error as AttestationError, graffiti::GraffitiString, AbstractExecPayload, Address,
Attestation, BeaconBlock, BlindedPayload, ChainSpec, ContributionAndProof, Domain, Epoch,
EthSpec, Fork, ForkName, Graffiti, Hash256, PublicKeyBytes, SelectionProof, Signature,
SignedBeaconBlock, SignedContributionAndProof, SignedRoot, SignedValidatorRegistrationData,
SignedVoluntaryExit, Slot, SyncAggregatorSelectionData, SyncCommitteeContribution,
SyncCommitteeMessage, SyncSelectionProof, SyncSubnetId, ValidatorRegistrationData,
VoluntaryExit,
};
use types::{
AggregateAndProof, AggregateAndProofBase, AggregateAndProofElectra, SignedAggregateAndProof,
SignedAggregateAndProofBase, SignedAggregateAndProofElectra,
AggregateAndProof, Attestation, BeaconBlock, BlindedPayload, ChainSpec, ContributionAndProof,
Domain, Epoch, EthSpec, Fork, ForkName, Graffiti, Hash256, PublicKeyBytes, SelectionProof,
Signature, SignedAggregateAndProof, SignedBeaconBlock, SignedContributionAndProof, SignedRoot,
SignedValidatorRegistrationData, SignedVoluntaryExit, Slot, SyncAggregatorSelectionData,
SyncCommitteeContribution, SyncCommitteeMessage, SyncSelectionProof, SyncSubnetId,
ValidatorRegistrationData, VoluntaryExit,
};
pub use crate::doppelganger_service::DoppelgangerStatus;
@@ -805,18 +801,8 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
let signing_epoch = aggregate.data().target.epoch;
let signing_context = self.signing_context(Domain::AggregateAndProof, signing_epoch);
let message = match aggregate {
Attestation::Base(att) => AggregateAndProof::Base(AggregateAndProofBase {
aggregator_index,
aggregate: att,
selection_proof: selection_proof.into(),
}),
Attestation::Electra(att) => AggregateAndProof::Electra(AggregateAndProofElectra {
aggregator_index,
aggregate: att,
selection_proof: selection_proof.into(),
}),
};
let message =
AggregateAndProof::from_attestation(aggregator_index, aggregate, selection_proof);
let signing_method = self.doppelganger_checked_signing_method(validator_pubkey)?;
let signature = signing_method
@@ -830,17 +816,9 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
metrics::inc_counter_vec(&metrics::SIGNED_AGGREGATES_TOTAL, &[metrics::SUCCESS]);
match message {
AggregateAndProof::Base(message) => {
Ok(SignedAggregateAndProof::Base(SignedAggregateAndProofBase {
message,
signature,
}))
}
AggregateAndProof::Electra(message) => Ok(SignedAggregateAndProof::Electra(
SignedAggregateAndProofElectra { message, signature },
)),
}
Ok(SignedAggregateAndProof::from_aggregate_and_proof(
message, signature,
))
}
/// Produces a `SelectionProof` for the `slot`, signed by with corresponding secret key to