Skip to content

Commit

Permalink
Resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Nov 22, 2022
2 parents 5eaa4ce + 8ff77f3 commit 75f72cf
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 35 deletions.
68 changes: 45 additions & 23 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ version = "2"
[dependencies.crossterm]
version = "0.25"

[target.'cfg(target_family = "unix")'.dependencies.nix]
version = "0.25"

[dependencies.num_cpus]
version = "1"

Expand Down Expand Up @@ -78,7 +81,7 @@ workspace = true
version = "1.0"

[dependencies.tokio]
version = "1.21"
version = "1.22"
features = ["rt"]

[dependencies.tracing-subscriber]
Expand Down
20 changes: 20 additions & 0 deletions cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ use rand_chacha::ChaChaRng;
use std::{net::SocketAddr, path::PathBuf};
use tokio::runtime::{self, Runtime};

/// The recommended minimum number of 'open files' limit for a beacon.
/// Beacons should be able to handle at least 1000 concurrent connections, each requiring 2 sockets.
#[cfg(target_family = "unix")]
const RECOMMENDED_MIN_NOFILES_LIMIT_BEACON: u64 = 2048;
/// The recommended minimum number of 'open files' limit for a validator.
/// Validators should be able to handle at least 500 concurrent connections, each requiring 2 sockets.
#[cfg(target_family = "unix")]
const RECOMMENDED_MIN_NOFILES_LIMIT_VALIDATOR: u64 = 1024;

/// Starts the snarkOS node.
#[derive(Clone, Debug, Parser)]
pub struct Start {
Expand Down Expand Up @@ -270,6 +279,17 @@ impl Start {
}
}

// If the node is a beacon, check if the open files limit is lower than recommended.
if node_type.is_beacon() {
#[cfg(target_family = "unix")]
crate::helpers::check_open_files_limit(RECOMMENDED_MIN_NOFILES_LIMIT_BEACON);
}
// If the node is a validator, check if the open files limit is lower than recommended.
if node_type.is_validator() {
#[cfg(target_family = "unix")]
crate::helpers::check_open_files_limit(RECOMMENDED_MIN_NOFILES_LIMIT_VALIDATOR);
}

// Initialize the node.
match node_type {
NodeType::Beacon => Node::new_beacon(self.node, rest_ip, account, &trusted_peers, genesis, cdn, self.dev).await,
Expand Down
42 changes: 42 additions & 0 deletions cli/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,45 @@ pub use logger::*;

pub mod updater;
pub use updater::*;

#[cfg(target_family = "unix")]
use colored::*;
#[cfg(target_family = "unix")]
use nix::sys::resource::{getrlimit, Resource};

/// Check if process's open files limit is above minimum and warn if not.
#[cfg(target_family = "unix")]
pub fn check_open_files_limit(minimum: u64) {
// Acquire current limits.
match getrlimit(Resource::RLIMIT_NOFILE) {
Ok((soft_limit, _)) => {
// Check if requirements are met.
if soft_limit < minimum {
// Warn about too low limit.
let warning = [
"⚠️ Warning!".to_owned(),
format!("⚠️ Current open files limit ({soft_limit}) for this process is lower than recommended."),
format!("⚠️ Please raise it to at least {minimum} to ensure correct behavior of the node."),
"⚠️ See `ulimit` command and `/etc/security/limits.conf` for more details.".to_owned(),
]
.join("\n")
.yellow()
.bold();
eprintln!("\n{warning}\n");
}
}
Err(err) => {
// Warn about unknown limit.
let warning = [
"⚠️ Warning!".to_owned(),
format!("⚠️ Couldn't check process's open files limit due to {err}."),
format!("⚠️ Please make sure it's at least {minimum} to ensure correct behavior of the node."),
"⚠️ See `ulimit` command and `/etc/security/limits.conf` for more details.".to_owned(),
]
.join("\n")
.yellow()
.bold();
eprintln!("\n{warning}\n");
}
};
}
2 changes: 1 addition & 1 deletion display/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ path = "../node"
workspace = true

[dependencies.tokio]
version = "1.21"
version = "1.22"
features = ["rt"]

[dependencies.tui]
Expand Down
5 changes: 1 addition & 4 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ workspace = true
version = "0.3"

[dependencies.tokio]
version = "1.21"
version = "1.22"
features = ["rt", "signal"]

[dependencies.tokio-util]
Expand All @@ -98,6 +98,3 @@ version = "0.40"

[dev-dependencies.rand_chacha]
version = "0.3.0"

[dev-dependencies.tokio-test]
version = "0.4"
4 changes: 2 additions & 2 deletions node/messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ version = "1"
version = "1.0"

[dependencies.bytes]
version = "1.0.0"
version = "1"

[dependencies.kadmium]
version = "0.6.0"
Expand All @@ -42,7 +42,7 @@ workspace = true
version = "0.9.0"

[dependencies.tokio]
version = "1.21"
version = "1.22"
features = [
"io-util",
"macros",
Expand Down
4 changes: 2 additions & 2 deletions node/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ version = "0.1"
version = "1.0"

[dependencies.bytes]
version = "1.0.0"
version = "1"

[dependencies.futures]
version = "0.3.21"
Expand Down Expand Up @@ -67,7 +67,7 @@ workspace = true
version = "0.3"

[dependencies.tokio]
version = "1.21"
version = "1.22"
features = [
"io-util",
"macros",
Expand Down
2 changes: 1 addition & 1 deletion node/src/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<N: Network, C: ConsensusStorage<N>> Prover<N, C> {
// Load the coinbase puzzle.
let coinbase_puzzle = CoinbasePuzzle::<N>::load()?;
// Compute the maximum number of puzzle instances.
let max_puzzle_instances = num_cpus::get().saturating_sub(2).min(6).max(1);
let max_puzzle_instances = num_cpus::get().saturating_sub(2).clamp(1, 6);
// Initialize the node.
let node = Self {
account,
Expand Down
1 change: 1 addition & 0 deletions node/store/src/rocksdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl Database for RocksDB {
let rocksdb = {
options.increase_parallelism(2);
options.create_if_missing(true);

Arc::new(rocksdb::DB::open(&options, primary)?)
};

Expand Down
2 changes: 1 addition & 1 deletion node/tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ bytes = "1"
futures-util = { version = "0.3", features = ["sink"] }
once_cell = { version = "1", features = ["parking_lot"] }
parking_lot = "0.12"
tokio = { version = "1.14", features = ["io-util", "net", "parking_lot", "rt", "sync", "time"] }
tokio = { version = "1.22", features = ["io-util", "net", "parking_lot", "rt", "sync", "time"] }
tokio-util = { version = "0.7", features = ["codec"] }
tracing = { version = "0.1", default-features = false }

0 comments on commit 75f72cf

Please sign in to comment.