mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 12:28:24 +00:00
Change --testnet flag to --network (#1751)
## Issue Addressed - Resolves #1689 ## Proposed Changes TBC ## Additional Info NA
This commit is contained in:
@@ -14,7 +14,7 @@ use ssz::Decode;
|
||||
use std::fs::{create_dir_all, File};
|
||||
use std::io::{Read, Write};
|
||||
use std::path::PathBuf;
|
||||
use types::{Address, BeaconState, EthSpec, EthSpecId, YamlConfig};
|
||||
use types::{BeaconState, EthSpec, EthSpecId, YamlConfig};
|
||||
|
||||
pub const ADDRESS_FILE: &str = "deposit_contract.txt";
|
||||
pub const DEPLOY_BLOCK_FILE: &str = "deploy_block.txt";
|
||||
@@ -29,7 +29,6 @@ pub struct HardcodedNet {
|
||||
pub yaml_config: &'static [u8],
|
||||
pub deploy_block: &'static [u8],
|
||||
pub boot_enr: &'static [u8],
|
||||
pub deposit_contract_address: &'static [u8],
|
||||
pub genesis_state_bytes: &'static [u8],
|
||||
}
|
||||
|
||||
@@ -43,7 +42,6 @@ macro_rules! define_net {
|
||||
yaml_config: $include_file!("../", "config.yaml"),
|
||||
deploy_block: $include_file!("../", "deploy_block.txt"),
|
||||
boot_enr: $include_file!("../", "boot_enr.yaml"),
|
||||
deposit_contract_address: $include_file!("../", "deposit_contract.txt"),
|
||||
genesis_state_bytes: $include_file!("../", "genesis.ssz"),
|
||||
}
|
||||
}};
|
||||
@@ -57,14 +55,13 @@ const MAINNET: HardcodedNet = define_net!(mainnet, include_mainnet_file);
|
||||
const TOLEDO: HardcodedNet = define_net!(toledo, include_toledo_file);
|
||||
|
||||
const HARDCODED_NETS: &[HardcodedNet] = &[ALTONA, MEDALLA, SPADINA, PYRMONT, MAINNET, TOLEDO];
|
||||
pub const DEFAULT_HARDCODED_TESTNET: &str = "medalla";
|
||||
pub const DEFAULT_HARDCODED_TESTNET: &str = "mainnet";
|
||||
|
||||
/// Specifies an Eth2 testnet.
|
||||
///
|
||||
/// See the crate-level documentation for more details.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct Eth2TestnetConfig {
|
||||
pub deposit_contract_address: String,
|
||||
/// Note: instead of the block where the contract is deployed, it is acceptable to set this
|
||||
/// value to be the block number where the first deposit occurs.
|
||||
pub deposit_contract_deploy_block: u64,
|
||||
@@ -74,10 +71,6 @@ pub struct Eth2TestnetConfig {
|
||||
}
|
||||
|
||||
impl Eth2TestnetConfig {
|
||||
/// Returns the default hard coded testnet.
|
||||
pub fn hard_coded_default() -> Result<Option<Self>, String> {
|
||||
Self::constant(DEFAULT_HARDCODED_TESTNET)
|
||||
}
|
||||
/// When Lighthouse is built it includes zero or more "hardcoded" network specifications. This
|
||||
/// function allows for instantiating one of these nets by name.
|
||||
pub fn constant(name: &str) -> Result<Option<Self>, String> {
|
||||
@@ -91,8 +84,6 @@ impl Eth2TestnetConfig {
|
||||
/// Instantiates `Self` from a `HardcodedNet`.
|
||||
fn from_hardcoded_net(net: &HardcodedNet) -> Result<Self, String> {
|
||||
Ok(Self {
|
||||
deposit_contract_address: serde_yaml::from_reader(net.deposit_contract_address)
|
||||
.map_err(|e| format!("Unable to parse contract address: {:?}", e))?,
|
||||
deposit_contract_deploy_block: serde_yaml::from_reader(net.deploy_block)
|
||||
.map_err(|e| format!("Unable to parse deploy block: {:?}", e))?,
|
||||
boot_enr: Some(
|
||||
@@ -177,7 +168,6 @@ impl Eth2TestnetConfig {
|
||||
};
|
||||
}
|
||||
|
||||
write_to_yaml_file!(ADDRESS_FILE, self.deposit_contract_address);
|
||||
write_to_yaml_file!(DEPLOY_BLOCK_FILE, self.deposit_contract_deploy_block);
|
||||
|
||||
if let Some(boot_enr) = &self.boot_enr {
|
||||
@@ -225,7 +215,6 @@ impl Eth2TestnetConfig {
|
||||
};
|
||||
}
|
||||
|
||||
let deposit_contract_address = load_from_file!(ADDRESS_FILE);
|
||||
let deposit_contract_deploy_block = load_from_file!(DEPLOY_BLOCK_FILE);
|
||||
let boot_enr = optional_load_from_file!(BOOT_ENR_FILE);
|
||||
let yaml_config = optional_load_from_file!(YAML_CONFIG_FILE);
|
||||
@@ -247,23 +236,12 @@ impl Eth2TestnetConfig {
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
deposit_contract_address,
|
||||
deposit_contract_deploy_block,
|
||||
boot_enr,
|
||||
genesis_state_bytes,
|
||||
yaml_config,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn deposit_contract_address(&self) -> Result<Address, String> {
|
||||
if self.deposit_contract_address.starts_with("0x") {
|
||||
self.deposit_contract_address[2..]
|
||||
.parse()
|
||||
.map_err(|e| format!("Corrupted address, unable to parse: {:?}", e))
|
||||
} else {
|
||||
Err("Corrupted address, must start with 0x".to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -334,11 +312,9 @@ mod tests {
|
||||
) {
|
||||
let temp_dir = TempDir::new("eth2_testnet_test").expect("should create temp dir");
|
||||
let base_dir = temp_dir.path().join("my_testnet");
|
||||
let deposit_contract_address = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413".to_string();
|
||||
let deposit_contract_deploy_block = 42;
|
||||
|
||||
let testnet: Eth2TestnetConfig = Eth2TestnetConfig {
|
||||
deposit_contract_address,
|
||||
deposit_contract_deploy_block,
|
||||
boot_enr,
|
||||
genesis_state_bytes: genesis_state.as_ref().map(Encode::as_ssz_bytes),
|
||||
|
||||
Reference in New Issue
Block a user