Allow starting from SSZ genesis state
This commit is contained in:
parent
6c50758bdf
commit
11a1505784
@ -4,9 +4,10 @@ use lighthouse_bootstrap::Bootstrapper;
|
|||||||
use merkle_proof::MerkleTree;
|
use merkle_proof::MerkleTree;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
use ssz::Encode;
|
use ssz::{Decode, Encode};
|
||||||
use state_processing::initialize_beacon_state_from_eth1;
|
use state_processing::initialize_beacon_state_from_eth1;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
@ -61,6 +62,20 @@ impl<T: BeaconChainTypes> BeaconChainBuilder<T> {
|
|||||||
Ok(Self::from_genesis_state(genesis_state, spec, log))
|
Ok(Self::from_genesis_state(genesis_state, spec, log))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ssz_state(file: &PathBuf, spec: ChainSpec, log: Logger) -> Result<Self, String> {
|
||||||
|
let mut file = File::open(file.clone())
|
||||||
|
.map_err(|e| format!("Unable to open SSZ genesis state file {:?}: {:?}", file, e))?;
|
||||||
|
|
||||||
|
let mut bytes = vec![];
|
||||||
|
file.read_to_end(&mut bytes)
|
||||||
|
.map_err(|e| format!("Failed to read SSZ file: {:?}", e))?;
|
||||||
|
|
||||||
|
let genesis_state = BeaconState::from_ssz_bytes(&bytes)
|
||||||
|
.map_err(|e| format!("Unable to parse SSZ genesis state file: {:?}", e))?;
|
||||||
|
|
||||||
|
Ok(Self::from_genesis_state(genesis_state, spec, log))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn http_bootstrap(server: &str, spec: ChainSpec, log: Logger) -> Result<Self, String> {
|
pub fn http_bootstrap(server: &str, spec: ChainSpec, log: Logger) -> Result<Self, String> {
|
||||||
let bootstrapper = Bootstrapper::from_server_string(server.to_string())
|
let bootstrapper = Bootstrapper::from_server_string(server.to_string())
|
||||||
.map_err(|e| format!("Failed to initialize bootstrap client: {}", e))?;
|
.map_err(|e| format!("Failed to initialize bootstrap client: {}", e))?;
|
||||||
|
@ -54,6 +54,8 @@ pub enum BeaconChainStartMethod {
|
|||||||
},
|
},
|
||||||
/// Create a new beacon chain by loading a YAML-encoded genesis state from a file.
|
/// Create a new beacon chain by loading a YAML-encoded genesis state from a file.
|
||||||
Yaml { file: PathBuf },
|
Yaml { file: PathBuf },
|
||||||
|
/// Create a new beacon chain by loading a SSZ-encoded genesis state from a file.
|
||||||
|
Ssz { file: PathBuf },
|
||||||
/// Create a new beacon chain by using a HTTP server (running our REST-API) to load genesis and
|
/// Create a new beacon chain by using a HTTP server (running our REST-API) to load genesis and
|
||||||
/// finalized states and blocks.
|
/// finalized states and blocks.
|
||||||
HttpBootstrap { server: String, port: Option<u16> },
|
HttpBootstrap { server: String, port: Option<u16> },
|
||||||
|
@ -138,6 +138,15 @@ where
|
|||||||
);
|
);
|
||||||
BeaconChainBuilder::yaml_state(file, spec.clone(), log.clone())?
|
BeaconChainBuilder::yaml_state(file, spec.clone(), log.clone())?
|
||||||
}
|
}
|
||||||
|
BeaconChainStartMethod::Ssz { file } => {
|
||||||
|
info!(
|
||||||
|
log,
|
||||||
|
"Starting beacon chain";
|
||||||
|
"file" => format!("{:?}", file),
|
||||||
|
"method" => "ssz"
|
||||||
|
);
|
||||||
|
BeaconChainBuilder::ssz_state(file, spec.clone(), log.clone())?
|
||||||
|
}
|
||||||
BeaconChainStartMethod::HttpBootstrap { server, port } => {
|
BeaconChainStartMethod::HttpBootstrap { server, port } => {
|
||||||
info!(
|
info!(
|
||||||
log,
|
log,
|
||||||
|
Loading…
Reference in New Issue
Block a user