mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-04 05:14:33 +00:00
Merge pull request #5835 from realbigsean/fix-validator-logic
Fix validator logic
This commit is contained in:
@@ -18,6 +18,7 @@ use types::{
|
|||||||
attestation::AttestationBase, AggregateSignature, Attestation, AttestationData, BitList,
|
attestation::AttestationBase, AggregateSignature, Attestation, AttestationData, BitList,
|
||||||
ChainSpec, CommitteeIndex, EthSpec, Slot,
|
ChainSpec, CommitteeIndex, EthSpec, Slot,
|
||||||
};
|
};
|
||||||
|
use types::{AttestationElectra, BitVector, ForkName};
|
||||||
|
|
||||||
/// Builds an `AttestationService`.
|
/// Builds an `AttestationService`.
|
||||||
pub struct AttestationServiceBuilder<T: SlotClock + 'static, E: EthSpec> {
|
pub struct AttestationServiceBuilder<T: SlotClock + 'static, E: EthSpec> {
|
||||||
@@ -362,9 +363,16 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
|
|||||||
let duty = &duty_and_proof.duty;
|
let duty = &duty_and_proof.duty;
|
||||||
let attestation_data = attestation_data_ref;
|
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.
|
// Ensure that the attestation matches the duties.
|
||||||
#[allow(clippy::suspicious_operation_groupings)]
|
#[allow(clippy::suspicious_operation_groupings)]
|
||||||
if duty.slot != attestation_data.slot || duty.committee_index != attestation_data.index
|
if duty.slot != attestation_data.slot
|
||||||
|
|| (fork_name < ForkName::Electra && duty.committee_index != attestation_data.index)
|
||||||
{
|
{
|
||||||
crit!(
|
crit!(
|
||||||
log,
|
log,
|
||||||
@@ -378,11 +386,26 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut attestation = Attestation::Base(AttestationBase {
|
let mut attestation = if fork_name >= ForkName::Electra {
|
||||||
aggregation_bits: BitList::with_capacity(duty.committee_length as usize).unwrap(),
|
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(),
|
data: attestation_data.clone(),
|
||||||
signature: AggregateSignature::infinity(),
|
signature: AggregateSignature::infinity(),
|
||||||
});
|
})
|
||||||
|
};
|
||||||
|
|
||||||
match self
|
match self
|
||||||
.validator_store
|
.validator_store
|
||||||
@@ -531,6 +554,12 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.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.
|
// Create futures to produce the signed aggregated attestations.
|
||||||
let signing_futures = validator_duties.iter().map(|duty_and_proof| async move {
|
let signing_futures = validator_duties.iter().map(|duty_and_proof| async move {
|
||||||
let duty = &duty_and_proof.duty;
|
let duty = &duty_and_proof.duty;
|
||||||
@@ -539,7 +568,9 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
|
|||||||
let slot = attestation_data.slot;
|
let slot = attestation_data.slot;
|
||||||
let committee_index = attestation_data.index;
|
let committee_index = attestation_data.index;
|
||||||
|
|
||||||
if duty.slot != slot || duty.committee_index != committee_index {
|
if duty.slot != slot
|
||||||
|
|| (fork_name < ForkName::Electra && duty.committee_index != committee_index)
|
||||||
|
{
|
||||||
crit!(log, "Inconsistent validator duties during signing");
|
crit!(log, "Inconsistent validator duties during signing");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user