snarkos_cli/helpers/
mod.rs1mod bech32m;
17pub use bech32m::*;
18
19mod log_writer;
20use log_writer::*;
21
22mod dynamic_format;
23use dynamic_format::*;
24
25pub mod logger;
26pub use logger::*;
27
28pub mod updater;
29pub use updater::*;
30
31use snarkos_node::router::messages::NodeType;
32
33use colored::*;
34#[cfg(target_family = "unix")]
35use nix::sys::resource::{Resource, getrlimit};
36
37#[cfg(target_family = "unix")]
39pub fn check_open_files_limit(minimum: u64) {
40 match getrlimit(Resource::RLIMIT_NOFILE) {
42 Ok((soft_limit, _)) => {
43 if soft_limit < minimum {
45 let warning = [
47 format!("⚠️ The open files limit ({soft_limit}) for this process is lower than recommended."),
48 format!(" • To ensure correct behavior of the node, please raise it to at least {minimum}."),
49 " • See the `ulimit` command and `/etc/security/limits.conf` for more details.".to_owned(),
50 ]
51 .join("\n")
52 .yellow()
53 .bold();
54 eprintln!("{warning}\n");
55 }
56 }
57 Err(err) => {
58 let warning = [
60 format!("⚠️ Unable to check the open files limit for this process due to {err}."),
61 format!(" • To ensure correct behavior of the node, please ensure it is at least {minimum}."),
62 " • See the `ulimit` command and `/etc/security/limits.conf` for more details.".to_owned(),
63 ]
64 .join("\n")
65 .yellow()
66 .bold();
67 eprintln!("{warning}\n");
68 }
69 };
70}
71
72pub(crate) fn detect_ram_memory() -> Result<u64, sys_info::Error> {
74 let ram_kib = sys_info::mem_info()?.total;
75 let ram_mib = ram_kib / 1024;
76 Ok(ram_mib / 1024)
77}
78
79#[rustfmt::skip]
83pub(crate) fn check_validator_machine(node_type: NodeType) {
84 if node_type.is_validator() {
86 if !cfg!(target_os = "linux") && !cfg!(target_os = "macos") {
89 let message = "⚠️ The operating system of this machine is not supported for a validator (Ubuntu required)\n".to_string();
90 println!("{}", message.yellow().bold());
91 }
92 let num_cores = num_cpus::get();
94 let min_num_cores = 64;
96 if num_cores < min_num_cores {
97 let message = format!("⚠️ The number of cores ({num_cores} cores) on this machine is insufficient for a validator (minimum {min_num_cores} cores)\n");
98 println!("{}", message.yellow().bold());
99 }
100 if let Ok(ram) = crate::helpers::detect_ram_memory() {
102 let min_ram = 256;
103 if ram < min_ram {
104 let message = format!("⚠️ The amount of RAM ({ram} GiB) on this machine is insufficient for a validator (minimum {min_ram} GiB)\n");
105 println!("{}", message.yellow().bold());
106 }
107 }
108 }
109}