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