-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Static testnet configs #1603
Changes from 4 commits
aeb009c
8547bf9
67c9ac3
e548147
7fff64f
0d228da
ae2ab3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
testnet* | ||
testnet*/* | ||
schlesi-* | ||
witti-* | ||
altona* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ reqwest = { version = "0.10.4", features = ["blocking", "native-tls-vendored"] } | |
eth2_config = { path = "../eth2_config"} | ||
handlebars = "3.3.0" | ||
serde_json = "1.0.56" | ||
zip = "0.5" | ||
|
||
[dev-dependencies] | ||
tempdir = "0.3.7" | ||
|
@@ -21,4 +22,4 @@ serde_yaml = "0.8.11" | |
types = { path = "../../consensus/types"} | ||
enr = { version = "0.1.0", features = ["libsecp256k1", "ed25519"] } | ||
eth2_ssz = "0.1.2" | ||
eth2_config = { path = "../eth2_config"} | ||
eth2_config = { path = "../eth2_config"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a newline here |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,53 @@ | ||
//! Downloads a testnet configuration from Github. | ||
|
||
use eth2_config::{altona, medalla, Eth2NetDirectory}; | ||
use eth2_config::{altona, medalla, Eth2NetArchiveAndDirectory}; | ||
use handlebars::Handlebars; | ||
use serde_json::json; | ||
use std::fs; | ||
use std::fs::File; | ||
use std::io; | ||
use std::io::Write; | ||
use zip::ZipArchive; | ||
|
||
const ETH2_NET_DIRS: &[Eth2NetDirectory<'static>] = &[altona::ETH2_NET_DIR, medalla::ETH2_NET_DIR]; | ||
const ETH2_NET_DIRS: &[Eth2NetArchiveAndDirectory<'static>] = | ||
&[altona::ETH2_NET_DIR, medalla::ETH2_NET_DIR]; | ||
|
||
fn main() { | ||
for testnet in ETH2_NET_DIRS { | ||
let testnet_dir = testnet.dir(); | ||
let archive_fullpath = testnet.archive_fullpath(); | ||
println!("archive fullpath: {:?}", archive_fullpath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think we should print things during a build script |
||
|
||
if !testnet_dir.exists() { | ||
std::fs::create_dir_all(&testnet_dir) | ||
.unwrap_or_else(|_| panic!("Unable to create {:?}", testnet_dir)); | ||
|
||
match get_all_files(testnet) { | ||
Ok(()) => (), | ||
Err(e) => { | ||
std::fs::remove_dir_all(&testnet_dir).unwrap_or_else(|_| panic!( | ||
"{}. Failed to remove {:?}, please remove the directory manually because it may contains incomplete testnet data.", | ||
e, | ||
testnet_dir, | ||
)); | ||
panic!(e); | ||
if !testnet_dir.exists() && archive_fullpath.exists() { | ||
//uncompress archive and continue | ||
let archive_file = File::open(&archive_fullpath).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use the |
||
uncompress(archive_file); | ||
} | ||
} | ||
} | ||
|
||
fn uncompress(archive_file: File) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A general rule of thumb is to not use For this function, you can handle the errors more ergonomically by letting it return a result such as |
||
let mut archive = ZipArchive::new(archive_file).unwrap(); | ||
for i in 0..archive.len() { | ||
let mut file = archive.by_index(i).unwrap(); | ||
let outpath = file.sanitized_name(); | ||
|
||
if (file.name().ends_with('/')) { | ||
fs::create_dir_all(&outpath).unwrap(); | ||
} else { | ||
if let Some(p) = outpath.parent() { | ||
if !p.exists() { | ||
fs::create_dir_all(&p).unwrap(); | ||
} | ||
} | ||
|
||
let mut outfile = File::create(&outpath).unwrap(); | ||
io::copy(&mut file, &mut outfile).unwrap(); | ||
} | ||
} | ||
} | ||
|
||
fn get_all_files(testnet: &Eth2NetDirectory<'static>) -> Result<(), String> { | ||
fn get_all_files(testnet: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), String> { | ||
get_file(testnet, "boot_enr.yaml")?; | ||
get_file(testnet, "config.yaml")?; | ||
get_file(testnet, "deploy_block.txt")?; | ||
|
@@ -46,7 +62,7 @@ fn get_all_files(testnet: &Eth2NetDirectory<'static>) -> Result<(), String> { | |
Ok(()) | ||
} | ||
|
||
fn get_file(testnet: &Eth2NetDirectory, filename: &str) -> Result<(), String> { | ||
fn get_file(testnet: &Eth2NetArchiveAndDirectory, filename: &str) -> Result<(), String> { | ||
let url = Handlebars::new() | ||
.render_template( | ||
testnet.url_template, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we need the url_template anymore right?