diff --git a/core/benches/banking_stage.rs b/core/benches/banking_stage.rs index 13cc77e9bd..ba4bdfa238 100644 --- a/core/benches/banking_stage.rs +++ b/core/benches/banking_stage.rs @@ -113,7 +113,7 @@ fn make_accounts_txs(txes: usize, mint_keypair: &Keypair, hash: Hash) -> Vec = (0..64).map(|_| thread_rng().gen()).collect(); + let sig: Vec<_> = (0..64).map(|_| thread_rng().gen::()).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])]; diff --git a/install/src/command.rs b/install/src/command.rs index dd317cab58..005c6bf03d 100644 --- a/install/src/command.rs +++ b/install/src/command.rs @@ -362,7 +362,7 @@ fn get_windows_path_var() -> Result, 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, diff --git a/logger/src/lib.rs b/logger/src/lib.rs index 2e044a01ce..9820ea2f86 100644 --- a/logger/src/lib.rs +++ b/logger/src/lib.rs @@ -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); +} diff --git a/net-utils/src/lib.rs b/net-utils/src/lib.rs index 663525bbde..7a12aab69f 100644 --- a/net-utils/src/lib.rs +++ b/net-utils/src/lib.rs @@ -374,7 +374,7 @@ pub fn is_host_port(string: String) -> Result<(), String> { #[cfg(windows)] fn udp_socket(_reuseaddr: bool) -> io::Result { - let sock = Socket::new(Domain::ipv4(), Type::dgram(), None)?; + let sock = Socket::new(Domain::IPV4, Type::DGRAM, None)?; Ok(sock) } diff --git a/scripts/cargo-install-all.sh b/scripts/cargo-install-all.sh index 2889c4d4d6..258f2f10a7 100755 --- a/scripts/cargo-install-all.sh +++ b/scripts/cargo-install-all.sh @@ -77,6 +77,7 @@ if [[ $CI_OS_NAME = windows ]]; then solana-install-init solana-keygen solana-stake-accounts + solana-test-validator solana-tokens ) else diff --git a/sys-tuner/src/main.rs b/sys-tuner/src/main.rs index e00a64b43e..ac61363dfb 100644 --- a/sys-tuner/src/main.rs +++ b/sys-tuner/src/main.rs @@ -1,3 +1,4 @@ +#[cfg(target_os = "linux")] use clap::{crate_description, crate_name, value_t_or_exit, App, Arg}; use log::*; diff --git a/validator/src/admin_rpc_service.rs b/validator/src/admin_rpc_service.rs index 78e643bceb..6a3abc515f 100644 --- a/validator/src/admin_rpc_service.rs +++ b/validator/src/admin_rpc_service.rs @@ -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 { - 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", diff --git a/validator/src/bin/solana-test-validator.rs b/validator/src/bin/solana-test-validator.rs index dc77f4eac7..5d2f08aefc 100644 --- a/validator/src/bin/solana-test-validator.rs +++ b/validator/src/bin/solana-test-validator.rs @@ -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![]; diff --git a/validator/src/lib.rs b/validator/src/lib.rs index 6d4c35e7a3..46b5d65d4a 100644 --- a/validator/src/lib.rs +++ b/validator/src/lib.rs @@ -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) -> Option 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) -> Option } #[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 { + 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, +) -> 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); + }) +} diff --git a/validator/src/main.rs b/validator/src/main.rs index 2531fb3555..92f1ef55e8 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -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));