Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Hotfixes for testnet3 branch #3186

Merged
merged 42 commits into from Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
73d5ad6
perf: use a blocking task for check_batch_header
ljedrz Oct 31, 2023
cca737d
perf: use a blocking task for insert_certificate
ljedrz Oct 31, 2023
adfc4bc
perf: use a blocking task for sync_certificate_with_block
ljedrz Oct 31, 2023
e8c95e6
Resolve cherry-pick of d419d9d
howardwu Feb 11, 2024
77c549f
Update redundancy factor
howardwu Feb 11, 2024
bda7672
Resolve cherry-pick of f779241
howardwu Feb 11, 2024
73ca892
Improve logging
howardwu Feb 11, 2024
bf01fc4
Update node/bft/src/primary.rs
howardwu Feb 11, 2024
f42ba9b
fix: don't try to propose a batch when we're not yet synced
joske Feb 14, 2024
7cb4d70
feat: handle more POSIX signals on UNIX systems
ljedrz Feb 19, 2024
9df16b4
Update is_proposing check
raychu86 Feb 20, 2024
441867f
perf: skip the timed batch proposal if round progression already trig…
ljedrz Feb 21, 2024
42089db
Update node/bft/src/primary.rs
howardwu Mar 2, 2024
72eed64
perf: cache the recently queried committees
ljedrz Feb 20, 2024
a84284d
fix: only cache committies with matching rounds
ljedrz Feb 21, 2024
6195f3b
nit: reorder items
howardwu Mar 2, 2024
e9ea9d5
nit: feature optional
howardwu Mar 2, 2024
03564e8
Add round check in signed proposals cache
raychu86 Feb 20, 2024
6a2aa4a
Use the certificate_round for lookback selection
raychu86 Mar 3, 2024
fc3def3
Add fee transmission check in ensure_transmission_id_matches
raychu86 Feb 19, 2024
572b2fa
Perform basic check on transmissions in batch proposals
raychu86 Feb 19, 2024
ff36283
Resolve cherry-pick for f8c2827
raychu86 Mar 3, 2024
3affa87
Skip seen transactions and solutions instead of bailing
HarukaMa Mar 4, 2024
c4ecc09
feat: jemalloc by default on linux
joske Mar 5, 2024
9425939
fix: x86_64 only
joske Mar 7, 2024
31ae363
Resolve cherry-pick for f033e7f
raychu86 Mar 6, 2024
91e7460
Skip ordering certs if it exists in the ledger
raychu86 Mar 6, 2024
3120192
Resolve cherry-pick for 690323e
raychu86 Mar 6, 2024
084a070
Resolve cherry-pick of 04b0407
raychu86 Mar 6, 2024
f161cf6
Add test for sync_bft_dag_at_bootup
raychu86 Mar 6, 2024
d30e763
Adds unit test for pre and post shutdown bft sync
mdelle1 Mar 7, 2024
fbfe152
Adds unit test for duplicate vertices in commit subdags after bft sync
mdelle1 Mar 7, 2024
8e21015
clippy
raychu86 Mar 7, 2024
183b25d
nit
raychu86 Mar 7, 2024
345681c
nit
raychu86 Mar 8, 2024
843da3e
Update node/bft/src/bft.rs
raychu86 Mar 9, 2024
76acf47
Merge branch 'testnet3-staging' into testnet3-staging-next
howardwu Mar 23, 2024
c9a499b
nit: fix interface
howardwu Mar 23, 2024
e546d08
Merge branch 'testnet3' into testnet3-staging-next
howardwu Mar 23, 2024
0f599ef
Updates bft unit test for garbage collection
mdelle1 Mar 24, 2024
1031c79
Updates block sync redundancy factor for unit tests
mdelle1 Mar 24, 2024
ae6d79c
Rustfmt
howardwu Mar 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
117 changes: 59 additions & 58 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Cargo.toml
Expand Up @@ -55,7 +55,6 @@ name = "snarkos"
path = "snarkos/main.rs"

[features]
jemalloc = [ "tikv-jemallocator" ]
metrics = [ "snarkos-node-metrics", "snarkos-node/metrics" ]

[dependencies.anyhow]
Expand Down Expand Up @@ -120,9 +119,8 @@ version = "=2.2.7"
path = "./node/tcp"
version = "=2.2.7"

[dependencies.tikv-jemallocator]
version = "0.5"
optional = true
[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.dependencies]
tikv-jemallocator = "0.5"

[dev-dependencies.rusty-hook]
version = "0.11.2"
Expand Down
23 changes: 6 additions & 17 deletions cli/src/commands/start.rs
Expand Up @@ -248,7 +248,7 @@ impl Start {
let _ = PrivateKey::<N>::new(&mut rng)?;
}
let private_key = PrivateKey::<N>::new(&mut rng)?;
println!("🔑 Your development private key for node {dev} is {}\n", private_key.to_string().bold());
println!("🔑 Your development private key for node {dev} is {}.\n", private_key.to_string().bold());
private_key
})
}
Expand Down Expand Up @@ -411,7 +411,7 @@ impl Start {
// If the display is not enabled, render the welcome message.
if self.nodisplay {
// Print the Aleo address.
println!("🪪 Your Aleo address is {}.\n", account.address().to_string().bold());
println!("👛 Your Aleo address is {}.\n", account.address().to_string().bold());
// Print the node type and network.
println!(
"🧭 Starting {} on {} {} at {}.\n",
Expand Down Expand Up @@ -465,23 +465,12 @@ impl Start {
fn runtime() -> Runtime {
// Retrieve the number of cores.
let num_cores = num_cpus::get();
// Determine the number of main cores.
let main_cores = match num_cores {
// Insufficient
0..=3 => {
eprintln!("The number of cores is insufficient, at least 4 are needed.");
std::process::exit(1);
}
// Efficiency mode
4..=8 => 2,
// Standard mode
9..=16 => 8,
// Performance mode
_ => 16,
};

// Initialize the number of tokio worker threads, max tokio blocking threads, and rayon cores.
// Note: We intentionally set the number of tokio worker threads and number of rayon cores to be
// more than the number of physical cores, because the node is expected to be I/O-bound.
let (num_tokio_worker_threads, max_tokio_blocking_threads, num_rayon_cores_global) =
{ (num_cores.min(main_cores), 512, num_cores.saturating_sub(main_cores).max(1)) };
(2 * num_cores, 512, num_cores);

// Initialize the parallelization parameters.
rayon::ThreadPoolBuilder::new()
Expand Down
8 changes: 4 additions & 4 deletions cli/src/helpers/mod.rs
Expand Up @@ -41,8 +41,8 @@ pub fn check_open_files_limit(minimum: u64) {
// Warn about too low limit.
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(),
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()
Expand All @@ -54,8 +54,8 @@ pub fn check_open_files_limit(minimum: u64) {
// Warn about unknown limit.
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(),
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()
Expand Down
5 changes: 4 additions & 1 deletion node/bft/ledger-service/Cargo.toml
Expand Up @@ -18,7 +18,7 @@ edition = "2021"

[features]
default = [ ]
ledger = [ "rand", "tokio", "tracing" ]
ledger = [ "parking_lot", "rand", "tokio", "tracing" ]
ledger-write = [ ]
mock = [ "parking_lot", "tracing" ]
prover = [ ]
Expand All @@ -32,6 +32,9 @@ version = "0.1"
version = "2.1"
features = [ "serde", "rayon" ]

[dependencies.lru]
version = "0.12"

[dependencies.parking_lot]
version = "0.12"
optional = true
Expand Down
31 changes: 27 additions & 4 deletions node/bft/ledger-service/src/ledger.rs
Expand Up @@ -26,6 +26,8 @@ use snarkvm::{
};

use indexmap::IndexMap;
use lru::LruCache;
use parking_lot::Mutex;
use std::{
fmt,
ops::Range,
Expand All @@ -35,18 +37,23 @@ use std::{
},
};

/// The capacity of the LRU holiding the recently queried committees.
const COMMITTEE_CACHE_SIZE: usize = 16;

/// A core ledger service.
pub struct CoreLedgerService<N: Network, C: ConsensusStorage<N>> {
ledger: Ledger<N, C>,
coinbase_verifying_key: Arc<CoinbaseVerifyingKey<N>>,
committee_cache: Arc<Mutex<LruCache<u64, Committee<N>>>>,
shutdown: Arc<AtomicBool>,
}

impl<N: Network, C: ConsensusStorage<N>> CoreLedgerService<N, C> {
/// Initializes a new core ledger service.
pub fn new(ledger: Ledger<N, C>, shutdown: Arc<AtomicBool>) -> Self {
let coinbase_verifying_key = Arc::new(ledger.coinbase_puzzle().coinbase_verifying_key().clone());
Self { ledger, coinbase_verifying_key, shutdown }
let committee_cache = Arc::new(Mutex::new(LruCache::new(COMMITTEE_CACHE_SIZE.try_into().unwrap())));
Self { ledger, coinbase_verifying_key, committee_cache, shutdown }
}
}

Expand Down Expand Up @@ -127,9 +134,19 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for CoreLedgerService<
/// Returns the committee for the given round.
/// If the given round is in the future, then the current committee is returned.
fn get_committee_for_round(&self, round: u64) -> Result<Committee<N>> {
// Check if the committee is already in the cache.
if let Some(committee) = self.committee_cache.lock().get(&round) {
return Ok(committee.clone());
}

match self.ledger.get_committee_for_round(round)? {
// Return the committee if it exists.
Some(committee) => Ok(committee),
Some(committee) => {
// Insert the committee into the cache.
self.committee_cache.lock().push(round, committee.clone());
// Return the committee.
Ok(committee)
}
// Return the current committee if the round is in the future.
None => {
// Retrieve the current committee.
Expand Down Expand Up @@ -174,8 +191,8 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for CoreLedgerService<
}
}

/// Ensures the given transmission ID matches the given transmission.
fn ensure_transmission_id_matches(
/// Ensures that the given transmission is not a fee and matches the given transmission ID.
fn ensure_transmission_is_well_formed(
&self,
transmission_id: TransmissionID<N>,
transmission: &mut Transmission<N>,
Expand All @@ -185,6 +202,7 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for CoreLedgerService<
(TransmissionID::Transaction(expected_transaction_id), Transmission::Transaction(transaction_data)) => {
match transaction_data.clone().deserialize_blocking() {
Ok(transaction) => {
// Ensure the transaction ID matches the expected transaction ID.
if transaction.id() != expected_transaction_id {
bail!(
"Received mismatching transaction ID - expected {}, found {}",
Expand All @@ -193,6 +211,11 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for CoreLedgerService<
);
}

// Ensure the transaction is not a fee transaction.
if transaction.is_fee() {
bail!("Received a fee transaction in a transmission");
}

// Update the transmission with the deserialized transaction.
*transaction_data = Data::Object(transaction);
}
Expand Down
4 changes: 2 additions & 2 deletions node/bft/ledger-service/src/mock.rs
Expand Up @@ -143,8 +143,8 @@ impl<N: Network> LedgerService<N> for MockLedgerService<N> {
Ok(false)
}

/// Ensures the given transmission ID matches the given transmission.
fn ensure_transmission_id_matches(
/// Ensures that the given transmission is not a fee and matches the given transmission ID.
fn ensure_transmission_is_well_formed(
&self,
transmission_id: TransmissionID<N>,
_transmission: &mut Transmission<N>,
Expand Down
4 changes: 2 additions & 2 deletions node/bft/ledger-service/src/prover.rs
Expand Up @@ -124,8 +124,8 @@ impl<N: Network> LedgerService<N> for ProverLedgerService<N> {
bail!("Transmission '{transmission_id}' does not exist in prover")
}

/// Ensures the given transmission ID matches the given transmission.
fn ensure_transmission_id_matches(
/// Ensures that the given transmission is not a fee and matches the given transmission ID.
fn ensure_transmission_is_well_formed(
&self,
_transmission_id: TransmissionID<N>,
_transmission: &mut Transmission<N>,
Expand Down
4 changes: 2 additions & 2 deletions node/bft/ledger-service/src/traits.rs
Expand Up @@ -78,8 +78,8 @@ pub trait LedgerService<N: Network>: Debug + Send + Sync {
/// Returns `true` if the ledger contains the given transmission ID.
fn contains_transmission(&self, transmission_id: &TransmissionID<N>) -> Result<bool>;

/// Ensures the given transmission ID matches the given transmission.
fn ensure_transmission_id_matches(
/// Ensures that the given transmission is not a fee and matches the given transmission ID.
fn ensure_transmission_is_well_formed(
&self,
transmission_id: TransmissionID<N>,
transmission: &mut Transmission<N>,
Expand Down
2 changes: 1 addition & 1 deletion node/bft/ledger-service/src/translucent.rs
Expand Up @@ -135,7 +135,7 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for TranslucentLedgerS
}

/// Always succeeds.
fn ensure_transmission_id_matches(
fn ensure_transmission_is_well_formed(
&self,
_transmission_id: TransmissionID<N>,
_transmission: &mut Transmission<N>,
Expand Down