mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Enable Compatibility with Windows (#2333)
## Issue Addressed Windows incompatibility. ## Proposed Changes On windows, lighthouse needs to default to STDIN as tty doesn't exist. Also Windows uses ACLs for file permissions. So to mirror chmod 600, we will remove every entry in a file's ACL and add only a single SID that is an alias for the file owner. Beyond that, there were several changes made to different unit tests because windows has slightly different error messages as well as frustrating nuances around killing a process :/ ## Additional Info Tested on my Windows VM and it appears to work, also compiled & tested on Linux with these changes. Permissions look correct on both platforms now. Just waiting for my validator to activate on Prater so I can test running full validator client on windows. Co-authored-by: ethDreamer <37123614+ethDreamer@users.noreply.github.com> Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@ eth2_ssz_derive = { path = "../consensus/ssz_derive" }
|
||||
flate2 = { version = "1.0.14", features = ["zlib"], default-features = false }
|
||||
lazy_static = "1.4.0"
|
||||
lighthouse_metrics = { path = "../common/lighthouse_metrics" }
|
||||
filesystem = { path = "../common/filesystem" }
|
||||
lmdb = "0.8"
|
||||
lmdb-sys = "0.8"
|
||||
parking_lot = "0.11.0"
|
||||
|
||||
@@ -10,6 +10,13 @@ pub const DEFAULT_UPDATE_PERIOD: u64 = 12;
|
||||
pub const DEFAULT_MAX_DB_SIZE: usize = 256 * 1024; // 256 GiB
|
||||
pub const DEFAULT_BROADCAST: bool = false;
|
||||
|
||||
/// Database size to use for tests.
|
||||
///
|
||||
/// Mostly a workaround for Windows due to a bug in LMDB, see:
|
||||
///
|
||||
/// https://github.com/sigp/lighthouse/issues/2342
|
||||
pub const TESTING_MAX_DB_SIZE: usize = 16; // MiB
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub database_path: PathBuf,
|
||||
@@ -38,6 +45,12 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
/// Use a smaller max DB size for testing.
|
||||
pub fn for_testing(mut self) -> Self {
|
||||
self.max_db_size_mbs = TESTING_MAX_DB_SIZE;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn validate(&self) -> Result<(), Error> {
|
||||
if self.chunk_size == 0
|
||||
|| self.validator_chunk_size == 0
|
||||
|
||||
@@ -195,6 +195,15 @@ impl<E: EthSpec> SlasherDB<E> {
|
||||
let proposers_db = env.create_db(Some(PROPOSERS_DB), Self::db_flags())?;
|
||||
let metadata_db = env.create_db(Some(METADATA_DB), Self::db_flags())?;
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use filesystem::restrict_file_permissions;
|
||||
let data = config.database_path.join("data.mdb");
|
||||
let lock = config.database_path.join("lock.mdb");
|
||||
restrict_file_permissions(data).map_err(Error::DatabasePermissionsError)?;
|
||||
restrict_file_permissions(lock).map_err(Error::DatabasePermissionsError)?;
|
||||
}
|
||||
|
||||
let db = Self {
|
||||
env,
|
||||
indexed_attestation_db,
|
||||
|
||||
@@ -6,6 +6,7 @@ use types::{Epoch, Hash256};
|
||||
pub enum Error {
|
||||
DatabaseError(lmdb::Error),
|
||||
DatabaseIOError(io::Error),
|
||||
DatabasePermissionsError(filesystem::Error),
|
||||
SszDecodeError(ssz::DecodeError),
|
||||
BincodeError(bincode::Error),
|
||||
ArithError(safe_arith::ArithError),
|
||||
|
||||
@@ -170,7 +170,7 @@ fn slasher_test(
|
||||
should_process_after: impl Fn(usize) -> bool,
|
||||
) {
|
||||
let tempdir = tempdir().unwrap();
|
||||
let config = Config::new(tempdir.path().into());
|
||||
let config = Config::new(tempdir.path().into()).for_testing();
|
||||
let slasher = Slasher::open(config, logger()).unwrap();
|
||||
let current_epoch = Epoch::new(current_epoch);
|
||||
|
||||
@@ -189,6 +189,8 @@ fn slasher_test(
|
||||
|
||||
// Pruning should not error.
|
||||
slasher.prune_database(current_epoch).unwrap();
|
||||
// windows won't delete the temporary directory if you don't do this..
|
||||
drop(slasher);
|
||||
}
|
||||
|
||||
fn parallel_slasher_test(
|
||||
@@ -197,7 +199,7 @@ fn parallel_slasher_test(
|
||||
current_epoch: u64,
|
||||
) {
|
||||
let tempdir = tempdir().unwrap();
|
||||
let config = Config::new(tempdir.path().into());
|
||||
let config = Config::new(tempdir.path().into()).for_testing();
|
||||
let slasher = Slasher::open(config, logger()).unwrap();
|
||||
let current_epoch = Epoch::new(current_epoch);
|
||||
|
||||
@@ -212,4 +214,6 @@ fn parallel_slasher_test(
|
||||
let slashings = slasher.get_attester_slashings();
|
||||
let slashed_validators = slashed_validators_from_slashings(&slashings);
|
||||
assert_eq!(slashed_validators, expected_slashed_validators);
|
||||
// windows won't delete the temporary directory if you don't do this..
|
||||
drop(slasher);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use types::{Epoch, EthSpec};
|
||||
#[test]
|
||||
fn empty_pruning() {
|
||||
let tempdir = tempdir().unwrap();
|
||||
let config = Config::new(tempdir.path().into());
|
||||
let config = Config::new(tempdir.path().into()).for_testing();
|
||||
let slasher = Slasher::<E>::open(config, logger()).unwrap();
|
||||
slasher.prune_database(Epoch::new(0)).unwrap();
|
||||
}
|
||||
@@ -18,7 +18,7 @@ fn block_pruning() {
|
||||
let slots_per_epoch = E::slots_per_epoch();
|
||||
|
||||
let tempdir = tempdir().unwrap();
|
||||
let mut config = Config::new(tempdir.path().into());
|
||||
let mut config = Config::new(tempdir.path().into()).for_testing();
|
||||
config.chunk_size = 2;
|
||||
config.history_length = 2;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ fn random_test(seed: u64, test_config: TestConfig) {
|
||||
|
||||
let tempdir = tempdir().unwrap();
|
||||
|
||||
let mut config = Config::new(tempdir.path().into());
|
||||
let mut config = Config::new(tempdir.path().into()).for_testing();
|
||||
config.validator_chunk_size = 1 << rng.gen_range(1, 4);
|
||||
|
||||
let chunk_size_exponent = rng.gen_range(1, 4);
|
||||
|
||||
@@ -8,7 +8,7 @@ use types::Epoch;
|
||||
#[test]
|
||||
fn attestation_pruning_empty_wrap_around() {
|
||||
let tempdir = tempdir().unwrap();
|
||||
let mut config = Config::new(tempdir.path().into());
|
||||
let mut config = Config::new(tempdir.path().into()).for_testing();
|
||||
config.validator_chunk_size = 1;
|
||||
config.chunk_size = 16;
|
||||
config.history_length = 16;
|
||||
@@ -42,7 +42,7 @@ fn attestation_pruning_empty_wrap_around() {
|
||||
#[test]
|
||||
fn pruning_with_map_full() {
|
||||
let tempdir = tempdir().unwrap();
|
||||
let mut config = Config::new(tempdir.path().into());
|
||||
let mut config = Config::new(tempdir.path().into()).for_testing();
|
||||
config.validator_chunk_size = 1;
|
||||
config.chunk_size = 16;
|
||||
config.history_length = 1024;
|
||||
|
||||
Reference in New Issue
Block a user