mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-30 11:24:31 +00:00
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:
@@ -249,7 +249,7 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
|
||||
log: self.log.ok_or("Cannot build environment without log")?,
|
||||
eth_spec_instance: self.eth_spec_instance,
|
||||
eth2_config: self.eth2_config,
|
||||
eth2_network_config: self.eth2_network_config,
|
||||
eth2_network_config: self.eth2_network_config.map(Arc::new),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -263,6 +263,7 @@ pub struct RuntimeContext<E: EthSpec> {
|
||||
pub executor: TaskExecutor,
|
||||
pub eth_spec_instance: E,
|
||||
pub eth2_config: Eth2Config,
|
||||
pub eth2_network_config: Option<Arc<Eth2NetworkConfig>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> RuntimeContext<E> {
|
||||
@@ -274,6 +275,7 @@ impl<E: EthSpec> RuntimeContext<E> {
|
||||
executor: self.executor.clone_with_name(service_name),
|
||||
eth_spec_instance: self.eth_spec_instance.clone(),
|
||||
eth2_config: self.eth2_config.clone(),
|
||||
eth2_network_config: self.eth2_network_config.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +303,7 @@ pub struct Environment<E: EthSpec> {
|
||||
log: Logger,
|
||||
eth_spec_instance: E,
|
||||
pub eth2_config: Eth2Config,
|
||||
pub eth2_network_config: Option<Eth2NetworkConfig>,
|
||||
pub eth2_network_config: Option<Arc<Eth2NetworkConfig>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Environment<E> {
|
||||
@@ -324,6 +326,7 @@ impl<E: EthSpec> Environment<E> {
|
||||
),
|
||||
eth_spec_instance: self.eth_spec_instance.clone(),
|
||||
eth2_config: self.eth2_config.clone(),
|
||||
eth2_network_config: self.eth2_network_config.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,6 +341,7 @@ impl<E: EthSpec> Environment<E> {
|
||||
),
|
||||
eth_spec_instance: self.eth_spec_instance.clone(),
|
||||
eth2_config: self.eth2_config.clone(),
|
||||
eth2_network_config: self.eth2_network_config.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
# Extends the mainnet preset
|
||||
PRESET_BASE: 'mainnet'
|
||||
|
||||
# Transition
|
||||
# ---------------------------------------------------------------
|
||||
# TBD, 2**256-2**10 is a placeholder
|
||||
TERMINAL_TOTAL_DIFFICULTY: 115792089237316195423570985008687907853269984665640564039457584007913129638912
|
||||
# By default, don't use these params
|
||||
TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000
|
||||
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615
|
||||
|
||||
# Genesis
|
||||
# ---------------------------------------------------------------
|
||||
# CUSTOMISED FOR TEST
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
mod metrics;
|
||||
|
||||
use beacon_node::{get_eth2_network_config, ProductionBeaconNode};
|
||||
use beacon_node::ProductionBeaconNode;
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use clap_utils::{flags::DISABLE_MALLOC_TUNING_FLAG, parse_optional};
|
||||
use clap_utils::{flags::DISABLE_MALLOC_TUNING_FLAG, get_eth2_network_config};
|
||||
use directory::{parse_path_or_default, DEFAULT_BEACON_NODE_DIR, DEFAULT_VALIDATOR_DIR};
|
||||
use env_logger::{Builder, Env};
|
||||
use environment::{EnvironmentBuilder, LoggerConfig};
|
||||
@@ -211,6 +211,45 @@ fn main() {
|
||||
)
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("terminal-total-difficulty-override")
|
||||
.long("terminal-total-difficulty-override")
|
||||
.value_name("INTEGER")
|
||||
.help("Used to coordinate manual overrides to the TERMINAL_TOTAL_DIFFICULTY parameter. \
|
||||
Accepts a 256-bit decimal integer (not a hex value). \
|
||||
This flag should only be used if the user has a clear understanding that \
|
||||
the broad Ethereum community has elected to override the terminal difficulty. \
|
||||
Incorrect use of this flag will cause your node to experience a consensus
|
||||
failure. Be extremely careful with this flag.")
|
||||
.takes_value(true)
|
||||
.global(true)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("terminal-block-hash-override")
|
||||
.long("terminal-block-hash-override")
|
||||
.value_name("TERMINAL_BLOCK_HASH")
|
||||
.help("Used to coordinate manual overrides to the TERMINAL_BLOCK_HASH parameter. \
|
||||
This flag should only be used if the user has a clear understanding that \
|
||||
the broad Ethereum community has elected to override the terminal PoW block. \
|
||||
Incorrect use of this flag will cause your node to experience a consensus
|
||||
failure. Be extremely careful with this flag.")
|
||||
.requires("terminal-block-hash-epoch-override")
|
||||
.takes_value(true)
|
||||
.global(true)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("terminal-block-hash-epoch-override")
|
||||
.long("terminal-block-hash-epoch-override")
|
||||
.value_name("EPOCH")
|
||||
.help("Used to coordinate manual overrides to the TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH \
|
||||
parameter. This flag should only be used if the user has a clear understanding \
|
||||
that the broad Ethereum community has elected to override the terminal PoW block. \
|
||||
Incorrect use of this flag will cause your node to experience a consensus
|
||||
failure. Be extremely careful with this flag.")
|
||||
.requires("terminal-block-hash-override")
|
||||
.takes_value(true)
|
||||
.global(true)
|
||||
)
|
||||
.subcommand(beacon_node::cli_app())
|
||||
.subcommand(boot_node::cli_app())
|
||||
.subcommand(validator_client::cli_app())
|
||||
@@ -250,7 +289,13 @@ fn main() {
|
||||
.expect("Debug-level must be present")
|
||||
.into();
|
||||
|
||||
boot_node::run(&matches, bootnode_matches, eth_spec_id, debug_info);
|
||||
boot_node::run(
|
||||
&matches,
|
||||
bootnode_matches,
|
||||
eth_spec_id,
|
||||
ð2_network_config,
|
||||
debug_info,
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
@@ -424,11 +469,7 @@ fn run<E: EthSpec>(
|
||||
let context = environment.core_context();
|
||||
let log = context.log().clone();
|
||||
let executor = context.executor.clone();
|
||||
let config = beacon_node::get_config::<E>(
|
||||
matches,
|
||||
&context.eth2_config().spec,
|
||||
context.log().clone(),
|
||||
)?;
|
||||
let config = beacon_node::get_config::<E>(matches, &context)?;
|
||||
let shutdown_flag = matches.is_present("immediate-shutdown");
|
||||
if let Some(dump_path) = clap_utils::parse_optional::<PathBuf>(matches, "dump-config")?
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
use std::string::ToString;
|
||||
use tempfile::TempDir;
|
||||
use types::{Checkpoint, Epoch, Hash256, Uint256};
|
||||
use types::{Checkpoint, Epoch, Hash256};
|
||||
|
||||
const DEFAULT_ETH1_ENDPOINT: &str = "http://localhost:8545/";
|
||||
|
||||
@@ -817,83 +817,6 @@ pub fn malloc_tuning_flag() {
|
||||
});
|
||||
}
|
||||
#[test]
|
||||
pub fn ttd_override_decimal() {
|
||||
CommandLineTest::new().run().with_config(|config| {
|
||||
assert!(config.terminal_total_difficulty_override.is_none());
|
||||
});
|
||||
|
||||
CommandLineTest::new()
|
||||
.flag("merge", None)
|
||||
.flag(
|
||||
"terminal-total-difficulty-override",
|
||||
Some("31,841,035,257,753,085,493,511"),
|
||||
)
|
||||
.run()
|
||||
.with_config(|config| {
|
||||
assert_eq!(
|
||||
config.terminal_total_difficulty_override.unwrap(),
|
||||
Uint256::from_dec_str(&"31841035257753085493511").unwrap()
|
||||
);
|
||||
});
|
||||
|
||||
CommandLineTest::new()
|
||||
.flag("merge", None)
|
||||
.flag(
|
||||
"terminal-total-difficulty-override",
|
||||
Some("31841035257753085493511"),
|
||||
)
|
||||
.run()
|
||||
.with_config(|config| {
|
||||
assert_eq!(
|
||||
config.terminal_total_difficulty_override.unwrap(),
|
||||
Uint256::from_dec_str(&"31841035257753085493511").unwrap()
|
||||
);
|
||||
});
|
||||
|
||||
CommandLineTest::new()
|
||||
.flag("merge", None)
|
||||
.flag("terminal-total-difficulty-override", Some("1234"))
|
||||
.run()
|
||||
.with_config(|config| {
|
||||
assert_eq!(
|
||||
config.terminal_total_difficulty_override.unwrap(),
|
||||
Uint256::from(1234)
|
||||
);
|
||||
});
|
||||
|
||||
CommandLineTest::new()
|
||||
.flag("merge", None)
|
||||
.flag("terminal-total-difficulty-override", Some("1,234"))
|
||||
.run()
|
||||
.with_config(|config| {
|
||||
assert_eq!(
|
||||
config.terminal_total_difficulty_override.unwrap(),
|
||||
Uint256::from(1234)
|
||||
);
|
||||
});
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
pub fn ttd_override_without_merge() {
|
||||
CommandLineTest::new()
|
||||
.flag("terminal-total-difficulty-override", Some("1234"))
|
||||
.run();
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
pub fn ttd_override_hex() {
|
||||
CommandLineTest::new()
|
||||
.flag("terminal-total-difficulty-override", Some("0xabcd"))
|
||||
.run();
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
pub fn ttd_override_none() {
|
||||
CommandLineTest::new()
|
||||
.flag("terminal-total-difficulty-override", None)
|
||||
.run();
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn ensure_panic_on_failed_launch() {
|
||||
CommandLineTest::new()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use boot_node::config::BootNodeConfigSerialization;
|
||||
|
||||
use crate::exec::{CommandLineTestExec, CompletedTest};
|
||||
use beacon_node::get_eth2_network_config;
|
||||
use clap::ArgMatches;
|
||||
use clap_utils::get_eth2_network_config;
|
||||
use lighthouse_network::discovery::ENR_FILENAME;
|
||||
use lighthouse_network::Enr;
|
||||
use std::fs::File;
|
||||
|
||||
Reference in New Issue
Block a user