windows: Make solana-test-validator work (#20099)
* windows: Make solana-test-validator work The important changes to get this going on Windows: * ledger lock needs to be done on a file instead of the directory * IPC service needs to use the Windows pipe naming scheme * always disable the JIT * file logging not possible yet because we can't redirect stderr, but this will change once env_logger fixes the pipe output target! * Integrate review feedback
This commit is contained in:
@ -113,7 +113,7 @@ fn make_accounts_txs(txes: usize, mint_keypair: &Keypair, hash: Hash) -> Vec<Tra
|
||||
.into_par_iter()
|
||||
.map(|_| {
|
||||
let mut new = dummy.clone();
|
||||
let sig: Vec<u8> = (0..64).map(|_| thread_rng().gen()).collect();
|
||||
let sig: Vec<_> = (0..64).map(|_| thread_rng().gen::<u8>()).collect();
|
||||
new.message.account_keys[0] = pubkey::new_rand();
|
||||
new.message.account_keys[1] = pubkey::new_rand();
|
||||
new.signatures = vec![Signature::new(&sig[0..64])];
|
||||
|
@ -362,7 +362,7 @@ fn get_windows_path_var() -> Result<Option<String>, String> {
|
||||
Ok(Some(s))
|
||||
} else {
|
||||
println!("the registry key HKEY_CURRENT_USER\\Environment\\PATH does not contain valid Unicode. Not modifying the PATH variable");
|
||||
return Ok(None);
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
Err(ref e) if e.kind() == io::ErrorKind::NotFound => Ok(Some(String::new())),
|
||||
@ -391,7 +391,7 @@ fn add_to_path(new_path: &str) -> bool {
|
||||
if !old_path.contains(&new_path) {
|
||||
let mut new_path = new_path.to_string();
|
||||
if !old_path.is_empty() {
|
||||
new_path.push_str(";");
|
||||
new_path.push(';');
|
||||
new_path.push_str(&old_path);
|
||||
}
|
||||
|
||||
@ -416,7 +416,7 @@ fn add_to_path(new_path: &str) -> bool {
|
||||
SendMessageTimeoutA(
|
||||
HWND_BROADCAST,
|
||||
WM_SETTINGCHANGE,
|
||||
0 as WPARAM,
|
||||
0_usize,
|
||||
"Environment\0".as_ptr() as LPARAM,
|
||||
SMTO_ABORTIFHUNG,
|
||||
5000,
|
||||
|
@ -51,3 +51,21 @@ pub fn setup_with_default(filter: &str) {
|
||||
pub fn setup() {
|
||||
setup_with_default("error");
|
||||
}
|
||||
|
||||
// Configures file logging with a default filter if RUST_LOG is not set
|
||||
//
|
||||
// NOTE: This does not work at the moment, pending the resolution of https://github.com/env-logger-rs/env_logger/issues/208
|
||||
pub fn setup_file_with_default(logfile: &str, filter: &str) {
|
||||
use std::fs::OpenOptions;
|
||||
let file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(logfile)
|
||||
.unwrap();
|
||||
let logger = env_logger::Builder::from_env(env_logger::Env::new().default_filter_or(filter))
|
||||
.format_timestamp_nanos()
|
||||
.target(env_logger::Target::Pipe(Box::new(file)))
|
||||
.build();
|
||||
replace_logger(logger);
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ pub fn is_host_port(string: String) -> Result<(), String> {
|
||||
|
||||
#[cfg(windows)]
|
||||
fn udp_socket(_reuseaddr: bool) -> io::Result<Socket> {
|
||||
let sock = Socket::new(Domain::ipv4(), Type::dgram(), None)?;
|
||||
let sock = Socket::new(Domain::IPV4, Type::DGRAM, None)?;
|
||||
Ok(sock)
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,7 @@ if [[ $CI_OS_NAME = windows ]]; then
|
||||
solana-install-init
|
||||
solana-keygen
|
||||
solana-stake-accounts
|
||||
solana-test-validator
|
||||
solana-tokens
|
||||
)
|
||||
else
|
||||
|
@ -1,3 +1,4 @@
|
||||
#[cfg(target_os = "linux")]
|
||||
use clap::{crate_description, crate_name, value_t_or_exit, App, Arg};
|
||||
use log::*;
|
||||
|
||||
|
@ -15,7 +15,7 @@ use {
|
||||
},
|
||||
std::{
|
||||
net::SocketAddr,
|
||||
path::Path,
|
||||
path::{Path, PathBuf},
|
||||
sync::{Arc, RwLock},
|
||||
thread::{self, Builder},
|
||||
time::{Duration, SystemTime},
|
||||
@ -171,7 +171,7 @@ impl AdminRpc for AdminRpcImpl {
|
||||
|
||||
// Start the Admin RPC interface
|
||||
pub fn run(ledger_path: &Path, metadata: AdminRpcRequestMetadata) {
|
||||
let admin_rpc_path = ledger_path.join("admin.rpc");
|
||||
let admin_rpc_path = admin_rpc_path(ledger_path);
|
||||
|
||||
let event_loop = tokio::runtime::Builder::new_multi_thread()
|
||||
.thread_name("sol-adminrpc-el")
|
||||
@ -212,9 +212,29 @@ pub fn run(ledger_path: &Path, metadata: AdminRpcRequestMetadata) {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn admin_rpc_path(ledger_path: &Path) -> PathBuf {
|
||||
#[cfg(target_family = "windows")]
|
||||
{
|
||||
// More information about the wackiness of pipe names over at
|
||||
// https://docs.microsoft.com/en-us/windows/win32/ipc/pipe-names
|
||||
if let Some(ledger_filename) = ledger_path.file_name() {
|
||||
PathBuf::from(format!(
|
||||
"\\\\.\\pipe\\{}-admin.rpc",
|
||||
ledger_filename.to_string_lossy()
|
||||
))
|
||||
} else {
|
||||
PathBuf::from("\\\\.\\pipe\\admin.rpc")
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_family = "windows"))]
|
||||
{
|
||||
ledger_path.join("admin.rpc")
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to the Admin RPC interface
|
||||
pub async fn connect(ledger_path: &Path) -> std::result::Result<gen_client::Client, RpcError> {
|
||||
let admin_rpc_path = ledger_path.join("admin.rpc");
|
||||
let admin_rpc_path = admin_rpc_path(ledger_path);
|
||||
if !admin_rpc_path.exists() {
|
||||
Err(RpcError::Client(format!(
|
||||
"{} does not exist",
|
||||
|
@ -24,8 +24,8 @@ use {
|
||||
},
|
||||
solana_streamer::socket::SocketAddrSpace,
|
||||
solana_validator::{
|
||||
admin_rpc_service, dashboard::Dashboard, println_name_value, redirect_stderr_to_file,
|
||||
test_validator::*,
|
||||
admin_rpc_service, dashboard::Dashboard, ledger_lockfile, lock_ledger, println_name_value,
|
||||
redirect_stderr_to_file, test_validator::*,
|
||||
},
|
||||
std::{
|
||||
collections::HashSet,
|
||||
@ -168,7 +168,7 @@ fn main() {
|
||||
Arg::with_name("no_bpf_jit")
|
||||
.long("no-bpf-jit")
|
||||
.takes_value(false)
|
||||
.help("Disable the just-in-time compiler and instead use the interpreter for BPF"),
|
||||
.help("Disable the just-in-time compiler and instead use the interpreter for BPF. Windows always disables JIT."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("slots_per_epoch")
|
||||
@ -304,15 +304,8 @@ fn main() {
|
||||
});
|
||||
}
|
||||
|
||||
let mut ledger_fd_lock = fd_lock::RwLock::new(fs::File::open(&ledger_path).unwrap());
|
||||
let _ledger_lock = ledger_fd_lock.try_write().unwrap_or_else(|_| {
|
||||
println!(
|
||||
"Error: Unable to lock {} directory. Check if another validator is running",
|
||||
ledger_path.display()
|
||||
);
|
||||
exit(1);
|
||||
});
|
||||
|
||||
let mut ledger_lock = ledger_lockfile(&ledger_path);
|
||||
let _ledger_write_guard = lock_ledger(&ledger_path, &mut ledger_lock);
|
||||
if reset_ledger {
|
||||
remove_directory_contents(&ledger_path).unwrap_or_else(|err| {
|
||||
println!("Error: Unable to remove {}: {}", ledger_path.display(), err);
|
||||
@ -396,6 +389,10 @@ fn main() {
|
||||
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
|
||||
faucet_port,
|
||||
));
|
||||
// JIT not supported on the BPF VM in Windows currently: https://github.com/solana-labs/rbpf/issues/217
|
||||
#[cfg(target_family = "windows")]
|
||||
let bpf_jit = false;
|
||||
#[cfg(not(target_family = "windows"))]
|
||||
let bpf_jit = !matches.is_present("no_bpf_jit");
|
||||
|
||||
let mut programs = vec![];
|
||||
|
@ -3,9 +3,17 @@ pub use solana_core::test_validator;
|
||||
pub use solana_gossip::cluster_info::MINIMUM_VALIDATOR_PORT_RANGE_WIDTH;
|
||||
use {
|
||||
console::style,
|
||||
fd_lock::{RwLock, RwLockWriteGuard},
|
||||
indicatif::{ProgressDrawTarget, ProgressStyle},
|
||||
log::*,
|
||||
std::{borrow::Cow, env, fmt::Display, process::exit, thread::JoinHandle},
|
||||
std::{
|
||||
borrow::Cow,
|
||||
env,
|
||||
fmt::Display,
|
||||
fs::{File, OpenOptions},
|
||||
path::Path,
|
||||
process::exit,
|
||||
thread::JoinHandle,
|
||||
},
|
||||
};
|
||||
|
||||
pub mod admin_rpc_service;
|
||||
@ -13,7 +21,7 @@ pub mod dashboard;
|
||||
|
||||
#[cfg(unix)]
|
||||
fn redirect_stderr(filename: &str) {
|
||||
use std::{fs::OpenOptions, os::unix::io::AsRawFd};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
match OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
@ -36,17 +44,23 @@ pub fn redirect_stderr_to_file(logfile: Option<String>) -> Option<JoinHandle<()>
|
||||
env::set_var("RUST_BACKTRACE", "1")
|
||||
}
|
||||
|
||||
let logger_thread = match logfile {
|
||||
None => None,
|
||||
let filter = "solana=info";
|
||||
match logfile {
|
||||
None => {
|
||||
solana_logger::setup_with_default(filter);
|
||||
None
|
||||
}
|
||||
Some(logfile) => {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use log::info;
|
||||
let signals = signal_hook::iterator::Signals::new(&[signal_hook::SIGUSR1])
|
||||
.unwrap_or_else(|err| {
|
||||
eprintln!("Unable to register SIGUSR1 handler: {:?}", err);
|
||||
exit(1);
|
||||
});
|
||||
|
||||
solana_logger::setup_with_default(filter);
|
||||
redirect_stderr(&logfile);
|
||||
Some(std::thread::spawn(move || {
|
||||
for signal in signals.forever() {
|
||||
@ -60,14 +74,12 @@ pub fn redirect_stderr_to_file(logfile: Option<String>) -> Option<JoinHandle<()>
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
println!("logging to a file is not supported on this platform");
|
||||
println!("logrotate is not supported on this platform");
|
||||
solana_logger::setup_file_with_default(&logfile, filter);
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
solana_logger::setup_with_default("solana=info");
|
||||
logger_thread
|
||||
}
|
||||
}
|
||||
|
||||
pub fn port_validator(port: String) -> Result<(), String> {
|
||||
@ -133,3 +145,27 @@ impl ProgressBar {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ledger_lockfile(ledger_path: &Path) -> RwLock<File> {
|
||||
let lockfile = ledger_path.join("ledger.lock");
|
||||
fd_lock::RwLock::new(
|
||||
OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(&lockfile)
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn lock_ledger<'path, 'lock>(
|
||||
ledger_path: &'path Path,
|
||||
ledger_lockfile: &'lock mut RwLock<File>,
|
||||
) -> RwLockWriteGuard<'lock, File> {
|
||||
ledger_lockfile.try_write().unwrap_or_else(|_| {
|
||||
println!(
|
||||
"Error: Unable to lock {} directory. Check if another validator is running",
|
||||
ledger_path.display()
|
||||
);
|
||||
exit(1);
|
||||
})
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ use {
|
||||
},
|
||||
solana_streamer::socket::SocketAddrSpace,
|
||||
solana_validator::{
|
||||
admin_rpc_service, dashboard::Dashboard, new_spinner_progress_bar, println_name_value,
|
||||
redirect_stderr_to_file,
|
||||
admin_rpc_service, dashboard::Dashboard, ledger_lockfile, lock_ledger,
|
||||
new_spinner_progress_bar, println_name_value, redirect_stderr_to_file,
|
||||
},
|
||||
std::{
|
||||
collections::{HashSet, VecDeque},
|
||||
@ -2848,14 +2848,8 @@ pub fn main() {
|
||||
})
|
||||
});
|
||||
|
||||
let mut ledger_fd_lock = fd_lock::RwLock::new(fs::File::open(&ledger_path).unwrap());
|
||||
let _ledger_lock = ledger_fd_lock.try_write().unwrap_or_else(|_| {
|
||||
println!(
|
||||
"Error: Unable to lock {} directory. Check if another validator is running",
|
||||
ledger_path.display()
|
||||
);
|
||||
exit(1);
|
||||
});
|
||||
let mut ledger_lock = ledger_lockfile(&ledger_path);
|
||||
let _ledger_write_guard = lock_ledger(&ledger_path, &mut ledger_lock);
|
||||
|
||||
let start_progress = Arc::new(RwLock::new(ValidatorStartProgress::default()));
|
||||
let admin_service_cluster_info = Arc::new(RwLock::new(None));
|
||||
|
Reference in New Issue
Block a user