mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
Dedup match_attestation_data
This commit is contained in:
@@ -716,6 +716,21 @@ pub struct AttesterData {
|
|||||||
pub slot: Slot,
|
pub slot: Slot,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AttesterData {
|
||||||
|
pub fn match_attestation_data<E: EthSpec>(
|
||||||
|
&self,
|
||||||
|
attestation_data: &AttestationData,
|
||||||
|
spec: &ChainSpec,
|
||||||
|
) -> bool {
|
||||||
|
if spec.fork_name_at_slot::<E>(attestation_data.slot) < ForkName::Electra {
|
||||||
|
self.slot == attestation_data.slot && self.committee_index == attestation_data.index
|
||||||
|
} else {
|
||||||
|
// After electra `attestation_data.index` is set to 0 and does not match the duties
|
||||||
|
self.slot == attestation_data.index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct ProposerData {
|
pub struct ProposerData {
|
||||||
pub pubkey: PublicKeyBytes,
|
pub pubkey: PublicKeyBytes,
|
||||||
|
|||||||
@@ -14,11 +14,7 @@ use std::ops::Deref;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::time::{sleep, sleep_until, Duration, Instant};
|
use tokio::time::{sleep, sleep_until, Duration, Instant};
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use types::ForkName;
|
use types::{Attestation, AttestationData, ChainSpec, CommitteeIndex, EthSpec, Slot};
|
||||||
use types::{
|
|
||||||
attestation::AttestationBase, AggregateSignature, Attestation, AttestationData,
|
|
||||||
AttestationElectra, BitList, BitVector, ChainSpec, CommitteeIndex, EthSpec, Slot,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Builds an `AttestationService`.
|
/// Builds an `AttestationService`.
|
||||||
pub struct AttestationServiceBuilder<T: SlotClock + 'static, E: EthSpec> {
|
pub struct AttestationServiceBuilder<T: SlotClock + 'static, E: EthSpec> {
|
||||||
@@ -363,17 +359,8 @@ 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)]
|
if !duty.match_attestation_data::<E>(attestation_data, &self.context.eth2_config.spec) {
|
||||||
if duty.slot != attestation_data.slot
|
|
||||||
|| (fork_name < ForkName::Electra && duty.committee_index != attestation_data.index)
|
|
||||||
{
|
|
||||||
crit!(
|
crit!(
|
||||||
log,
|
log,
|
||||||
"Inconsistent validator duties during signing";
|
"Inconsistent validator duties during signing";
|
||||||
@@ -552,23 +539,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;
|
||||||
let selection_proof = duty_and_proof.selection_proof.as_ref()?;
|
let selection_proof = duty_and_proof.selection_proof.as_ref()?;
|
||||||
|
|
||||||
let slot = attestation_data.slot;
|
if !duty.match_attestation_data::<E>(attestation_data, &self.context.eth2_config.spec) {
|
||||||
let committee_index = attestation_data.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