From 71ab16e4047e5073c68969be4413f4ea11cc76ca Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 6 Aug 2021 02:13:15 +0000 Subject: [PATCH] Register vals with doppelganger earlier (#2494) ## Issue Addressed NA ## Proposed Changes Registers validators with the doppelganger service at the earliest possible point. This avoids the following (non-harmful, but scary) log when pruning the slashing DB on startup: ``` CRIT Validator unknown to doppelganger service, pubkey: 0xabc..., msg: preventing validator from performing duties, service: doppelganger ``` ## Additional Info NA --- validator_client/src/doppelganger_service.rs | 30 ++++++++++++++++++-- validator_client/src/lib.rs | 6 ++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/validator_client/src/doppelganger_service.rs b/validator_client/src/doppelganger_service.rs index 1dee3be11..8df05023e 100644 --- a/validator_client/src/doppelganger_service.rs +++ b/validator_client/src/doppelganger_service.rs @@ -371,7 +371,8 @@ impl DoppelgangerService { slot_clock: &T, ) -> Result<(), String> { let current_epoch = slot_clock - .now() + // If registering before genesis, use the genesis slot. + .now_or_genesis() .ok_or_else(|| "Unable to read slot clock when registering validator".to_string())? .epoch(E::slots_per_epoch()); let genesis_epoch = slot_clock.genesis_slot().epoch(E::slots_per_epoch()); @@ -674,6 +675,9 @@ mod test { const DEFAULT_VALIDATORS: usize = 8; + const GENESIS_TIME: Duration = Duration::from_secs(42); + const SLOT_DURATION: Duration = Duration::from_secs(1); + type E = MainnetEthSpec; fn genesis_epoch() -> Epoch { @@ -703,8 +707,7 @@ mod test { impl TestBuilder { fn build(self) -> TestScenario { let mut rng = XorShiftRng::from_seed([42; 16]); - let slot_clock = - TestingSlotClock::new(Slot::new(0), Duration::from_secs(0), Duration::from_secs(1)); + let slot_clock = TestingSlotClock::new(Slot::new(0), GENESIS_TIME, SLOT_DURATION); let log = null_logger().unwrap(); TestScenario { @@ -737,6 +740,16 @@ mod test { self } + pub fn set_current_time(self, time: Duration) -> Self { + self.slot_clock.set_current_time(time); + self + } + + pub fn assert_prior_to_genesis(self) -> Self { + assert!(self.slot_clock.is_prior_to_genesis().unwrap()); + self + } + pub fn register_all_in_doppelganger_protection_if_enabled(self) -> Self { let mut this = self; for i in 0..this.validators.len() { @@ -1099,6 +1112,17 @@ mod test { }) } + #[test] + fn register_prior_to_genesis() { + let prior_to_genesis = GENESIS_TIME.checked_sub(SLOT_DURATION).unwrap(); + + TestBuilder::default() + .build() + .set_current_time(prior_to_genesis) + .assert_prior_to_genesis() + .register_all_in_doppelganger_protection_if_enabled(); + } + #[test] fn detect_doppelganger_in_starting_epoch() { let epoch = genesis_epoch() + 1; diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index bfdc183d4..32b5bab8c 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -335,6 +335,9 @@ impl ProductionValidatorClient { log.clone(), )); + // Ensure all validators are registered in doppelganger protection. + validator_store.register_all_in_doppelganger_protection_if_enabled()?; + info!( log, "Loaded validator keypair store"; @@ -402,9 +405,6 @@ impl ProductionValidatorClient { // of making too many changes this close to genesis (<1 week). wait_for_genesis(&beacon_nodes, genesis_time, &context).await?; - // Ensure all validators are registered in doppelganger protection. - validator_store.register_all_in_doppelganger_protection_if_enabled()?; - Ok(Self { context, duties_service,