diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index f3af1e669b2..768dbc6cb55 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -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; @@ -107,6 +107,8 @@ impl ProductionValidatorClient { .await .map_err(|e| format!("Unable to initialize validators: {:?}", e))?; + let voting_pubkeys: Vec<_> = validators.iter_voting_pubkeys().collect(); + info!( log, "Initialized validators"; @@ -114,16 +116,21 @@ impl ProductionValidatorClient { "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: {:?}", @@ -143,11 +150,11 @@ impl ProductionValidatorClient { // 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\