lighthouse/common/eth2_testnet_config/build.rs
Paul Hauner eba51f0973 Update testnet configs, change on-disk format (#1799)
## Issue Addressed

- Related to #1691

## Proposed Changes

- Add `DEPOSIT_CHAIN_ID` and `DEPOSIT_NETWORK_ID` to `config.yaml`.
    - Pass the `DEPOSIT_NETWORK_ID` to the `eth1::Service`.
- Remove the unused `MAX_EPOCHS_PER_CROSSLINK` from the `altona` and `medalla` configs (see [spec commit](2befe90032 (diff-efb845ac2ebd4aafbc23df40f47ce25699255064e99d36d0406d0a14ca7953ec))).
- Change from compressing the whole testnet directory, to only compressing the genesis state file. This is the only file we need to compress and *not* compressing the others makes them work nicely with git.
    - We can modify the boot nodes, configs, etc. without incurring an eternal binary-blob cost on our git history.
    - This change is backwards compatible (i.e., non-breaking).

## Additional Info

NA
2020-10-25 22:15:46 +00:00

58 lines
1.9 KiB
Rust

//! Downloads a testnet configuration from Github.
use eth2_config::{
altona, medalla, spadina, zinken, Eth2NetArchiveAndDirectory, GENESIS_FILE_NAME,
};
use std::fs::File;
use std::io;
use zip::ZipArchive;
const ETH2_NET_DIRS: &[Eth2NetArchiveAndDirectory<'static>] = &[
altona::ETH2_NET_DIR,
medalla::ETH2_NET_DIR,
spadina::ETH2_NET_DIR,
zinken::ETH2_NET_DIR,
];
fn main() {
for testnet in ETH2_NET_DIRS {
match uncompress_state(testnet) {
Ok(()) => (),
Err(e) => panic!(
"Failed to uncompress {} genesis state zip file: {}",
testnet.name, e
),
}
}
}
/// Uncompress the testnet configs archive into a testnet configs folder.
fn uncompress_state(testnet: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), String> {
let archive_path = testnet.genesis_state_archive();
let archive_file = File::open(&archive_path)
.map_err(|e| format!("Failed to open archive file {:?}: {:?}", archive_path, e))?;
let mut archive =
ZipArchive::new(archive_file).map_err(|e| format!("Error with zip file: {}", e))?;
if testnet.genesis_is_known {
let mut file = archive.by_name(GENESIS_FILE_NAME).map_err(|e| {
format!(
"Error retrieving file {} inside zip: {}",
GENESIS_FILE_NAME, e
)
})?;
let path = testnet.dir().join(GENESIS_FILE_NAME);
let mut outfile = File::create(&path)
.map_err(|e| format!("Error while creating file {:?}: {}", path, e))?;
io::copy(&mut file, &mut outfile)
.map_err(|e| format!("Error writing file {:?}: {}", path, e))?;
} else {
// Create empty genesis.ssz if genesis is unknown
File::create(testnet.dir().join(GENESIS_FILE_NAME))
.map_err(|e| format!("Failed to create {}: {}", GENESIS_FILE_NAME, e))?;
}
Ok(())
}