Fix minor bugs whilst testing

This commit is contained in:
Paul Hauner
2019-11-25 14:52:09 +11:00
parent 73572c32d4
commit 713c0a8c10
6 changed files with 59 additions and 32 deletions

View File

@@ -10,7 +10,7 @@ use lmd_ghost::LmdGhost;
use operation_pool::DepositInsertStatus; use operation_pool::DepositInsertStatus;
use operation_pool::{OperationPool, PersistedOperationPool}; use operation_pool::{OperationPool, PersistedOperationPool};
use parking_lot::RwLock; use parking_lot::RwLock;
use slog::{crit, debug, error, info, trace, warn, Logger}; use slog::{debug, error, info, trace, warn, Logger};
use slot_clock::SlotClock; use slot_clock::SlotClock;
use ssz::Encode; use ssz::Encode;
use state_processing::per_block_processing::{ use state_processing::per_block_processing::{
@@ -355,9 +355,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// We log warnings or simply fail if there are too many skip slots. This is a // We log warnings or simply fail if there are too many skip slots. This is a
// protection against DoS attacks. // protection against DoS attacks.
if slot > head_state.slot + BLOCK_SKIPPING_FAILURE_THRESHOLD { if slot > head_state.slot + BLOCK_SKIPPING_FAILURE_THRESHOLD {
crit!( error!(
self.log, self.log,
"Refusing to skip more than {} blocks", BLOCK_SKIPPING_LOGGING_THRESHOLD; "Refusing to skip more than {} blocks", BLOCK_SKIPPING_FAILURE_THRESHOLD;
"head_slot" => head_state.slot, "head_slot" => head_state.slot,
"request_slot" => slot "request_slot" => slot
); );

View File

@@ -137,8 +137,9 @@ pub fn get_deposit_count(
block_number, block_number,
timeout, timeout,
) )
.and_then(|result| result.ok_or_else(|| "No response to deposit count".to_string())) .and_then(|result| match result {
.and_then(|bytes| { None => Ok(None),
Some(bytes) => {
if bytes.is_empty() { if bytes.is_empty() {
Ok(None) Ok(None)
} else if bytes.len() == DEPOSIT_COUNT_RESPONSE_BYTES { } else if bytes.len() == DEPOSIT_COUNT_RESPONSE_BYTES {
@@ -151,6 +152,7 @@ pub fn get_deposit_count(
DEPOSIT_COUNT_RESPONSE_BYTES, bytes DEPOSIT_COUNT_RESPONSE_BYTES, bytes
)) ))
} }
}
}) })
} }
@@ -172,8 +174,9 @@ pub fn get_deposit_root(
block_number, block_number,
timeout, timeout,
) )
.and_then(|result| result.ok_or_else(|| "No response to deposit root".to_string())) .and_then(|result| match result {
.and_then(|bytes| { None => Ok(None),
Some(bytes) => {
if bytes.is_empty() { if bytes.is_empty() {
Ok(None) Ok(None)
} else if bytes.len() == DEPOSIT_ROOT_BYTES { } else if bytes.len() == DEPOSIT_ROOT_BYTES {
@@ -184,6 +187,7 @@ pub fn get_deposit_root(
DEPOSIT_ROOT_BYTES, bytes DEPOSIT_ROOT_BYTES, bytes
)) ))
} }
}
}) })
} }

View File

@@ -121,7 +121,7 @@ impl Default for Config {
lowest_cached_block_number: 0, lowest_cached_block_number: 0,
follow_distance: 128, follow_distance: 128,
block_cache_truncation: Some(4_096), block_cache_truncation: Some(4_096),
auto_update_interval_millis: 500, auto_update_interval_millis: 7_000,
blocks_per_log_query: 1_000, blocks_per_log_query: 1_000,
max_log_requests_per_update: None, max_log_requests_per_update: None,
max_blocks_per_update: None, max_blocks_per_update: None,

View File

@@ -268,7 +268,6 @@ fn process_testnet_subcommand(
spec.max_effective_balance = 3_200_000_000; spec.max_effective_balance = 3_200_000_000;
spec.ejection_balance = 1_600_000_000; spec.ejection_balance = 1_600_000_000;
spec.effective_balance_increment = 100_000_000; spec.effective_balance_increment = 100_000_000;
spec.min_genesis_time = 0;
spec.genesis_fork = Fork { spec.genesis_fork = Fork {
previous_version: [0; 4], previous_version: [0; 4],
current_version: [0, 0, 0, 42], current_version: [0, 0, 0, 42],
@@ -276,11 +275,19 @@ fn process_testnet_subcommand(
}; };
client_config.eth1.deposit_contract_address = client_config.eth1.deposit_contract_address =
format!("{}", eth2_testnet_dir.deposit_contract_address()?); format!("{:?}", eth2_testnet_dir.deposit_contract_address()?);
client_config.eth1.deposit_contract_deploy_block = client_config.eth1.deposit_contract_deploy_block =
eth2_testnet_dir.deposit_contract_deploy_block; eth2_testnet_dir.deposit_contract_deploy_block;
spec.min_genesis_time = eth2_testnet_dir.min_genesis_time;
// Note: these constants _should_ only be used during genesis to determine the genesis
// time. This allows the testnet to start shortly after the time + validator count
// conditions are satisified, not 1-2 days.
spec.seconds_per_day = 60;
client_config.eth1.follow_distance = 16; client_config.eth1.follow_distance = 16;
client_config.dummy_eth1_backend = false; client_config.dummy_eth1_backend = false;
client_config.sync_eth1_chain = true;
builder.set_genesis(ClientGenesis::DepositContract) builder.set_genesis(ClientGenesis::DepositContract)
} }

View File

@@ -3,6 +3,7 @@ use serde_derive::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
pub const DEFAULT_HTTP_SERVER: &str = "http://localhost:5052/"; pub const DEFAULT_HTTP_SERVER: &str = "http://localhost:5052/";
pub const DEFAULT_DATA_DIR: &str = ".lighthouse/validators";
/// Specifies a method for obtaining validator keypairs. /// Specifies a method for obtaining validator keypairs.
#[derive(Clone)] #[derive(Clone)]
@@ -37,7 +38,7 @@ impl Default for Config {
/// Build a new configuration from defaults. /// Build a new configuration from defaults.
fn default() -> Self { fn default() -> Self {
Self { Self {
data_dir: PathBuf::from(".lighthouse/validators"), data_dir: PathBuf::from(DEFAULT_DATA_DIR),
key_source: <_>::default(), key_source: <_>::default(),
http_server: DEFAULT_HTTP_SERVER.to_string(), http_server: DEFAULT_HTTP_SERVER.to_string(),
} }
@@ -50,6 +51,21 @@ impl Config {
pub fn from_cli(cli_args: &ArgMatches) -> Result<Config, String> { pub fn from_cli(cli_args: &ArgMatches) -> Result<Config, String> {
let mut config = Config::default(); let mut config = Config::default();
// Read the `--datadir` flag.
//
// If it's not present, try and find the home directory (`~`) and push the default data
// directory onto it.
config.data_dir = cli_args
.value_of("datadir")
.map(PathBuf::from)
.or_else(|| {
dirs::home_dir().map(|mut home| {
home.push(DEFAULT_DATA_DIR);
home
})
})
.ok_or_else(|| "Unable to find a home directory for the datadir".to_string())?;
if let Some(server) = cli_args.value_of("server") { if let Some(server) = cli_args.value_of("server") {
config.http_server = server.to_string(); config.http_server = server.to_string();
} }

View File

@@ -34,7 +34,7 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
log: Logger, log: Logger,
) -> Result<Self, String> { ) -> Result<Self, String> {
let validator_iter = read_dir(&base_dir) let validator_iter = read_dir(&base_dir)
.map_err(|e| format!("Failed to read base directory: {:?}", e))? .map_err(|e| format!("Failed to read base directory {:?}: {:?}", base_dir, e))?
.filter_map(|validator_dir| { .filter_map(|validator_dir| {
let path = validator_dir.ok()?.path(); let path = validator_dir.ok()?.path();