Update account manager config parsing

This commit is contained in:
Paul Hauner
2019-06-09 04:34:56 -04:00
parent 3487b16ce5
commit ab12787610
12 changed files with 66 additions and 96 deletions

View File

@@ -22,7 +22,7 @@ impl<T: EthSpec> BlockProcessingBuilder<T> {
}
}
pub fn set_slot(&mut self, slot: Slot, spec: &ChainSpec) {
pub fn set_slot(&mut self, slot: Slot) {
self.state_builder.teleport_to_slot(slot);
}

View File

@@ -223,7 +223,7 @@ impl ValidatorStatuses {
if is_from_epoch(a, state.current_epoch()) {
status.is_current_epoch_attester = true;
if target_matches_epoch_start_block(a, state, state.current_epoch(), spec)? {
if target_matches_epoch_start_block(a, state, state.current_epoch())? {
status.is_current_epoch_target_attester = true;
}
} else if is_from_epoch(a, state.previous_epoch()) {
@@ -244,7 +244,7 @@ impl ValidatorStatuses {
)?,
});
if target_matches_epoch_start_block(a, state, state.previous_epoch(), spec)? {
if target_matches_epoch_start_block(a, state, state.previous_epoch())? {
status.is_previous_epoch_target_attester = true;
}
@@ -336,7 +336,6 @@ fn target_matches_epoch_start_block<T: EthSpec>(
a: &PendingAttestation,
state: &BeaconState<T>,
epoch: Epoch,
spec: &ChainSpec,
) -> Result<bool, BeaconStateError> {
let slot = epoch.start_slot(T::slots_per_epoch());
let state_boundary_root = *state.get_block_root(slot)?;

View File

@@ -453,11 +453,7 @@ impl<T: EthSpec> BeaconState<T> {
///
/// Spec v0.6.0
// FIXME(sproul): name swap with get_block_root
pub fn get_block_root_at_epoch(
&self,
epoch: Epoch,
spec: &ChainSpec,
) -> Result<&Hash256, BeaconStateError> {
pub fn get_block_root_at_epoch(&self, epoch: Epoch) -> Result<&Hash256, BeaconStateError> {
self.get_block_root(epoch.start_slot(T::slots_per_epoch()))
}

View File

@@ -1,6 +1,6 @@
use crate::{
test_utils::{fork_from_hex_str, TestRandom},
ChainSpec, Epoch,
Epoch,
};
use serde_derive::{Deserialize, Serialize};
@@ -58,6 +58,7 @@ impl Fork {
#[cfg(test)]
mod tests {
use super::*;
use crate::ChainSpec;
ssz_tests!(Fork);
cached_tree_hash_tests!(Fork);

View File

@@ -1,5 +1,6 @@
use clap::ArgMatches;
use serde_derive::{Deserialize, Serialize};
use std::fs;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
@@ -104,3 +105,15 @@ where
Ok(None)
}
}
pub fn get_data_dir(args: &ArgMatches, default_data_dir: PathBuf) -> Result<PathBuf, &'static str> {
if let Some(data_dir) = args.value_of("data_dir") {
Ok(PathBuf::from(data_dir))
} else {
let path = dirs::home_dir()
.ok_or_else(|| "Unable to locate home directory")?
.join(&default_data_dir);
fs::create_dir_all(&path).map_err(|_| "Unable to create data_dir")?;
Ok(path)
}
}