Allow validator client to start before genesis

This commit is contained in:
Paul Hauner
2019-09-06 10:03:45 +10:00
parent 940ddd0d13
commit 8b69a48fc5
5 changed files with 48 additions and 37 deletions

View File

@@ -178,7 +178,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
genesis_state.genesis_time,
Duration::from_millis(spec.milliseconds_per_slot),
)
.ok_or_else(|| Error::SlotClockDidNotStart)?;
.map_err(|_| Error::SlotClockDidNotStart)?;
info!(log, "Beacon chain initialized from genesis";
"validator_count" => genesis_state.validators.len(),
@@ -220,7 +220,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state.genesis_time,
Duration::from_millis(spec.milliseconds_per_slot),
)
.ok_or_else(|| Error::SlotClockDidNotStart)?;
.map_err(|_| Error::SlotClockDidNotStart)?;
let last_finalized_root = p.canonical_head.beacon_state.finalized_checkpoint.root;
let last_finalized_block = &p.canonical_head.beacon_block;

View File

@@ -16,7 +16,7 @@ use slog::{crit, error, info, o};
use slot_clock::SlotClock;
use std::marker::PhantomData;
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use tokio::runtime::TaskExecutor;
use tokio::timer::Interval;
use types::EthSpec;
@@ -177,8 +177,18 @@ where
.map_err(error::Error::from)?,
);
if beacon_chain.slot().is_err() {
panic!("Cannot start client before genesis!")
let since_epoch = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_err(|e| format!("Unable to read system time: {}", e))?;
let since_genesis = Duration::from_secs(beacon_chain.head().beacon_state.genesis_time);
if since_genesis > since_epoch {
info!(
log,
"Starting node prior to genesis";
"now" => since_epoch.as_secs(),
"genesis_seconds" => since_genesis.as_secs(),
);
}
let network_config = &client_config.network;