diff --git a/Makefile b/Makefile index 6fadf222f0a..3303882e632 100644 --- a/Makefile +++ b/Makefile @@ -133,7 +133,11 @@ arbitrary-fuzz: # Runs cargo audit (Audit Cargo.lock files for crates with security vulnerabilities reported to the RustSec Advisory Database) audit: cargo install --force cargo-audit - cargo audit + # TODO: we should address this --ignore. + # + # Tracking issue: + # https://github.com/sigp/lighthouse/issues/1669 + cargo audit --ignore RUSTSEC-2020-0043 # Runs `cargo udeps` to check for unused dependencies udeps: diff --git a/common/eth2_config/src/lib.rs b/common/eth2_config/src/lib.rs index ee3898ecff1..89b488d33a2 100644 --- a/common/eth2_config/src/lib.rs +++ b/common/eth2_config/src/lib.rs @@ -52,7 +52,6 @@ pub struct Eth2NetArchiveAndDirectory<'a> { pub name: &'a str, pub unique_id: &'a str, pub archive_name: &'a str, - pub commit: &'a str, pub genesis_is_known: bool, } @@ -76,26 +75,21 @@ impl<'a> Eth2NetArchiveAndDirectory<'a> { #[macro_export] macro_rules! unique_id { - ($name: tt, $commit: tt, $genesis_is_known: tt) => { - concat!("testnet_", $name, "_", $commit, "_", $genesis_is_known); - }; - - ($name: tt, $commit: tt) => { - concat!("testnet_", $name, "_", $commit, ".zip"); + ($name: tt) => { + concat!("testnet_", $name); }; } macro_rules! define_net { - ($title: ident, $macro_title: tt, $name: tt, $commit: tt, $genesis_is_known: tt) => { + ($title: ident, $macro_title: tt, $name: tt, $genesis_is_known: tt) => { #[macro_use] pub mod $title { use super::*; pub const ETH2_NET_DIR: Eth2NetArchiveAndDirectory = Eth2NetArchiveAndDirectory { name: $name, - unique_id: unique_id!($name, $commit, $genesis_is_known), - archive_name: unique_id!($name, $commit), - commit: $commit, + unique_id: unique_id!($name), + archive_name: concat!(unique_id!($name), ".zip"), genesis_is_known: $genesis_is_known, }; @@ -104,33 +98,18 @@ macro_rules! define_net { #[macro_export] macro_rules! $macro_title { ($base_dir: tt, $filename: tt) => { - include_bytes!(concat!( - $base_dir, - unique_id!($name, $commit, $genesis_is_known), - "/", - $filename - )) + include_bytes!(concat!($base_dir, unique_id!($name), "/", $filename)) }; } } }; } -define_net!( - altona, - include_altona_file, - "altona", - "a94e00c1a03df851f960fcf44a79f2a6b1d29af1", - true -); - -define_net!( - medalla, - include_medalla_file, - "medalla", - "09bbf2c9d108944ac934f94ec6a1d0684ca062a5", - true -); +define_net!(altona, include_altona_file, "altona", true); + +define_net!(medalla, include_medalla_file, "medalla", true); + +define_net!(spadina, include_spadina_file, "spadina", false); #[cfg(test)] mod tests { diff --git a/common/eth2_testnet_config/build.rs b/common/eth2_testnet_config/build.rs index eeda3180730..588ec90a04e 100644 --- a/common/eth2_testnet_config/build.rs +++ b/common/eth2_testnet_config/build.rs @@ -1,67 +1,55 @@ //! Downloads a testnet configuration from Github. -use eth2_config::{altona, medalla, Eth2NetArchiveAndDirectory}; +use eth2_config::{altona, medalla, spadina, Eth2NetArchiveAndDirectory}; use std::fs; use std::fs::File; use std::io; use zip::ZipArchive; -const ETH2_NET_DIRS: &[Eth2NetArchiveAndDirectory<'static>] = - &[altona::ETH2_NET_DIR, medalla::ETH2_NET_DIR]; +const ETH2_NET_DIRS: &[Eth2NetArchiveAndDirectory<'static>] = &[ + altona::ETH2_NET_DIR, + medalla::ETH2_NET_DIR, + spadina::ETH2_NET_DIR, +]; fn main() { for testnet in ETH2_NET_DIRS { - let testnet_dir = testnet.dir(); - let archive_fullpath = testnet.archive_fullpath(); - //no need to do anything if archives have already been uncompressed before - if !testnet_dir.exists() { - if archive_fullpath.exists() { - //uncompress archive and continue - let archive_file = match File::open(&archive_fullpath) { - Ok(f) => f, - Err(e) => panic!("Problem opening archive file: {}", e), - }; - - match uncompress(archive_file) { - Ok(_) => (), - Err(e) => panic!(e), - }; - } else { - panic!( - "Couldn't find testnet archive at this location: {:?}", - archive_fullpath - ); - } + match uncompress(testnet) { + Ok(()) => (), + Err(e) => panic!("Failed to uncompress testnet zip file: {}", e), } } } -fn uncompress(archive_file: File) -> Result<(), String> { +/// Uncompress the testnet configs archive into a testnet configs folder. +fn uncompress(testnet: &Eth2NetArchiveAndDirectory<'static>) -> Result<(), String> { + let archive_file = File::open(&testnet.archive_fullpath()) + .map_err(|e| format!("Failed to open archive file: {:?}", e))?; + let mut archive = ZipArchive::new(archive_file).map_err(|e| format!("Error with zip file: {}", e))?; + + // Create testnet dir + fs::create_dir_all(testnet.dir()) + .map_err(|e| format!("Failed to create testnet directory: {:?}", e))?; + + // Create empty genesis.ssz if genesis is unknown + if !testnet.genesis_is_known { + File::create(testnet.dir().join("genesis.ssz")) + .map_err(|e| format!("Failed to create genesis.ssz: {}", e))?; + } + for i in 0..archive.len() { let mut file = archive .by_index(i) .map_err(|e| format!("Error retrieving file {} inside zip: {}", i, e))?; - let outpath = file.sanitized_name(); + let path = testnet.dir().join(file.name()); - if file.name().ends_with('/') { - fs::create_dir_all(&outpath) - .map_err(|e| format!("Error creating testnet directories: {}", e))?; - } else { - if let Some(p) = outpath.parent() { - if !p.exists() { - fs::create_dir_all(&p) - .map_err(|e| format!("Error creating testnet directories: {}", e))?; - } - } - - let mut outfile = File::create(&outpath) - .map_err(|e| format!("Error while creating file {:?}: {}", outpath, e))?; - io::copy(&mut file, &mut outfile) - .map_err(|e| format!("Error writing file {:?}: {}", outpath, e))?; - } + 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))?; } Ok(()) diff --git a/common/eth2_testnet_config/src/lib.rs b/common/eth2_testnet_config/src/lib.rs index d4636e9873f..1b0d4a933a4 100644 --- a/common/eth2_testnet_config/src/lib.rs +++ b/common/eth2_testnet_config/src/lib.rs @@ -7,7 +7,7 @@ //! //! https://github.com/sigp/lighthouse/pull/605 //! -use eth2_config::{include_altona_file, include_medalla_file, unique_id}; +use eth2_config::{include_altona_file, include_medalla_file, include_spadina_file, unique_id}; use enr::{CombinedKey, Enr}; use ssz::{Decode, Encode}; @@ -53,8 +53,9 @@ macro_rules! define_net { const ALTONA: HardcodedNet = define_net!(altona, include_altona_file); const MEDALLA: HardcodedNet = define_net!(medalla, include_medalla_file); +const SPADINA: HardcodedNet = define_net!(spadina, include_spadina_file); -const HARDCODED_NETS: &[HardcodedNet] = &[ALTONA, MEDALLA]; +const HARDCODED_NETS: &[HardcodedNet] = &[ALTONA, MEDALLA, SPADINA]; pub const DEFAULT_HARDCODED_TESTNET: &str = "medalla"; /// Specifies an Eth2 testnet. diff --git a/common/eth2_testnet_config/testnet_altona.zip b/common/eth2_testnet_config/testnet_altona.zip new file mode 100644 index 00000000000..b2c264803aa Binary files /dev/null and b/common/eth2_testnet_config/testnet_altona.zip differ diff --git a/common/eth2_testnet_config/testnet_altona_a94e00c1a03df851f960fcf44a79f2a6b1d29af1.zip b/common/eth2_testnet_config/testnet_altona_a94e00c1a03df851f960fcf44a79f2a6b1d29af1.zip deleted file mode 100644 index 29b9cd0cef3..00000000000 Binary files a/common/eth2_testnet_config/testnet_altona_a94e00c1a03df851f960fcf44a79f2a6b1d29af1.zip and /dev/null differ diff --git a/common/eth2_testnet_config/testnet_medalla.zip b/common/eth2_testnet_config/testnet_medalla.zip new file mode 100644 index 00000000000..fdf8b4e1798 Binary files /dev/null and b/common/eth2_testnet_config/testnet_medalla.zip differ diff --git a/common/eth2_testnet_config/testnet_medalla_09bbf2c9d108944ac934f94ec6a1d0684ca062a5.zip b/common/eth2_testnet_config/testnet_medalla_09bbf2c9d108944ac934f94ec6a1d0684ca062a5.zip deleted file mode 100644 index a6cd0a8430a..00000000000 Binary files a/common/eth2_testnet_config/testnet_medalla_09bbf2c9d108944ac934f94ec6a1d0684ca062a5.zip and /dev/null differ diff --git a/common/eth2_testnet_config/testnet_spadina.zip b/common/eth2_testnet_config/testnet_spadina.zip new file mode 100644 index 00000000000..7b0cb3ef07d Binary files /dev/null and b/common/eth2_testnet_config/testnet_spadina.zip differ diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 52e90f17980..2df5c35396c 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -112,7 +112,7 @@ fn main() { .long("testnet") .value_name("testnet") .help("Name of network lighthouse will connect to") - .possible_values(&["medalla", "altona"]) + .possible_values(&["medalla", "altona", "spadina"]) .conflicts_with("testnet-dir") .takes_value(true) .global(true)