mod.rs
1 // Copyright (c) 2025-2026 ACDC Network 2 // This file is part of the alphaos library. 3 // 4 // Alpha Chain | Delta Chain Protocol 5 // International Monetary Graphite. 6 // 7 // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com). 8 // They built world-class ZK infrastructure. We installed the EASY button. 9 // Their cryptography: elegant. Our modifications: bureaucracy-compatible. 10 // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours. 11 // 12 // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0 13 // All modifications and new work: CC0 1.0 Universal Public Domain Dedication. 14 // No rights reserved. No permission required. No warranty. No refunds. 15 // 16 // https://creativecommons.org/publicdomain/zero/1.0/ 17 // SPDX-License-Identifier: CC0-1.0 18 19 mod bech32m; 20 pub use bech32m::*; 21 22 mod log_writer; 23 use log_writer::*; 24 25 mod dynamic_format; 26 use dynamic_format::*; 27 28 pub(crate) mod args; 29 30 pub mod logger; 31 pub use logger::*; 32 33 pub mod dev; 34 35 pub mod updater; 36 pub use updater::*; 37 38 use alphaos_node::network::NodeType; 39 40 use anyhow::Result; 41 use colored::*; 42 #[cfg(target_family = "unix")] 43 use nix::sys::resource::{getrlimit, Resource}; 44 45 /// Check if process's open files limit is above minimum and warn if not. 46 #[cfg(target_family = "unix")] 47 pub fn check_open_files_limit(minimum: u64) { 48 // Acquire current limits. 49 match getrlimit(Resource::RLIMIT_NOFILE) { 50 Ok((soft_limit, _)) => { 51 // Check if requirements are met. 52 if soft_limit < minimum { 53 // Warn about too low limit. 54 let warning = [ 55 format!("⚠️ The open files limit ({soft_limit}) for this process is lower than recommended."), 56 format!(" • To ensure correct behavior of the node, please raise it to at least {minimum}."), 57 " • See the `ulimit` command and `/etc/security/limits.conf` for more details.".to_owned(), 58 ] 59 .join("\n") 60 .yellow() 61 .bold(); 62 eprintln!("{warning}\n"); 63 } 64 } 65 Err(err) => { 66 // Warn about unknown limit. 67 let warning = [ 68 format!("⚠️ Unable to check the open files limit for this process due to {err}."), 69 format!(" • To ensure correct behavior of the node, please ensure it is at least {minimum}."), 70 " • See the `ulimit` command and `/etc/security/limits.conf` for more details.".to_owned(), 71 ] 72 .join("\n") 73 .yellow() 74 .bold(); 75 eprintln!("{warning}\n"); 76 } 77 }; 78 } 79 80 /// Returns the RAM memory in GiB. 81 pub(crate) fn detect_ram_memory() -> Result<u64, sys_info::Error> { 82 let ram_kib = sys_info::mem_info()?.total; 83 let ram_mib = ram_kib / 1024; 84 Ok(ram_mib / 1024) 85 } 86 87 /// Ensures the current system meets the minimum requirements for a validator. 88 /// Note: Some of the checks in this method are overly-permissive, in order to ensure 89 /// future hardware architecture changes do not prevent validators from running a node. 90 #[rustfmt::skip] 91 pub(crate) fn check_validator_machine(node_type: NodeType) { 92 // If the node is a validator, ensure it meets the minimum requirements. 93 if node_type.is_validator() { 94 // Ensure the system is a Linux-based system. 95 // Note: While macOS is not officially supported, we allow it for development purposes. 96 if !cfg!(target_os = "linux") && !cfg!(target_os = "macos") { 97 let message = "⚠️ The operating system of this machine is not supported for a validator (Ubuntu required)\n".to_string(); 98 println!("{}", message.yellow().bold()); 99 } 100 // Retrieve the number of cores. 101 let num_cores = num_cpus::get(); 102 // Enforce the minimum number of cores. 103 let min_num_cores = 64; 104 if num_cores < min_num_cores { 105 let message = format!("⚠️ The number of cores ({num_cores} cores) on this machine is insufficient for a validator (minimum {min_num_cores} cores)\n"); 106 println!("{}", message.yellow().bold()); 107 } 108 // Enforce the minimum amount of RAM. 109 if let Ok(ram) = crate::helpers::detect_ram_memory() { 110 let min_ram = 256; 111 if ram < min_ram { 112 let message = format!("⚠️ The amount of RAM ({ram} GiB) on this machine is insufficient for a validator (minimum {min_ram} GiB)\n"); 113 println!("{}", message.yellow().bold()); 114 } 115 } 116 } 117 }