mod bech32m;
pub use bech32m::*;
mod log_writer;
use log_writer::*;
mod dynamic_format;
use dynamic_format::*;
pub(crate) mod args;
pub mod logger;
pub use logger::*;
pub mod dev;
pub mod updater;
pub use updater::*;
use snarkos_node::network::NodeType;
use anyhow::Result;
use colored::*;
#[cfg(target_family = "unix")]
use nix::sys::resource::{Resource, getrlimit};
#[cfg(target_family = "unix")]
pub fn check_open_files_limit(minimum: u64) {
match getrlimit(Resource::RLIMIT_NOFILE) {
Ok((soft_limit, _)) => {
if soft_limit < minimum {
let warning = [
format!("⚠️ The open files limit ({soft_limit}) for this process is lower than recommended."),
format!(" • To ensure correct behavior of the node, please raise it to at least {minimum}."),
" • See the `ulimit` command and `/etc/security/limits.conf` for more details.".to_owned(),
]
.join("\n")
.yellow()
.bold();
eprintln!("{warning}\n");
}
}
Err(err) => {
let warning = [
format!("⚠️ Unable to check the open files limit for this process due to {err}."),
format!(" • To ensure correct behavior of the node, please ensure it is at least {minimum}."),
" • See the `ulimit` command and `/etc/security/limits.conf` for more details.".to_owned(),
]
.join("\n")
.yellow()
.bold();
eprintln!("{warning}\n");
}
};
}
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)
}
#[rustfmt::skip]
pub(crate) fn check_validator_machine(node_type: NodeType) {
if node_type.is_validator() {
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();
println!("{}", message.yellow().bold());
}
let num_cores = num_cpus::get();
let min_num_cores = 64;
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");
println!("{}", message.yellow().bold());
}
if let Ok(ram) = crate::helpers::detect_ram_memory() {
let min_ram = 256;
if ram < min_ram {
let message = format!("⚠️ The amount of RAM ({ram} GiB) on this machine is insufficient for a validator (minimum {min_ram} GiB)\n");
println!("{}", message.yellow().bold());
}
}
}
}