Skip to content

Commit

Permalink
Delete uncompressed genesis states (#2092)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
michaelsproul committed Dec 16, 2020
1 parent 80f47fc commit da1c5fe
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ flamegraph.svg
perf.data*
*.tar.gz
/bin
genesis.ssz
26 changes: 15 additions & 11 deletions common/eth2_network_config/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Downloads a network configuration from Github.
//! Extracts zipped genesis states on first run.
use eth2_config::{
altona, mainnet, medalla, pyrmont, spadina, toledo, Eth2NetArchiveAndDirectory,
GENESIS_FILE_NAME,
Expand Down Expand Up @@ -31,7 +30,16 @@ fn main() {

/// Uncompress the network configs archive into a network configs folder.
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 {
// Extract genesis state from genesis.ssz.zip
let archive_path = network.genesis_state_archive();
let archive_file = File::open(&archive_path)
.map_err(|e| format!("Failed to open archive file {:?}: {:?}", archive_path, e))?;
Expand All @@ -45,18 +53,14 @@ fn uncompress_state(network: &Eth2NetArchiveAndDirectory<'static>) -> Result<(),
GENESIS_FILE_NAME, e
)
})?;
let path = network.dir().join(GENESIS_FILE_NAME);
let mut outfile = File::create(&path)
.map_err(|e| format!("Error while creating file {:?}: {}", path, e))?;
let mut outfile = File::create(&genesis_ssz_path)
.map_err(|e| format!("Error while creating file {:?}: {}", genesis_ssz_path, e))?;
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 {
// Create empty genesis.ssz if genesis is unknown
let genesis_file = network.dir().join(GENESIS_FILE_NAME);
if !genesis_file.exists() {
File::create(genesis_file)
.map_err(|e| format!("Failed to create {}: {}", GENESIS_FILE_NAME, e))?;
}
File::create(genesis_ssz_path)
.map_err(|e| format!("Failed to create {}: {}", GENESIS_FILE_NAME, e))?;
}

Ok(())
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit da1c5fe

Please sign in to comment.