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
This commit is contained in:
Paul Hauner 2021-08-06 02:13:15 +00:00
parent 17a2c778e3
commit 71ab16e404
2 changed files with 30 additions and 6 deletions

View File

@ -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;

View File

@ -335,6 +335,9 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
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<T: EthSpec> ProductionValidatorClient<T> {
// 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,