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

This commit is contained in:
Michael Sproul
2022-11-30 14:14:17 +11:00
173 changed files with 6359 additions and 1655 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "lighthouse"
version = "3.1.2"
version = "3.3.0"
authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = "2021"
autotests = false

View File

@@ -55,6 +55,7 @@ pub struct LoggerConfig {
pub max_log_size: u64,
pub max_log_number: usize,
pub compression: bool,
pub is_restricted: bool,
}
impl Default for LoggerConfig {
fn default() -> Self {
@@ -68,6 +69,7 @@ impl Default for LoggerConfig {
max_log_size: 200,
max_log_number: 5,
compression: false,
is_restricted: true,
}
}
}
@@ -257,7 +259,7 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
.rotate_size(config.max_log_size)
.rotate_keep(config.max_log_number)
.rotate_compress(config.compression)
.restrict_permissions(true)
.restrict_permissions(config.is_restricted)
.build()
.map_err(|e| format!("Unable to build file logger: {}", e))?;
@@ -380,7 +382,7 @@ impl<E: EthSpec> Environment<E> {
}
/// Returns a `Context` where no "service" has been added to the logger output.
pub fn core_context(&mut self) -> RuntimeContext<E> {
pub fn core_context(&self) -> RuntimeContext<E> {
RuntimeContext {
executor: TaskExecutor::new(
Arc::downgrade(self.runtime()),
@@ -395,7 +397,7 @@ impl<E: EthSpec> Environment<E> {
}
/// Returns a `Context` where the `service_name` is added to the logger output.
pub fn service_context(&mut self, service_name: String) -> RuntimeContext<E> {
pub fn service_context(&self, service_name: String) -> RuntimeContext<E> {
RuntimeContext {
executor: TaskExecutor::new(
Arc::downgrade(self.runtime()),

View File

@@ -129,6 +129,15 @@ fn main() {
to store old logs.")
.global(true),
)
.arg(
Arg::with_name("logfile-no-restricted-perms")
.long("logfile-no-restricted-perms")
.help(
"If present, log files will be generated as world-readable meaning they can be read by \
any user on the machine. Note that logs can often contain sensitive information \
about your validator and so this flag should be used with caution.")
.global(true),
)
.arg(
Arg::with_name("log-format")
.long("log-format")
@@ -407,6 +416,8 @@ fn run<E: EthSpec>(
let logfile_compress = matches.is_present("logfile-compress");
let logfile_restricted = !matches.is_present("logfile-no-restricted-perms");
// Construct the path to the log file.
let mut log_path: Option<PathBuf> = clap_utils::parse_optional(matches, "logfile")?;
if log_path.is_none() {
@@ -446,6 +457,7 @@ fn run<E: EthSpec>(
max_log_size: logfile_max_size * 1_024 * 1_024,
max_log_number: logfile_max_number,
compression: logfile_compress,
is_restricted: logfile_restricted,
};
let builder = environment_builder.initialize_logger(logger_config.clone())?;

View File

@@ -56,7 +56,9 @@ impl CommandLineTestExec for CommandLineTest {
fn datadir_flag() {
CommandLineTest::new()
.run_with_zero_port()
.with_config_and_dir(|config, dir| assert_eq!(config.data_dir, dir.path().join("beacon")));
.with_config_and_dir(|config, dir| {
assert_eq!(*config.data_dir(), dir.path().join("beacon"))
});
}
#[test]
@@ -132,6 +134,25 @@ fn fork_choice_before_proposal_timeout_zero() {
.with_config(|config| assert_eq!(config.chain.fork_choice_before_proposal_timeout_ms, 0));
}
#[test]
fn checkpoint_sync_url_timeout_flag() {
CommandLineTest::new()
.flag("checkpoint-sync-url-timeout", Some("300"))
.run_with_zero_port()
.with_config(|config| {
assert_eq!(config.chain.checkpoint_sync_url_timeout, 300);
});
}
#[test]
fn checkpoint_sync_url_timeout_default() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| {
assert_eq!(config.chain.checkpoint_sync_url_timeout, 60);
});
}
#[test]
fn paranoid_block_proposal_default() {
CommandLineTest::new()
@@ -1545,3 +1566,80 @@ fn enabled_disable_log_timestamp_flag() {
assert!(config.logger_config.disable_log_timestamp);
});
}
#[test]
fn logfile_restricted_perms_default() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| {
assert!(config.logger_config.is_restricted);
});
}
#[test]
fn logfile_no_restricted_perms_flag() {
CommandLineTest::new()
.flag("logfile-no-restricted-perms", None)
.run_with_zero_port()
.with_config(|config| {
assert!(config.logger_config.is_restricted == false);
});
}
#[test]
fn sync_eth1_chain_default() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| assert_eq!(config.sync_eth1_chain, false));
}
#[test]
fn sync_eth1_chain_execution_endpoints_flag() {
let dir = TempDir::new().expect("Unable to create temporary directory");
CommandLineTest::new()
.flag("execution-endpoints", Some("http://localhost:8551/"))
.flag(
"execution-jwt",
dir.path().join("jwt-file").as_os_str().to_str(),
)
.run_with_zero_port()
.with_config(|config| assert_eq!(config.sync_eth1_chain, true));
}
#[test]
fn sync_eth1_chain_disable_deposit_contract_sync_flag() {
let dir = TempDir::new().expect("Unable to create temporary directory");
CommandLineTest::new()
.flag("disable-deposit-contract-sync", None)
.flag("execution-endpoints", Some("http://localhost:8551/"))
.flag(
"execution-jwt",
dir.path().join("jwt-file").as_os_str().to_str(),
)
.run_with_zero_port()
.with_config(|config| assert_eq!(config.sync_eth1_chain, false));
}
#[test]
fn light_client_server_default() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| assert_eq!(config.network.enable_light_client_server, false));
}
#[test]
fn light_client_server_enabled() {
CommandLineTest::new()
.flag("light-client-server", None)
.run_with_zero_port()
.with_config(|config| assert_eq!(config.network.enable_light_client_server, true));
}
#[test]
fn gui_flag() {
CommandLineTest::new()
.flag("gui", None)
.run_with_zero_port()
.with_config(|config| {
assert!(config.http_api.enabled);
assert!(config.validator_monitor_auto);
});
}

View File

@@ -56,7 +56,7 @@ impl CommandLineTestExec for CommandLineTest {
fn enr_address_arg() {
let mut test = CommandLineTest::new();
test.run_with_ip().with_config(|config| {
assert_eq!(config.local_enr.ip(), Some(IP_ADDRESS.parse().unwrap()));
assert_eq!(config.local_enr.ip4(), Some(IP_ADDRESS.parse().unwrap()));
});
}
@@ -127,7 +127,7 @@ fn enr_port_flag() {
.flag("enr-port", Some(port.to_string().as_str()))
.run_with_ip()
.with_config(|config| {
assert_eq!(config.local_enr.udp(), Some(port));
assert_eq!(config.local_enr.udp4(), Some(port));
})
}