Ensure difficulty/hash/epoch overrides change the ChainSpec (#2798)

* Unify loading of eth2_network_config

* Apply overrides at lighthouse binary level

* Remove duplicate override values

* Add merge values to existing net configs

* Make override flags global

* Add merge fields to testing config

* Add one to TTD

* Fix failing engine tests

* Fix test compile error

* Remove TTD flags

* Move get_eth2_network_config

* Fix warn

* Address review comments
This commit is contained in:
Paul Hauner
2021-11-16 11:46:12 +11:00
parent 47db682d7e
commit afe59afacd
25 changed files with 391 additions and 267 deletions

View File

@@ -23,3 +23,4 @@ hex = "0.4.2"
serde = "1.0.116"
serde_derive = "1.0.116"
serde_json = "1.0.66"
eth2_network_config = { path = "../common/eth2_network_config" }

View File

@@ -1,5 +1,6 @@
use beacon_node::{get_data_dir, get_eth2_network_config, set_network_config};
use beacon_node::{get_data_dir, set_network_config};
use clap::ArgMatches;
use eth2_network_config::Eth2NetworkConfig;
use lighthouse_network::discv5::{enr::CombinedKey, Discv5Config, Enr};
use lighthouse_network::{
discovery::{create_enr_builder_from_config, load_enr_from_disk, use_or_load_enr},
@@ -7,7 +8,6 @@ use lighthouse_network::{
};
use serde_derive::{Deserialize, Serialize};
use ssz::Encode;
use std::convert::TryFrom;
use std::net::SocketAddr;
use std::{marker::PhantomData, path::PathBuf};
use types::EthSpec;
@@ -23,15 +23,13 @@ pub struct BootNodeConfig<T: EthSpec> {
phantom: PhantomData<T>,
}
impl<T: EthSpec> TryFrom<&ArgMatches<'_>> for BootNodeConfig<T> {
type Error = String;
fn try_from(matches: &ArgMatches<'_>) -> Result<Self, Self::Error> {
impl<T: EthSpec> BootNodeConfig<T> {
pub fn new(
matches: &ArgMatches<'_>,
eth2_network_config: &Eth2NetworkConfig,
) -> Result<Self, String> {
let data_dir = get_data_dir(matches);
// Try and grab network config from input CLI params
let eth2_network_config = get_eth2_network_config(matches)?;
// Try and obtain bootnodes
let boot_nodes = {

View File

@@ -2,7 +2,7 @@
use clap::ArgMatches;
use slog::{o, Drain, Level, Logger};
use std::convert::TryFrom;
use eth2_network_config::Eth2NetworkConfig;
use std::fs::File;
use std::path::PathBuf;
mod cli;
@@ -19,6 +19,7 @@ pub fn run(
lh_matches: &ArgMatches<'_>,
bn_matches: &ArgMatches<'_>,
eth_spec_id: EthSpecId,
eth2_network_config: &Eth2NetworkConfig,
debug_level: String,
) {
let debug_level = match debug_level.as_str() {
@@ -56,8 +57,12 @@ pub fn run(
let log = slog_scope::logger();
// Run the main function emitting any errors
if let Err(e) = match eth_spec_id {
EthSpecId::Minimal => main::<types::MinimalEthSpec>(lh_matches, bn_matches, log),
EthSpecId::Mainnet => main::<types::MainnetEthSpec>(lh_matches, bn_matches, log),
EthSpecId::Minimal => {
main::<types::MinimalEthSpec>(lh_matches, bn_matches, eth2_network_config, log)
}
EthSpecId::Mainnet => {
main::<types::MainnetEthSpec>(lh_matches, bn_matches, eth2_network_config, log)
}
} {
slog::crit!(slog_scope::logger(), "{}", e);
}
@@ -66,6 +71,7 @@ pub fn run(
fn main<T: EthSpec>(
lh_matches: &ArgMatches<'_>,
bn_matches: &ArgMatches<'_>,
eth2_network_config: &Eth2NetworkConfig,
log: slog::Logger,
) -> Result<(), String> {
// Builds a custom executor for the bootnode
@@ -74,8 +80,8 @@ fn main<T: EthSpec>(
.build()
.map_err(|e| format!("Failed to build runtime: {}", e))?;
// Parse the CLI args into a useable config
let config: BootNodeConfig<T> = BootNodeConfig::try_from(bn_matches)?;
// parse the CLI args into a useable config
let config: BootNodeConfig<T> = BootNodeConfig::new(bn_matches, eth2_network_config)?;
// Dump config if `dump-config` flag is set
let dump_config = clap_utils::parse_optional::<PathBuf>(lh_matches, "dump-config")?;