mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +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:
@@ -74,8 +74,11 @@ impl GanacheInstance {
|
||||
/// RPC connections.
|
||||
pub fn new(network_id: u64, chain_id: u64) -> Result<Self, String> {
|
||||
let port = unused_port()?;
|
||||
|
||||
let child = Command::new("ganache-cli")
|
||||
let binary = match cfg!(windows) {
|
||||
true => "ganache-cli.cmd",
|
||||
false => "ganache-cli",
|
||||
};
|
||||
let child = Command::new(binary)
|
||||
.stdout(Stdio::piped())
|
||||
.arg("--defaultBalanceEther")
|
||||
.arg("1000000000")
|
||||
@@ -83,6 +86,8 @@ impl GanacheInstance {
|
||||
.arg("1000000000")
|
||||
.arg("--accounts")
|
||||
.arg("10")
|
||||
.arg("--keepAliveTimeout")
|
||||
.arg("0")
|
||||
.arg("--port")
|
||||
.arg(format!("{}", port))
|
||||
.arg("--mnemonic")
|
||||
@@ -94,9 +99,9 @@ impl GanacheInstance {
|
||||
.spawn()
|
||||
.map_err(|e| {
|
||||
format!(
|
||||
"Failed to start ganache-cli. \
|
||||
Is it ganache-cli installed and available on $PATH? Error: {:?}",
|
||||
e
|
||||
"Failed to start {}. \
|
||||
Is it installed and available on $PATH? Error: {:?}",
|
||||
binary, e
|
||||
)
|
||||
})?;
|
||||
|
||||
@@ -105,21 +110,26 @@ impl GanacheInstance {
|
||||
|
||||
pub fn fork(&self) -> Result<Self, String> {
|
||||
let port = unused_port()?;
|
||||
|
||||
let child = Command::new("ganache-cli")
|
||||
let binary = match cfg!(windows) {
|
||||
true => "ganache-cli.cmd",
|
||||
false => "ganache-cli",
|
||||
};
|
||||
let child = Command::new(binary)
|
||||
.stdout(Stdio::piped())
|
||||
.arg("--fork")
|
||||
.arg(self.endpoint())
|
||||
.arg("--port")
|
||||
.arg(format!("{}", port))
|
||||
.arg("--keepAliveTimeout")
|
||||
.arg("0")
|
||||
.arg("--chainId")
|
||||
.arg(format!("{}", self.chain_id))
|
||||
.spawn()
|
||||
.map_err(|e| {
|
||||
format!(
|
||||
"Failed to start ganache-cli. \
|
||||
Is it ganache-cli installed and available on $PATH? Error: {:?}",
|
||||
e
|
||||
"Failed to start {}. \
|
||||
Is it installed and available on $PATH? Error: {:?}",
|
||||
binary, e
|
||||
)
|
||||
})?;
|
||||
|
||||
@@ -202,6 +212,23 @@ pub fn unused_port() -> Result<u16, String> {
|
||||
|
||||
impl Drop for GanacheInstance {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.child.kill();
|
||||
if cfg!(windows) {
|
||||
// Calling child.kill() in Windows will only kill the process
|
||||
// that spawned ganache, leaving the actual ganache process
|
||||
// intact. You have to kill the whole process tree. What's more,
|
||||
// if you don't spawn ganache with --keepAliveTimeout=0, Windows
|
||||
// will STILL keep the server running even after you've ended
|
||||
// the process tree and it's disappeared from the task manager.
|
||||
// Unbelievable...
|
||||
Command::new("taskkill")
|
||||
.arg("/pid")
|
||||
.arg(self.child.id().to_string())
|
||||
.arg("/T")
|
||||
.arg("/F")
|
||||
.output()
|
||||
.expect("failed to execute taskkill");
|
||||
} else {
|
||||
let _ = self.child.kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user