From 46c29b09b7d044bedcccf0921a1e87cf9e658a5a Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Fri, 9 May 2025 14:15:46 +0800 Subject: [PATCH] fix --- validator_client/src/lib.rs | 31 +++++++------ .../validator_services/src/duties_service.rs | 44 ++++++++++++------- .../validator_services/src/sync.rs | 12 +++-- validator_client/validator_store/src/lib.rs | 1 - 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index daf80895c3..0eadffacfb 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -483,7 +483,7 @@ impl ProductionValidatorClient { } }; - let sync_selection_proof_config = if config.distributed { + let _sync_selection_proof_config = if config.distributed { SelectionProofConfig { lookahead_slot: AGGREGATION_PRE_COMPUTE_SLOTS_DISTRIBUTED, computation_offset: Duration::default(), @@ -499,21 +499,20 @@ impl ProductionValidatorClient { } }; - let duties_context = context.service_context("duties".into()); - let duties_service = Arc::new(DutiesService { - attesters: <_>::default(), - proposers: <_>::default(), - sync_duties: SyncDutiesMap::new(sync_selection_proof_config), - slot_clock: slot_clock.clone(), - beacon_nodes: beacon_nodes.clone(), - validator_store: validator_store.clone(), - unknown_validator_next_poll_slots: <_>::default(), - spec: context.eth2_config.spec.clone(), - context: duties_context, - enable_high_validator_count_metrics: config.enable_high_validator_count_metrics, - selection_proof_config: attestation_selection_proof_config, - disable_attesting: config.disable_attesting, - }); + let duties_service: Arc< + DutiesService, SystemTimeSlotClock>, + > = Arc::new( + DutiesServiceBuilder::new() + .slot_clock(slot_clock.clone()) + .beacon_nodes(beacon_nodes.clone()) + .validator_store(validator_store.clone()) + .spec(context.eth2_config.spec.clone()) + .executor(context.executor.clone()) + .enable_high_validator_count_metrics(config.enable_high_validator_count_metrics) + .selection_proof_config(attestation_selection_proof_config) + .disable_attesting(config.disable_attesting) + .build()?, + ); // Update the metrics server. if let Some(ctx) = &validator_metrics_ctx { diff --git a/validator_client/validator_services/src/duties_service.rs b/validator_client/validator_services/src/duties_service.rs index b1c418de88..8902684cb1 100644 --- a/validator_client/validator_services/src/duties_service.rs +++ b/validator_client/validator_services/src/duties_service.rs @@ -114,6 +114,7 @@ pub struct SubscriptionSlots { duty_slot: Slot, } +#[derive(Copy, Clone)] pub struct SelectionProofConfig { pub lookahead_slot: u64, pub computation_offset: Duration, // The seconds to compute the selection proof before a slot @@ -121,16 +122,27 @@ pub struct SelectionProofConfig { pub parallel_sign: bool, } +impl SelectionProofConfig { + fn default() -> Self { + Self { + lookahead_slot: 0, + computation_offset: Duration::default(), + selections_endpoint: false, + parallel_sign: false, + } + } +} + /// Create a selection proof for `duty`. /// /// Return `Ok(None)` if the attesting validator is not an aggregator. -async fn make_selection_proof( +async fn make_selection_proof( duty: &AttesterData, validator_store: &S, spec: &ChainSpec, - beacon_nodes: &Arc>, + beacon_nodes: &Arc>, config: &SelectionProofConfig, -) -> Result, Error> { +) -> Result, Error> { let selection_proof = if config.selections_endpoint { let beacon_committee_selection = BeaconCommitteeSelection { validator_index: duty.validator_index, @@ -266,7 +278,7 @@ pub struct DutiesServiceBuilder { //// Whether we permit large validator counts in the metrics. enable_high_validator_count_metrics: bool, /// If this validator is running in distributed mode. - distributed: bool, + selection_proof_config: SelectionProofConfig, disable_attesting: bool, } @@ -285,7 +297,7 @@ impl DutiesServiceBuilder { executor: None, spec: None, enable_high_validator_count_metrics: false, - distributed: false, + selection_proof_config: SelectionProofConfig::default(), disable_attesting: false, } } @@ -323,8 +335,8 @@ impl DutiesServiceBuilder { self } - pub fn distributed(mut self, distributed: bool) -> Self { - self.distributed = distributed; + pub fn selection_proof_config(mut self, selection_proof_config: SelectionProofConfig) -> Self { + self.selection_proof_config = selection_proof_config; self } @@ -337,7 +349,7 @@ impl DutiesServiceBuilder { Ok(DutiesService { attesters: Default::default(), proposers: Default::default(), - sync_duties: SyncDutiesMap::new(self.distributed), + sync_duties: SyncDutiesMap::new(self.selection_proof_config), validator_store: self .validator_store .ok_or("Cannot build DutiesService without validator_store")?, @@ -353,7 +365,7 @@ impl DutiesServiceBuilder { .ok_or("Cannot build DutiesService without executor")?, spec: self.spec.ok_or("Cannot build DutiesService without spec")?, enable_high_validator_count_metrics: self.enable_high_validator_count_metrics, - distributed: self.distributed, + selection_proof_config: self.selection_proof_config, disable_attesting: self.disable_attesting, }) } @@ -1168,9 +1180,9 @@ async fn post_validator_duties_attester( +fn process_duty_and_proof( attesters: &mut RwLockWriteGuard, - result: Result<(AttesterData, Option), Error>, + result: Result<(AttesterData, Option), Error>, dependent_root: Hash256, current_slot: Slot, ) -> bool { @@ -1198,7 +1210,7 @@ fn process_duty_and_proof( }; let attester_map = attesters.entry(duty.pubkey).or_default(); - let epoch = duty.slot.epoch(E::slots_per_epoch()); + let epoch = duty.slot.epoch(S::E::slots_per_epoch()); match attester_map.entry(epoch) { hash_map::Entry::Occupied(mut entry) => { // No need to update duties for which no proof was computed. @@ -1304,7 +1316,7 @@ async fn fill_in_selection_proofs( + if !process_duty_and_proof::( &mut attesters, result, dependent_root, @@ -1332,7 +1344,7 @@ async fn fill_in_selection_proofs( + if !process_duty_and_proof::( &mut attesters, result, dependent_root, diff --git a/validator_client/validator_services/src/sync.rs b/validator_client/validator_services/src/sync.rs index da8aab6401..d2a1aabc5b 100644 --- a/validator_client/validator_services/src/sync.rs +++ b/validator_client/validator_services/src/sync.rs @@ -1,6 +1,4 @@ use crate::duties_service::{DutiesService, Error, SelectionProofConfig}; -// use beacon_node_fallback::BeaconNodeFallback; -use doppelganger_service::DoppelgangerStatus; use eth2::types::{Signature, SyncCommitteeSelection}; use futures::future::join_all; use futures::stream::{FuturesUnordered, StreamExt}; @@ -489,8 +487,8 @@ pub async fn poll_sync_committee_duties_for_period( - duties_service: &Arc>, +pub async fn make_sync_selection_proof( + duties_service: &Arc>, duty: &SyncDuty, proof_slot: Slot, subnet_id: SyncSubnetId, @@ -608,7 +606,7 @@ pub async fn fill_in_aggregation_proofs() { + let subnet_ids = match duty.subnet_ids::() { Ok(subnet_ids) => subnet_ids, Err(e) => { crit!( @@ -646,7 +644,7 @@ pub async fn fill_in_aggregation_proofs() { + match proof.is_aggregator::() { Ok(true) => { if let Some(Some(duty)) = validators.get(&validator_index) { debug!( @@ -703,7 +701,7 @@ pub async fn fill_in_aggregation_proofs { GreaterThanCurrentEpoch { epoch: Epoch, current_epoch: Epoch }, UnableToSignAttestation(AttestationError), SpecificError(T), - UnableToSign(SigningError), Middleware(String), }