Merge remote-tracking branch 'origin/unstable' into tree-states

This commit is contained in:
Michael Sproul
2022-09-14 13:51:23 +10:00
404 changed files with 28947 additions and 12000 deletions

View File

@@ -1,4 +1,5 @@
use clap::{App, Arg};
use strum::VariantNames;
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new("beacon_node")
@@ -148,7 +149,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
If a DNS address is provided, the enr-address is set to the IP address it resolves to and \
does not auto-update based on PONG responses in discovery. \
Set this only if you are sure other nodes can connect to your local node on this address. \
Discovery will automatically find your external address,if possible.")
Discovery will automatically find your external address, if possible.")
.requires("enr-udp-port")
.takes_value(true),
)
@@ -229,8 +230,15 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.arg(
Arg::with_name("http-disable-legacy-spec")
.long("http-disable-legacy-spec")
.help("Disable serving of legacy data on the /config/spec endpoint. May be \
disabled by default in a future release.")
.hidden(true)
)
.arg(
Arg::with_name("http-spec-fork")
.long("http-spec-fork")
.value_name("FORK")
.help("Serve the spec for a specific hard fork on /eth/v1/config/spec. It should \
not be necessary to set this flag.")
.takes_value(true)
)
.arg(
Arg::with_name("http-enable-tls")
@@ -312,6 +320,15 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
and never provide an untrusted URL.")
.takes_value(true),
)
.arg(
Arg::with_name("monitoring-endpoint-period")
.long("monitoring-endpoint-period")
.value_name("SECONDS")
.help("Defines how many seconds to wait between each message sent to \
the monitoring-endpoint. Default: 60s")
.requires("monitoring-endpoint")
.takes_value(true),
)
/*
* Standard staking flags
@@ -320,9 +337,9 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.arg(
Arg::with_name("staking")
.long("staking")
.help("Standard option for a staking beacon node. Equivalent to \
`lighthouse bn --http --eth1 `. This will enable the http server on localhost:5052 \
and try connecting to an eth1 node on localhost:8545")
.help("Standard option for a staking beacon node. This will enable the HTTP server \
on localhost:5052 and import deposit logs from the execution node. This is \
equivalent to `--http` on merge-ready networks, or `--http --eth1` pre-merge")
.takes_value(false)
)
@@ -377,72 +394,87 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.default_value("1000")
.takes_value(true)
)
.arg(
Arg::with_name("eth1-cache-follow-distance")
.long("eth1-cache-follow-distance")
.value_name("BLOCKS")
.help("Specifies the distance between the Eth1 chain head and the last block which \
should be imported into the cache. Setting this value lower can help \
compensate for irregular Proof-of-Work block times, but setting it too low \
can make the node vulnerable to re-orgs.")
.takes_value(true)
)
/*
* Execution Layer Integration
*/
.arg(
Arg::with_name("merge")
.long("merge")
.help("Enable the features necessary to run merge testnets. This feature \
is unstable and is for developers only.")
.takes_value(false),
.help("Deprecated. The feature activates automatically when --execution-endpoint \
is supplied.")
.takes_value(false)
.hidden(true)
)
.arg(
Arg::with_name("execution-endpoints")
.long("execution-endpoints")
.value_name("EXECUTION-ENDPOINTS")
.help("One or more comma-delimited server endpoints for HTTP JSON-RPC connection. \
If multiple endpoints are given the endpoints are used as fallback in the \
given order. Also enables the --merge flag. \
If this flag is omitted and the --eth1-endpoints is supplied, those values \
will be used. Defaults to http://127.0.0.1:8545.")
Arg::with_name("execution-endpoint")
.long("execution-endpoint")
.value_name("EXECUTION-ENDPOINT")
.alias("execution-endpoints")
.help("Server endpoint for an execution layer JWT-authenticated HTTP \
JSON-RPC connection. Uses the same endpoint to populate the \
deposit cache.")
.takes_value(true)
.requires("execution-jwt")
)
.arg(
Arg::with_name("execution-jwt")
.long("execution-jwt")
.value_name("EXECUTION-JWT")
.alias("jwt-secrets")
.help("File path which contains the hex-encoded JWT secret for the \
execution endpoint provided in the --execution-endpoint flag.")
.requires("execution-endpoint")
.takes_value(true)
)
.arg(
Arg::with_name("jwt-secrets")
.long("jwt-secrets")
.value_name("JWT-SECRETS")
.help("One or more comma-delimited file paths which contain the corresponding hex-encoded \
JWT secrets for each execution endpoint provided in the --execution-endpoints flag. \
The number of paths should be in the same order and strictly equal to the number \
of execution endpoints provided.")
.takes_value(true)
.requires("execution-endpoints")
)
.arg(
Arg::with_name("jwt-id")
.long("jwt-id")
.value_name("JWT-ID")
Arg::with_name("execution-jwt-id")
.long("execution-jwt-id")
.value_name("EXECUTION-JWT-ID")
.alias("jwt-id")
.help("Used by the beacon node to communicate a unique identifier to execution nodes \
during JWT authentication. It corresponds to the 'id' field in the JWT claims object.\
Set to empty by deafult")
Set to empty by default")
.requires("execution-jwt")
.takes_value(true)
)
.arg(
Arg::with_name("jwt-version")
.long("jwt-version")
.value_name("JWT-VERSION")
Arg::with_name("execution-jwt-version")
.long("execution-jwt-version")
.value_name("EXECUTION-JWT-VERSION")
.alias("jwt-version")
.help("Used by the beacon node to communicate a client version to execution nodes \
during JWT authentication. It corresponds to the 'clv' field in the JWT claims object.\
Set to empty by deafult")
Set to empty by default")
.requires("execution-jwt")
.takes_value(true)
)
.arg(
Arg::with_name("suggested-fee-recipient")
.long("suggested-fee-recipient")
.value_name("SUGGESTED-FEE-RECIPIENT")
.help("Once the merge has happened, this address will receive transaction fees \
collected from any blocks produced by this node. Defaults to a junk \
address whilst the merge is in development stages. THE DEFAULT VALUE \
WILL BE REMOVED BEFORE THE MERGE ENTERS PRODUCTION")
.requires("merge")
.help("Emergency fallback fee recipient for use in case the validator client does \
not have one configured. You should set this flag on the validator \
client instead of (or in addition to) setting it here.")
.requires("execution-endpoint")
.takes_value(true)
)
.arg(
Arg::with_name("payload-builders")
.long("payload-builders")
Arg::with_name("builder")
.long("builder")
.alias("payload-builder")
.alias("payload-builders")
.help("The URL of a service compatible with the MEV-boost API.")
.requires("merge")
.requires("execution-endpoint")
.takes_value(true)
)
@@ -623,6 +655,15 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
[disabled by default].")
.requires("slasher")
)
.arg(
Arg::with_name("slasher-backend")
.long("slasher-backend")
.value_name("DATABASE")
.help("Set the database backend to be used by the slasher.")
.takes_value(true)
.possible_values(slasher::DatabaseBackend::VARIANTS)
.requires("slasher")
)
.arg(
Arg::with_name("wss-checkpoint")
.long("wss-checkpoint")
@@ -709,4 +750,94 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.default_value("250")
.takes_value(true)
)
.arg(
Arg::with_name("paranoid-block-proposal")
.long("paranoid-block-proposal")
.help("Paranoid enough to be reading the source? Nice. This flag reverts some \
block proposal optimisations and forces the node to check every attestation \
it includes super thoroughly. This may be useful in an emergency, but not \
otherwise.")
.hidden(true)
.takes_value(false)
)
.arg(
Arg::with_name("builder-fallback-skips")
.long("builder-fallback-skips")
.help("If this node is proposing a block and has seen this number of skip slots \
on the canonical chain in a row, it will NOT query any connected builders, \
and will use the local execution engine for payload construction.")
.default_value("3")
.takes_value(true)
)
.arg(
Arg::with_name("builder-fallback-skips-per-epoch")
.long("builder-fallback-skips-per-epoch")
.help("If this node is proposing a block and has seen this number of skip slots \
on the canonical chain in the past `SLOTS_PER_EPOCH`, it will NOT query \
any connected builders, and will use the local execution engine for \
payload construction.")
.default_value("8")
.takes_value(true)
)
.arg(
Arg::with_name("builder-fallback-epochs-since-finalization")
.long("builder-fallback-epochs-since-finalization")
.help("If this node is proposing a block and the chain has not finalized within \
this number of epochs, it will NOT query any connected builders, \
and will use the local execution engine for payload construction. Setting \
this value to anything less than 2 will cause the node to NEVER query \
connected builders. Setting it to 2 will cause this condition to be hit \
if there are skips slots at the start of an epoch, right before this node \
is set to propose.")
.default_value("3")
.takes_value(true)
)
.arg(
Arg::with_name("builder-fallback-disable-checks")
.long("builder-fallback-disable-checks")
.help("This flag disables all checks related to chain health. This means the builder \
API will always be used for payload construction, regardless of recent chain \
conditions.")
.takes_value(false)
)
.arg(
Arg::with_name("builder-profit-threshold")
.long("builder-profit-threshold")
.value_name("WEI_VALUE")
.help("The minimum reward in wei provided to the proposer by a block builder for \
an external payload to be considered for inclusion in a proposal. If this \
threshold is not met, the local EE's payload will be used. This is currently \
*NOT* in comparison to the value of the local EE's payload. It simply checks \
whether the total proposer reward from an external payload is equal to or \
greater than this value. In the future, a comparison to a local payload is \
likely to be added. Example: Use 250000000000000000 to set the threshold to \
0.25 ETH.")
.default_value("0")
.takes_value(true)
)
.arg(
Arg::with_name("count-unrealized")
.long("count-unrealized")
.hidden(true)
.help("Enables an alternative, potentially more performant FFG \
vote tracking method.")
.takes_value(true)
.default_value("true")
)
.arg(
Arg::with_name("count-unrealized-full")
.long("count-unrealized-full")
.hidden(true)
.help("Stricter version of `count-unrealized`.")
.takes_value(true)
.default_value("false")
)
.arg(
Arg::with_name("reset-payload-statuses")
.long("reset-payload-statuses")
.help("When present, Lighthouse will forget the payload statuses of any \
already-imported blocks. This can assist in the recovery from a consensus \
failure caused by the execution layer.")
.takes_value(false)
)
}

View File

@@ -3,12 +3,15 @@ use clap_utils::flags::DISABLE_MALLOC_TUNING_FLAG;
use client::{ClientConfig, ClientGenesis};
use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR};
use environment::RuntimeContext;
use genesis::Eth1Endpoint;
use http_api::TlsConfig;
use lighthouse_network::{multiaddr::Protocol, Enr, Multiaddr, NetworkConfig, PeerIdSerialized};
use sensitive_url::SensitiveUrl;
use slog::{info, warn, Logger};
use std::cmp;
use std::cmp::max;
use std::fmt::Debug;
use std::fmt::Write;
use std::fs;
use std::net::{IpAddr, Ipv4Addr, ToSocketAddrs};
use std::path::{Path, PathBuf};
@@ -113,7 +116,14 @@ pub fn get_config<E: EthSpec>(
}
if cli_args.is_present("http-disable-legacy-spec") {
client_config.http_api.serve_legacy_spec = false;
warn!(
log,
"The flag --http-disable-legacy-spec is deprecated and will be removed"
);
}
if let Some(fork_name) = clap_utils::parse_optional(cli_args, "http-spec-fork")? {
client_config.http_api.spec_fork_name = Some(fork_name);
}
if cli_args.is_present("http-enable-tls") {
@@ -168,9 +178,13 @@ pub fn get_config<E: EthSpec>(
* Explorer metrics
*/
if let Some(monitoring_endpoint) = cli_args.value_of("monitoring-endpoint") {
let update_period_secs =
clap_utils::parse_optional(cli_args, "monitoring-endpoint-period")?;
client_config.monitoring_api = Some(monitoring_api::Config {
db_path: None,
freezer_db_path: None,
update_period_secs,
monitoring_endpoint: monitoring_endpoint.to_string(),
});
}
@@ -215,15 +229,18 @@ pub fn get_config<E: EthSpec>(
"msg" => "please use --eth1-endpoints instead"
);
client_config.sync_eth1_chain = true;
client_config.eth1.endpoints = vec![SensitiveUrl::parse(endpoint)
let endpoints = vec![SensitiveUrl::parse(endpoint)
.map_err(|e| format!("eth1-endpoint was an invalid URL: {:?}", e))?];
client_config.eth1.endpoints = Eth1Endpoint::NoAuth(endpoints);
} else if let Some(endpoints) = cli_args.value_of("eth1-endpoints") {
client_config.sync_eth1_chain = true;
client_config.eth1.endpoints = endpoints
let endpoints = endpoints
.split(',')
.map(SensitiveUrl::parse)
.collect::<Result<_, _>>()
.map_err(|e| format!("eth1-endpoints contains an invalid URL {:?}", e))?;
client_config.eth1.endpoints = Eth1Endpoint::NoAuth(endpoints);
}
if let Some(val) = cli_args.value_of("eth1-blocks-per-log-query") {
@@ -236,47 +253,87 @@ pub fn get_config<E: EthSpec>(
client_config.eth1.purge_cache = true;
}
if cli_args.is_present("merge") || cli_args.is_present("execution-endpoints") {
if let Some(follow_distance) =
clap_utils::parse_optional(cli_args, "eth1-cache-follow-distance")?
{
client_config.eth1.cache_follow_distance = Some(follow_distance);
}
if cli_args.is_present("merge") {
if cli_args.is_present("execution-endpoint") {
warn!(
log,
"The --merge flag is deprecated";
"info" => "the --execution-endpoint flag automatically enables this feature"
)
} else {
return Err("The --merge flag is deprecated. \
Supply a value to --execution-endpoint instead."
.into());
}
}
if let Some(endpoints) = cli_args.value_of("execution-endpoint") {
let mut el_config = execution_layer::Config::default();
if let Some(endpoints) = cli_args.value_of("execution-endpoints") {
client_config.sync_eth1_chain = true;
el_config.execution_endpoints = endpoints
.split(',')
.map(SensitiveUrl::parse)
.collect::<Result<_, _>>()
.map_err(|e| format!("execution-endpoints contains an invalid URL {:?}", e))?;
} else if cli_args.is_present("merge") {
el_config.execution_endpoints = client_config.eth1.endpoints.clone();
}
if let Some(endpoints) = cli_args.value_of("payload-builders") {
el_config.builder_endpoints = endpoints
.split(',')
.map(SensitiveUrl::parse)
.collect::<Result<_, _>>()
.map_err(|e| format!("payload-builders contains an invalid URL {:?}", e))?;
}
if let Some(secrets) = cli_args.value_of("jwt-secrets") {
let secret_files: Vec<_> = secrets.split(',').map(PathBuf::from).collect();
if !secret_files.is_empty() && secret_files.len() != el_config.execution_endpoints.len()
{
return Err(format!(
"{} execution-endpoints supplied with {} jwt-secrets. Lengths \
must match or jwt-secrets must be empty.",
el_config.execution_endpoints.len(),
secret_files.len(),
));
}
el_config.secret_files = secret_files;
// Always follow the deposit contract when there is an execution endpoint.
//
// This is wasteful for non-staking nodes as they have no need to process deposit contract
// logs and build an "eth1" cache. The alternative is to explicitly require the `--eth1` or
// `--staking` flags, however that poses a risk to stakers since they cannot produce blocks
// without "eth1".
//
// The waste for non-staking nodes is relatively small so we err on the side of safety for
// stakers. The merge is already complicated enough.
client_config.sync_eth1_chain = true;
// Parse a single execution endpoint, logging warnings if multiple endpoints are supplied.
let execution_endpoint =
parse_only_one_value(endpoints, SensitiveUrl::parse, "--execution-endpoint", log)?;
// Parse a single JWT secret, logging warnings if multiple are supplied.
//
// JWTs are required if `--execution-endpoint` is supplied.
let secret_files: String = clap_utils::parse_required(cli_args, "execution-jwt")?;
let secret_file =
parse_only_one_value(&secret_files, PathBuf::from_str, "--execution-jwt", log)?;
// Parse and set the payload builder, if any.
if let Some(endpoint) = cli_args.value_of("builder") {
let payload_builder =
parse_only_one_value(endpoint, SensitiveUrl::parse, "--builder", log)?;
el_config.builder_url = Some(payload_builder);
}
// Set config values from parse values.
el_config.secret_files = vec![secret_file.clone()];
el_config.execution_endpoints = vec![execution_endpoint.clone()];
el_config.suggested_fee_recipient =
clap_utils::parse_optional(cli_args, "suggested-fee-recipient")?;
el_config.jwt_id = clap_utils::parse_optional(cli_args, "jwt-id")?;
el_config.jwt_version = clap_utils::parse_optional(cli_args, "jwt-version")?;
el_config.jwt_id = clap_utils::parse_optional(cli_args, "execution-jwt-id")?;
el_config.jwt_version = clap_utils::parse_optional(cli_args, "execution-jwt-version")?;
el_config.default_datadir = client_config.data_dir.clone();
el_config.builder_profit_threshold =
clap_utils::parse_required(cli_args, "builder-profit-threshold")?;
// If `--execution-endpoint` is provided, we should ignore any `--eth1-endpoints` values and
// use `--execution-endpoint` instead. Also, log a deprecation warning.
if cli_args.is_present("eth1-endpoints") || cli_args.is_present("eth1-endpoint") {
warn!(
log,
"Ignoring --eth1-endpoints flag";
"info" => "the value for --execution-endpoint will be used instead. \
--eth1-endpoints has been deprecated for post-merge configurations"
);
}
client_config.eth1.endpoints = Eth1Endpoint::Auth {
endpoint: execution_endpoint,
jwt_path: secret_file,
jwt_id: el_config.jwt_id.clone(),
jwt_version: el_config.jwt_version.clone(),
};
// Store the EL config in the client config.
client_config.execution_layer = Some(el_config);
}
@@ -342,7 +399,6 @@ pub fn get_config<E: EthSpec>(
client_config.eth1.follow_distance = spec.eth1_follow_distance;
client_config.eth1.node_far_behind_seconds =
max(5, spec.eth1_follow_distance / 2) * spec.seconds_per_eth1_block;
client_config.eth1.network_id = spec.deposit_network_id.into();
client_config.eth1.chain_id = spec.deposit_chain_id.into();
client_config.eth1.set_block_cache_truncation::<E>(spec);
@@ -545,6 +601,10 @@ pub fn get_config<E: EthSpec>(
slasher_config.broadcast = cli_args.is_present("slasher-broadcast");
if let Some(backend) = clap_utils::parse_optional(cli_args, "slasher-backend")? {
slasher_config.backend = backend;
}
client_config.slasher = Some(slasher_config);
}
@@ -591,6 +651,30 @@ pub fn get_config<E: EthSpec>(
client_config.chain.fork_choice_before_proposal_timeout_ms = timeout;
}
client_config.chain.count_unrealized =
clap_utils::parse_required(cli_args, "count-unrealized")?;
client_config.chain.count_unrealized_full =
clap_utils::parse_required::<bool>(cli_args, "count-unrealized-full")?.into();
client_config.chain.always_reset_payload_statuses =
cli_args.is_present("reset-payload-statuses");
client_config.chain.paranoid_block_proposal = cli_args.is_present("paranoid-block-proposal");
/*
* Builder fallback configs.
*/
client_config.chain.builder_fallback_skips =
clap_utils::parse_required(cli_args, "builder-fallback-skips")?;
client_config.chain.builder_fallback_skips_per_epoch =
clap_utils::parse_required(cli_args, "builder-fallback-skips-per-epoch")?;
client_config
.chain
.builder_fallback_epochs_since_finalization =
clap_utils::parse_required(cli_args, "builder-fallback-epochs-since-finalization")?;
client_config.chain.builder_fallback_disable_checks =
cli_args.is_present("builder-fallback-disable-checks");
Ok(client_config)
}
@@ -746,7 +830,8 @@ pub fn set_network_config(
None
})
{
addr.push_str(&format!(":{}", enr_udp_port));
write!(addr, ":{}", enr_udp_port)
.map_err(|e| format!("Failed to write enr address {}", e))?;
} else {
return Err(
"enr-udp-port must be set for node to be discoverable with dns address"
@@ -842,3 +927,38 @@ pub fn get_slots_per_restore_point<E: EthSpec>(
Ok((default, false))
}
}
/// Parses the `cli_value` as a comma-separated string of values to be parsed with `parser`.
///
/// If there is more than one value, log a warning. If there are no values, return an error.
pub fn parse_only_one_value<F, T, E>(
cli_value: &str,
parser: F,
flag_name: &str,
log: &Logger,
) -> Result<T, String>
where
F: Fn(&str) -> Result<T, E>,
E: Debug,
{
let values = cli_value
.split(',')
.map(parser)
.collect::<Result<Vec<_>, _>>()
.map_err(|e| format!("{} contains an invalid value {:?}", flag_name, e))?;
if values.len() > 1 {
warn!(
log,
"Multiple values provided";
"info" => "multiple values are deprecated, only the first value will be used",
"count" => values.len(),
"flag" => flag_name
);
}
values
.into_iter()
.next()
.ok_or(format!("Must provide at least one value to {}", flag_name))
}