mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 22:34:45 +00:00
Moved configuration around for validator client.
- Custom datadir/server argument logic moved into configuration, out of main. - Updated the validator config directory structure, as per issue #253 suggestions - Removed the 'generate 3 random keys' function - Updated the README to reflect new structure - Just exit if there are no keys, don't generate any (this is for accounts_manager, in a separate commit). - Created a lib.rs file, so that the validator client configuration can be included by external crates.
This commit is contained in:
@@ -1,24 +1,19 @@
|
||||
use self::block_producer_service::{BeaconBlockGrpcClient, BlockProducerService};
|
||||
use self::duties::{DutiesManager, DutiesManagerService, EpochDutiesMap};
|
||||
use crate::config::ClientConfig;
|
||||
use crate::config::ValidatorClientConfig;
|
||||
use block_proposer::{test_utils::LocalSigner, BlockProducer};
|
||||
use bls::Keypair;
|
||||
use clap::{App, Arg};
|
||||
use grpcio::{ChannelBuilder, EnvBuilder};
|
||||
use protos::services_grpc::{BeaconBlockServiceClient, ValidatorServiceClient};
|
||||
use slog::{debug, error, info, o, Drain};
|
||||
use slog::{error, info, o, Drain};
|
||||
use slot_clock::SystemTimeSlotClock;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use types::ChainSpec;
|
||||
use std::{thread, process, time};
|
||||
|
||||
mod block_producer_service;
|
||||
mod config;
|
||||
mod duties;
|
||||
|
||||
const NUMBER_OF_VALIDATOR_TEST_KEYS: u16 = 3;
|
||||
|
||||
fn main() {
|
||||
// Logging
|
||||
let decorator = slog_term::TermDecorator::new().build();
|
||||
@@ -57,36 +52,11 @@ fn main() {
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let mut config = ClientConfig::default().expect("Unable to create a default configuration.");
|
||||
|
||||
// Custom datadir
|
||||
if let Some(dir) = matches.value_of("datadir") {
|
||||
config.data_dir = PathBuf::from(dir.to_string());
|
||||
}
|
||||
|
||||
// Custom server port
|
||||
if let Some(server_str) = matches.value_of("server") {
|
||||
if let Ok(addr) = server_str.parse::<u16>() {
|
||||
config.server = addr.to_string();
|
||||
} else {
|
||||
error!(log, "Invalid address"; "server" => server_str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Permit loading a custom spec from file.
|
||||
// Custom spec
|
||||
if let Some(spec_str) = matches.value_of("spec") {
|
||||
match spec_str {
|
||||
"foundation" => config.spec = ChainSpec::foundation(),
|
||||
"few_validators" => config.spec = ChainSpec::few_validators(),
|
||||
// Should be impossible due to clap's `possible_values(..)` function.
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
let config = ValidatorClientConfig::build_config(&matches)
|
||||
.expect("Unable to build a configuration for the validator client.");
|
||||
|
||||
// Log configuration
|
||||
info!(log, "";
|
||||
info!(log, "Configuration parameters:";
|
||||
"data_dir" => &config.data_dir.to_str(),
|
||||
"server" => &config.server);
|
||||
|
||||
@@ -121,31 +91,21 @@ fn main() {
|
||||
let poll_interval_millis = spec.seconds_per_slot * 1000 / 10; // 10% epoch time precision.
|
||||
info!(log, "Starting block producer service"; "polls_per_epoch" => spec.seconds_per_slot * 1000 / poll_interval_millis);
|
||||
|
||||
let keypairs = config
|
||||
.fetch_keys()
|
||||
.expect("Encountered an error while fetching saved keys.")
|
||||
.unwrap_or_else(|| {
|
||||
error!(log, "No key pairs found in configuration, they must first be generated with: account_manager generate.");
|
||||
// give the logger a chance to flush the error before exiting.
|
||||
thread::sleep(time::Duration::from_millis(500));
|
||||
process::exit(1)
|
||||
});
|
||||
|
||||
/*
|
||||
* Start threads.
|
||||
*/
|
||||
let mut threads = vec![];
|
||||
|
||||
let keypairs = config
|
||||
.fetch_keys()
|
||||
.expect("Encountered an error while fetching saved keys.")
|
||||
.unwrap_or_else(|| {
|
||||
// TODO: Key generation should occur in a separate binary
|
||||
let mut k = Vec::new();
|
||||
info!(
|
||||
log,
|
||||
"No key pairs found, generating and saving 3 random key pairs."
|
||||
);
|
||||
for _n in 0..NUMBER_OF_VALIDATOR_TEST_KEYS {
|
||||
let keypair = Keypair::random();
|
||||
config
|
||||
.save_key(&keypair)
|
||||
.expect("Unable to save newly generated private key.");
|
||||
debug!(log, "Keypair generated {:?}", keypair.identifier());
|
||||
k.push(keypair);
|
||||
}
|
||||
k
|
||||
});
|
||||
|
||||
for keypair in keypairs {
|
||||
info!(log, "Starting validator services"; "validator" => keypair.pk.concatenated_hex_id());
|
||||
|
||||
Reference in New Issue
Block a user