Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Sep 27, 2023
1 parent 52339d6 commit 0e12e4e
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The following are **minimum** requirements to run an Aleo node:
- **OS**: 64-bit architectures only, latest up-to-date for security
- Clients: Ubuntu 20.04, macOS Ventura or later, Windows 11 or later
- Provers: Ubuntu 20.04, macOS Ventura or later
- Validators: Ubuntu 20.04, macOS Ventura or later
- Validators: Ubuntu 20.04
- **CPU**: 64-bit architectures only
- Clients: 16-cores
- Provers: 32-cores (64-cores preferred)
Expand Down
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ version = "=2.1.7"
[dependencies.snarkvm]
workspace = true

[dependencies.sys-info]
version = "0.9"

[dependencies.thiserror]
version = "1.0"

Expand Down
2 changes: 2 additions & 0 deletions cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ impl Start {
if node_type.is_validator() {
crate::helpers::check_open_files_limit(RECOMMENDED_MIN_NOFILES_LIMIT);
}
// Check if the machine meets the minimum requirements for a validator.
crate::helpers::check_validator_machine(node_type, self.dev.is_some());

// Initialize the node.
match node_type {
Expand Down
92 changes: 92 additions & 0 deletions cli/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub use logger::*;
pub mod updater;
pub use updater::*;

use snarkos_node::router::messages::NodeType;

#[cfg(target_family = "unix")]
use colored::*;
#[cfg(target_family = "unix")]
Expand Down Expand Up @@ -63,3 +65,93 @@ pub fn check_open_files_limit(minimum: u64) {
}
};
}

#[cfg(target_family = "unix")]
#[derive(Debug)]
pub(crate) enum DriveType {
SSD,
HDD,
Unknown,
}

/// Returns the drive type of the given device.
#[cfg(target_family = "unix")]
pub(crate) fn detect_drive_type(device: &str) -> Result<DriveType, std::io::Error> {
let path = format!("/sys/block/{}/queue/rotational", device);
match std::fs::read_to_string(&path)?.trim() {
"0" => Ok(DriveType::SSD),
"1" => Ok(DriveType::HDD),
_ => Ok(DriveType::Unknown),
}
}

/// Returns `true` if the current system is a NVMe system.
#[cfg(target_family = "unix")]
pub(crate) fn is_nvme() -> Result<bool, std::io::Error> {
let path = "/sys/class/nvme/";
Ok(std::fs::metadata(path)?.is_dir())
}

/// Returns the RAM memory in GiB.
pub(crate) fn detect_ram_memory() -> Result<u64, sys_info::Error> {
let ram_kib = sys_info::mem_info()?.total;
let ram_mib = ram_kib / 1024;
Ok(ram_mib / 1024)
}

/// Ensures the current system meets the minimum requirements for a validator.
#[rustfmt::skip]
pub(crate) fn check_validator_machine(node_type: NodeType, is_dev: bool) {
// If the node is a validator, ensure it meets the minimum requirements.
if node_type.is_validator() {
// Ensure the system is a Linux-based system.
// Note: While macOS is not officially supported, we allow it for development purposes.
if !cfg!(target_os = "linux") && !cfg!(target_os = "macos") {
let message = "⚠️ The operating system of this machine is not supported for a validator (Ubuntu required)\n".to_string();
match is_dev {
true => println!("{}", message.yellow().bold()),
false => panic!("{message} in production mode"),
}
}
// Retrieve the number of cores.
let num_cores = num_cpus::get();
// Enforce the minimum number of cores.
let min_num_cores = 32;
if num_cores < min_num_cores {
let message = format!("⚠️ The number of cores ({num_cores} cores) on this machine is insufficient for a validator (minimum {min_num_cores} cores)\n");
match is_dev {
true => println!("{}", message.yellow().bold()),
false => panic!("{message} in production mode"),
}
}
// Enforce the minimum amount of RAM.
if let Ok(ram) = crate::helpers::detect_ram_memory() {
let min_ram = 64;
if ram < min_ram {
let message = format!("⚠️ The amount of RAM ({ram} GB) on this machine is insufficient for a validator (minimum {min_ram} GB)\n");
match is_dev {
true => println!("{}", message.yellow().bold()),
false => panic!("{message} in production mode"),
}
}
}
// Enforce the required drive type.
#[cfg(target_family = "unix")]
if let Ok(crate::helpers::DriveType::HDD) = crate::helpers::detect_drive_type("sda") {
let message = "⚠️ The drive type of this machine is an HDD, and is insufficient for a validator (NVMe SSD required)\n".to_string();
match is_dev {
true => println!("{}", message.yellow().bold()),
false => panic!("{message} in production mode"),
}
}
// Enforce the drive.
#[cfg(target_family = "unix")]
if let Ok(false) = crate::helpers::is_nvme() {
let message = "⚠️ This machine does not have an NVMe drive, and is insufficient for a validator (NVMe SSD required)\n".to_string();
match is_dev {
true => println!("{}", message.yellow().bold()),
false => panic!("{message} in production mode"),
}
}
}
}

0 comments on commit 0e12e4e

Please sign in to comment.