Skip to content

Commit

Permalink
Allow VC to start without any validators (#1779)
Browse files Browse the repository at this point in the history
## Issue Addressed

NA

## Proposed Changes

- Don't exit early if the VC is without any validators.
- When there are no validators, always create the slashing database (even without `--init-slashing-protection`).
  • Loading branch information
paulhauner committed Oct 21, 2020
1 parent 2acf757 commit 02d94a7
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions validator_client/src/lib.rs
Expand Up @@ -29,7 +29,7 @@ use http_api::ApiSecret;
use initialized_validators::InitializedValidators;
use notifier::spawn_notifier;
use slashing_protection::{SlashingDatabase, SLASHING_PROTECTION_FILENAME};
use slog::{error, info, Logger};
use slog::{error, info, warn, Logger};
use slot_clock::SlotClock;
use slot_clock::SystemTimeSlotClock;
use std::marker::PhantomData;
Expand Down Expand Up @@ -107,23 +107,30 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
.await
.map_err(|e| format!("Unable to initialize validators: {:?}", e))?;

let voting_pubkeys: Vec<_> = validators.iter_voting_pubkeys().collect();

info!(
log,
"Initialized validators";
"disabled" => validators.num_total().saturating_sub(validators.num_enabled()),
"enabled" => validators.num_enabled(),
);

if validators.num_enabled() == 0 {
return Err("Cannot run with 0 enabled validators. \
Please create or import validators before starting the validator client, \
or check your datadir configuration"
.to_string());
if voting_pubkeys.is_empty() {
warn!(
log,
"No enabled validators";
"hint" => "create validators via the API, or the `lighthouse account` CLI command"
);
}

// Initialize slashing protection.
//
// Create the slashing database if there are no validators, even if
// `init_slashing_protection` is not supplied. There is no risk in creating a slashing
// database without any validators in it.
let slashing_db_path = config.validator_dir.join(SLASHING_PROTECTION_FILENAME);
let slashing_protection = if config.init_slashing_protection {
let slashing_protection = if config.init_slashing_protection || voting_pubkeys.is_empty() {
SlashingDatabase::open_or_create(&slashing_db_path).map_err(|e| {
format!(
"Failed to open or create slashing protection database: {:?}",
Expand All @@ -143,11 +150,11 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
// Check validator registration with slashing protection, or auto-register all validators.
if config.init_slashing_protection {
slashing_protection
.register_validators(validators.iter_voting_pubkeys())
.register_validators(voting_pubkeys.iter().copied())
.map_err(|e| format!("Error while registering slashing protection: {:?}", e))?;
} else {
slashing_protection
.check_validator_registrations(validators.iter_voting_pubkeys())
.check_validator_registrations(voting_pubkeys.iter().copied())
.map_err(|e| {
format!(
"One or more validators not found in slashing protection database.\n\
Expand Down

0 comments on commit 02d94a7

Please sign in to comment.