diff --git a/validator_client/Cargo.toml b/validator_client/Cargo.toml index 494ebcb3dfc..26dc3596a5f 100644 --- a/validator_client/Cargo.toml +++ b/validator_client/Cargo.toml @@ -62,5 +62,4 @@ url = "2.2.2" malloc_utils = { path = "../common/malloc_utils" } sysinfo = "0.26.5" system_health = { path = "../common/system_health" } -logging = { path = "../common/logging" } - +logging = { path = "../common/logging" } \ No newline at end of file diff --git a/validator_client/src/beacon_node_fallback.rs b/validator_client/src/beacon_node_fallback.rs index a380440e9e7..8f586ffbb32 100644 --- a/validator_client/src/beacon_node_fallback.rs +++ b/validator_client/src/beacon_node_fallback.rs @@ -11,7 +11,6 @@ use crate::http_metrics::metrics::{inc_counter_vec, ENDPOINT_ERRORS, ENDPOINT_RE use environment::RuntimeContext; use eth2::BeaconNodeHttpClient; use futures::future; -use parking_lot::RwLock as PLRwLock; use serde_derive::{Deserialize, Serialize}; use slog::{debug, error, warn, Logger}; use slot_clock::SlotClock; @@ -141,7 +140,7 @@ pub enum CandidateError { pub struct CandidateBeaconNode { id: usize, beacon_node: BeaconNodeHttpClient, - health: PLRwLock>, + health: RwLock>, status: RwLock>, _phantom: PhantomData, } @@ -156,7 +155,10 @@ impl Eq for CandidateBeaconNode {} impl Ord for CandidateBeaconNode { fn cmp(&self, other: &Self) -> Ordering { - match (&(*self.health.read()), &(*other.health.read())) { + match ( + &(*self.health.blocking_read()), + &(*other.health.blocking_read()), + ) { (None, None) => Ordering::Equal, (None, _) => Ordering::Greater, (_, None) => Ordering::Less, @@ -177,7 +179,7 @@ impl CandidateBeaconNode { Self { id, beacon_node, - health: PLRwLock::new(None), + health: RwLock::new(None), status: RwLock::new(Err(CandidateError::Uninitialized)), _phantom: PhantomData, } @@ -232,14 +234,14 @@ impl CandidateBeaconNode { new_health.get_health_tier() ); - *self.health.write() = Some(new_health); + *self.health.write().await = Some(new_health); *self.status.write().await = Ok(()); Ok(()) } Err(status) => { // Set the health as None which is sorted last in the list. - *self.health.write() = None; + *self.health.write().await = None; *self.status.write().await = Err(status); Ok(()) } @@ -367,7 +369,7 @@ impl BeaconNodeFallback { pub async fn num_synced(&self) -> usize { let mut n = 0; for candidate in self.candidates.read().await.iter() { - if let Some(cand) = candidate.health.read().as_ref() { + if let Some(cand) = candidate.health.read().await.as_ref() { if self .distance_tiers .distance_tier(cand.health_tier.sync_distance) @@ -384,7 +386,7 @@ impl BeaconNodeFallback { pub async fn num_synced_fallback(&self) -> usize { let mut n = 0; for candidate in self.candidates.read().await.iter().skip(1) { - if let Some(cand) = candidate.health.read().as_ref() { + if let Some(cand) = candidate.health.read().await.as_ref() { if self .distance_tiers .distance_tier(cand.health_tier.sync_distance) @@ -708,12 +710,12 @@ mod tests { health_tier: BeaconNodeHealthTier::new(4, Slot::new(9), small), }; - *candidate_1.health.write() = Some(health_1); - *candidate_2.health.write() = Some(health_2); - *candidate_3.health.write() = Some(health_3); - *candidate_4.health.write() = Some(health_4); - *candidate_5.health.write() = Some(health_5); - *candidate_6.health.write() = Some(health_6); + *candidate_1.health.blocking_write() = Some(health_1); + *candidate_2.health.blocking_write() = Some(health_2); + *candidate_3.health.blocking_write() = Some(health_3); + *candidate_4.health.blocking_write() = Some(health_4); + *candidate_5.health.blocking_write() = Some(health_5); + *candidate_6.health.blocking_write() = Some(health_6); let mut candidates = vec![ candidate_3,