Delete uncompressed genesis states (#2092)

## Issue Addressed

Replaces #2091

## Proposed Changes

* Delete the uncompressed genesis states from `eth2_network_config` after they were merged accidentally in #2029.
* Tweak the build script to not overwrite `genesis.ssz` on every build, which caused spurious rebuilds.
This commit is contained in:
Michael Sproul 2020-12-16 03:44:05 +00:00
parent 80f47fcfff
commit da1c5fe69d
9 changed files with 16 additions and 11 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ flamegraph.svg
perf.data* perf.data*
*.tar.gz *.tar.gz
/bin /bin
genesis.ssz

View File

@ -1,5 +1,4 @@
//! Downloads a network configuration from Github. //! Extracts zipped genesis states on first run.
use eth2_config::{ use eth2_config::{
altona, mainnet, medalla, pyrmont, spadina, toledo, Eth2NetArchiveAndDirectory, altona, mainnet, medalla, pyrmont, spadina, toledo, Eth2NetArchiveAndDirectory,
GENESIS_FILE_NAME, GENESIS_FILE_NAME,
@ -31,7 +30,16 @@ fn main() {
/// Uncompress the network configs archive into a network configs folder. /// Uncompress the network configs archive into a network configs folder.
fn uncompress_state(network: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), String> { fn uncompress_state(network: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), String> {
let genesis_ssz_path = network.dir().join(GENESIS_FILE_NAME);
// Take care to not overwrite the genesis.ssz if it already exists, as that causes
// spurious rebuilds.
if genesis_ssz_path.exists() {
return Ok(());
}
if network.genesis_is_known { if network.genesis_is_known {
// Extract genesis state from genesis.ssz.zip
let archive_path = network.genesis_state_archive(); let archive_path = network.genesis_state_archive();
let archive_file = File::open(&archive_path) let archive_file = File::open(&archive_path)
.map_err(|e| format!("Failed to open archive file {:?}: {:?}", archive_path, e))?; .map_err(|e| format!("Failed to open archive file {:?}: {:?}", archive_path, e))?;
@ -45,19 +53,15 @@ fn uncompress_state(network: &Eth2NetArchiveAndDirectory<'static>) -> Result<(),
GENESIS_FILE_NAME, e GENESIS_FILE_NAME, e
) )
})?; })?;
let path = network.dir().join(GENESIS_FILE_NAME); let mut outfile = File::create(&genesis_ssz_path)
let mut outfile = File::create(&path) .map_err(|e| format!("Error while creating file {:?}: {}", genesis_ssz_path, e))?;
.map_err(|e| format!("Error while creating file {:?}: {}", path, e))?;
io::copy(&mut file, &mut outfile) io::copy(&mut file, &mut outfile)
.map_err(|e| format!("Error writing file {:?}: {}", path, e))?; .map_err(|e| format!("Error writing file {:?}: {}", genesis_ssz_path, e))?;
} else { } else {
// Create empty genesis.ssz if genesis is unknown // Create empty genesis.ssz if genesis is unknown
let genesis_file = network.dir().join(GENESIS_FILE_NAME); File::create(genesis_ssz_path)
if !genesis_file.exists() {
File::create(genesis_file)
.map_err(|e| format!("Failed to create {}: {}", GENESIS_FILE_NAME, e))?; .map_err(|e| format!("Failed to create {}: {}", GENESIS_FILE_NAME, e))?;
} }
}
Ok(()) Ok(())
} }