mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 12:47:05 +00:00
fix default network handling (#2029)
## Issue Addressed #1992 and #1987, and also to be considered a continuation of #1751 ## Proposed Changes many changed files but most are renaming to align the code with the semantics of `--network` - remove the `--network` default value (in clap) and instead set it after checking the `network` and `testnet-dir` flags - move `eth2_testnet_config` crate to `eth2_network_config` - move `Eth2TestnetConfig` to `Eth2NetworkConfig` - move `DEFAULT_HARDCODED_TESTNET` to `DEFAULT_HARDCODED_NETWORK` - `beacon_node`s `get_eth2_testnet_config` loads the `DEFAULT_HARDCODED_NETWORK` if there is no network nor testnet provided - `boot_node`s config loads the config same as the `beacon_node`, it was using the configuration only for preconfigured networks (That code is ~1year old so I asume it was not intended) - removed a one year old comment stating we should try to emulate `https://github.com/eth2-clients/eth2-testnets/tree/master/nimbus/testnet1` it looks outdated (?) - remove `lighthouse`s `load_testnet_config` in favor of `get_eth2_network_config` to centralize that logic (It had differences) - some spelling ## Additional Info Both the command of #1992 and the scripts of #1987 seem to work fine, same as `bn` and `vc`
This commit is contained in:
63
common/eth2_network_config/build.rs
Normal file
63
common/eth2_network_config/build.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
//! Downloads a network 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 network in ETH2_NET_DIRS {
|
||||
match uncompress_state(network) {
|
||||
Ok(()) => (),
|
||||
Err(e) => panic!(
|
||||
"Failed to uncompress {} genesis state zip file: {}",
|
||||
network.name, e
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Uncompress the network configs archive into a network configs folder.
|
||||
fn uncompress_state(network: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), String> {
|
||||
if network.genesis_is_known {
|
||||
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))?;
|
||||
|
||||
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 = network.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 = 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))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user