2021-07-09 06:15:32 +00:00
|
|
|
use crate::transition_blocks::load_from_ssz_with;
|
2020-05-03 22:04:00 +00:00
|
|
|
use clap::ArgMatches;
|
2021-07-09 06:15:32 +00:00
|
|
|
use eth2_network_config::Eth2NetworkConfig;
|
2020-05-03 22:04:00 +00:00
|
|
|
use ssz::Encode;
|
|
|
|
use state_processing::per_slot_processing;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use types::{BeaconState, EthSpec};
|
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(), String> {
|
2020-05-03 22:04:00 +00:00
|
|
|
let pre_state_path = matches
|
|
|
|
.value_of("pre-state")
|
2020-12-03 01:10:26 +00:00
|
|
|
.ok_or("No pre-state file supplied")?
|
2020-05-03 22:04:00 +00:00
|
|
|
.parse::<PathBuf>()
|
|
|
|
.map_err(|e| format!("Failed to parse pre-state path: {}", e))?;
|
|
|
|
|
|
|
|
let slots = matches
|
|
|
|
.value_of("slots")
|
2020-12-03 01:10:26 +00:00
|
|
|
.ok_or("No slots supplied")?
|
2020-05-03 22:04:00 +00:00
|
|
|
.parse::<usize>()
|
|
|
|
.map_err(|e| format!("Failed to parse slots: {}", e))?;
|
|
|
|
|
|
|
|
let output_path = matches
|
|
|
|
.value_of("output")
|
2020-12-03 01:10:26 +00:00
|
|
|
.ok_or("No output file supplied")?
|
2020-05-03 22:04:00 +00:00
|
|
|
.parse::<PathBuf>()
|
|
|
|
.map_err(|e| format!("Failed to parse output path: {}", e))?;
|
|
|
|
|
2020-05-19 03:49:23 +00:00
|
|
|
info!("Using {} spec", T::spec_name());
|
2020-05-03 22:04:00 +00:00
|
|
|
info!("Pre-state path: {:?}", pre_state_path);
|
|
|
|
info!("Slots: {:?}", slots);
|
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let eth2_network_config = Eth2NetworkConfig::load(testnet_dir)?;
|
|
|
|
let spec = ð2_network_config.chain_spec::<T>()?;
|
2020-05-03 22:04:00 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut state: BeaconState<T> =
|
|
|
|
load_from_ssz_with(&pre_state_path, spec, BeaconState::from_ssz_bytes)?;
|
2020-05-03 22:04:00 +00:00
|
|
|
|
|
|
|
state
|
|
|
|
.build_all_caches(spec)
|
|
|
|
.map_err(|e| format!("Unable to build caches: {:?}", e))?;
|
|
|
|
|
|
|
|
// Transition the parent state to the block slot.
|
|
|
|
for i in 0..slots {
|
|
|
|
per_slot_processing(&mut state, None, spec)
|
|
|
|
.map_err(|e| format!("Failed to advance slot on iteration {}: {:?}", i, e))?;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut output_file =
|
|
|
|
File::create(output_path).map_err(|e| format!("Unable to create output file: {:?}", e))?;
|
|
|
|
|
|
|
|
output_file
|
|
|
|
.write_all(&state.as_ssz_bytes())
|
|
|
|
.map_err(|e| format!("Unable to write to output file: {:?}", e))?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|