lighthouse/common/eth2_testnet_config/build.rs
Age Manning a567f788bd Upgrade to tokio 0.3 (#1839)
## Description

This PR updates Lighthouse to tokio 0.3. It includes a number of dependency updates and some structural changes as to how we create and spawn tasks.

This also brings with it a number of various improvements:

- Discv5 update
- Libp2p update
- Fix for recompilation issues
- Improved UPnP port mapping handling
- Futures dependency update
- Log downgrade to traces for rejecting peers when we've reached our max



Co-authored-by: blacktemplar <blacktemplar@a1.net>
2020-11-28 05:30:57 +00:00

64 lines
2.1 KiB
Rust

//! Downloads a testnet configuration from Github.
use eth2_config::{
altona, mainnet, medalla, pyrmont, spadina, toledo, 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,
mainnet::ETH2_NET_DIR,
pyrmont::ETH2_NET_DIR,
toledo::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> {
if testnet.genesis_is_known {
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))?;
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
let genesis_file = testnet.dir().join(GENESIS_FILE_NAME);
if !genesis_file.exists() {
File::create(genesis_file)
.map_err(|e| format!("Failed to create {}: {}", GENESIS_FILE_NAME, e))?;
}
}
Ok(())
}