Fix bug when resuming from DB prior to genesis (#946)

* Use default client genesis if no chain in store

* Always use resume if there is a beacon chain
This commit is contained in:
Paul Hauner
2020-04-01 17:41:59 +11:00
committed by GitHub
parent 0759806c89
commit 88d37e96fa
3 changed files with 34 additions and 1 deletions

View File

@@ -151,6 +151,26 @@ where
Ok((builder, spec, context))
})
.and_then(move |(builder, spec, context)| {
let chain_exists = builder
.store_contains_beacon_chain()
.unwrap_or_else(|_| false);
// If the client is expect to resume but there's no beacon chain in the database,
// use the `DepositContract` method. This scenario is quite common when the client
// is shutdown before finding genesis via eth1.
//
// Alternatively, if there's a beacon chain in the database then always resume
// using it.
let client_genesis = if client_genesis == ClientGenesis::Resume && !chain_exists {
info!(context.log, "Defaulting to deposit contract genesis");
ClientGenesis::DepositContract
} else if chain_exists {
ClientGenesis::Resume
} else {
client_genesis
};
let genesis_state_future: Box<dyn Future<Item = _, Error = _> + Send> =
match client_genesis {
ClientGenesis::Interop {

View File

@@ -12,7 +12,7 @@ const TESTNET_SPEC_CONSTANTS: &str = "minimal";
const DEFAULT_FREEZER_DB_DIR: &str = "freezer_db";
/// Defines how the client should initialize the `BeaconChain` and other components.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub enum ClientGenesis {
/// Reads the genesis state and other persisted data from the `Store`.
Resume,