From 87816b5e1f8508f1f743548ceb87063b5a0e50da Mon Sep 17 00:00:00 2001 From: Daniel Knopik Date: Fri, 25 Apr 2025 15:24:12 +0200 Subject: [PATCH] Move notifier and latency service to `validator_services` --- Cargo.lock | 1 + validator_client/src/lib.rs | 17 ++++++++++------ .../validator_services/Cargo.toml | 11 +++++----- .../src/latency_service.rs} | 6 +++--- .../validator_services/src/lib.rs | 2 ++ .../src/notifier_service.rs} | 20 ++++++++++--------- 6 files changed, 34 insertions(+), 23 deletions(-) rename validator_client/{src/latency.rs => validator_services/src/latency_service.rs} (95%) rename validator_client/{src/notifier.rs => validator_services/src/notifier_service.rs} (91%) diff --git a/Cargo.lock b/Cargo.lock index 53592b11bd..dd0c367692 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9819,6 +9819,7 @@ dependencies = [ "parking_lot 0.12.3", "safe_arith", "slot_clock", + "task_executor", "tokio", "tracing", "tree_hash", diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index 7171dea57b..cbfafab412 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -1,7 +1,5 @@ pub mod cli; pub mod config; -mod latency; -mod notifier; use crate::cli::ValidatorClient; pub use config::Config; @@ -20,7 +18,6 @@ use doppelganger_service::DoppelgangerService; use environment::RuntimeContext; use eth2::{reqwest::ClientBuilder, BeaconNodeHttpClient, StatusCode, Timeouts}; use initialized_validators::Error::UnableToOpenVotingKeystore; -use notifier::spawn_notifier; use parking_lot::RwLock; use reqwest::Certificate; use slot_clock::SlotClock; @@ -39,10 +36,12 @@ use tokio::{ use tracing::{debug, error, info, warn}; use types::{EthSpec, Hash256}; use validator_http_api::ApiSecret; +use validator_services::notifier_service::spawn_notifier; use validator_services::{ attestation_service::{AttestationService, AttestationServiceBuilder}, block_service::{BlockService, BlockServiceBuilder}, duties_service::{self, DutiesService}, + latency_service, preparation_service::{PreparationService, PreparationServiceBuilder}, sync::SyncDutiesMap, sync_committee_service::SyncCommitteeService, @@ -600,11 +599,17 @@ impl ProductionValidatorClient { info!("Doppelganger protection disabled.") } - spawn_notifier(self).map_err(|e| format!("Failed to start notifier: {}", e))?; + let context = self.context.service_context("notifier".into()); + spawn_notifier( + self.duties_service.clone(), + context.executor, + &self.context.eth2_config.spec, + ) + .map_err(|e| format!("Failed to start notifier: {}", e))?; if self.config.enable_latency_measurement_service { - latency::start_latency_service( - self.context.clone(), + latency_service::start_latency_service( + self.context.executor.clone(), self.duties_service.slot_clock.clone(), self.duties_service.beacon_nodes.clone(), ); diff --git a/validator_client/validator_services/Cargo.toml b/validator_client/validator_services/Cargo.toml index 4b023bb40a..8c80a99bb8 100644 --- a/validator_client/validator_services/Cargo.toml +++ b/validator_client/validator_services/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Sigma Prime "] [dependencies] beacon_node_fallback = { workspace = true } -bls = { workspace = true } +bls = { workspace = true } doppelganger_service = { workspace = true } either = { workspace = true } environment = { workspace = true } @@ -16,10 +16,11 @@ graffiti_file = { workspace = true } logging = { workspace = true } parking_lot = { workspace = true } safe_arith = { workspace = true } -slot_clock = { workspace = true } -tokio = { workspace = true } +slot_clock = { workspace = true } +task_executor = { workspace = true } +tokio = { workspace = true } tracing = { workspace = true } -tree_hash = { workspace = true } -types = { workspace = true } +tree_hash = { workspace = true } +types = { workspace = true } validator_metrics = { workspace = true } validator_store = { workspace = true } diff --git a/validator_client/src/latency.rs b/validator_client/validator_services/src/latency_service.rs similarity index 95% rename from validator_client/src/latency.rs rename to validator_client/validator_services/src/latency_service.rs index edd8daa731..c53d74b4e5 100644 --- a/validator_client/src/latency.rs +++ b/validator_client/validator_services/src/latency_service.rs @@ -1,7 +1,7 @@ use beacon_node_fallback::BeaconNodeFallback; -use environment::RuntimeContext; use slot_clock::SlotClock; use std::sync::Arc; +use task_executor::TaskExecutor; use tokio::time::sleep; use tracing::debug; use types::EthSpec; @@ -13,7 +13,7 @@ pub const SLOT_DELAY_DENOMINATOR: u32 = 12; /// Starts a service that periodically checks the latency between the VC and the /// candidate BNs. pub fn start_latency_service( - context: RuntimeContext, + executor: TaskExecutor, slot_clock: T, beacon_nodes: Arc>, ) { @@ -57,5 +57,5 @@ pub fn start_latency_service( } }; - context.executor.spawn(future, "latency"); + executor.spawn(future, "latency"); } diff --git a/validator_client/validator_services/src/lib.rs b/validator_client/validator_services/src/lib.rs index abf8fab3cb..3b8bd9ae14 100644 --- a/validator_client/validator_services/src/lib.rs +++ b/validator_client/validator_services/src/lib.rs @@ -1,6 +1,8 @@ pub mod attestation_service; pub mod block_service; pub mod duties_service; +pub mod latency_service; +pub mod notifier_service; pub mod preparation_service; pub mod sync; pub mod sync_committee_service; diff --git a/validator_client/src/notifier.rs b/validator_client/validator_services/src/notifier_service.rs similarity index 91% rename from validator_client/src/notifier.rs rename to validator_client/validator_services/src/notifier_service.rs index 75b3d46457..5b3a26a494 100644 --- a/validator_client/src/notifier.rs +++ b/validator_client/validator_services/src/notifier_service.rs @@ -1,17 +1,19 @@ -use crate::{DutiesService, ProductionValidatorClient}; -use metrics::set_gauge; +use crate::duties_service::DutiesService; use slot_clock::SlotClock; +use std::sync::Arc; +use task_executor::TaskExecutor; use tokio::time::{sleep, Duration}; use tracing::{debug, error, info}; -use types::EthSpec; +use types::{ChainSpec, EthSpec}; +use validator_metrics::set_gauge; /// Spawns a notifier service which periodically logs information about the node. -pub fn spawn_notifier(client: &ProductionValidatorClient) -> Result<(), String> { - let context = client.context.service_context("notifier".into()); - let executor = context.executor.clone(); - let duties_service = client.duties_service.clone(); - - let slot_duration = Duration::from_secs(context.eth2_config.spec.seconds_per_slot); +pub fn spawn_notifier( + duties_service: Arc>, + executor: TaskExecutor, + spec: &ChainSpec, +) -> Result<(), String> { + let slot_duration = Duration::from_secs(spec.seconds_per_slot); let interval_fut = async move { loop {