From cd9bad2c75ac349d94f59eea713438e2d464d648 Mon Sep 17 00:00:00 2001 From: Victor Sint Nicolaas Date: Tue, 27 Feb 2024 11:59:55 +0100 Subject: [PATCH 1/7] Add --dev-traffic flag --- .devnet/start.sh | 2 +- cli/src/commands/start.rs | 9 ++++++++- devnet.sh | 4 ++-- node/src/node.rs | 2 ++ node/src/validator/mod.rs | 11 +++++++---- node/tests/common/node.rs | 1 + 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.devnet/start.sh b/.devnet/start.sh index f61cea6af0..5214836d71 100755 --- a/.devnet/start.sh +++ b/.devnet/start.sh @@ -37,7 +37,7 @@ start_snarkos_in_tmux() { tmux new-session -d -s snarkos-session # Send the snarkOS start command to the tmux session with the NODE_ID - tmux send-keys -t "snarkos-session" "snarkos start --nodisplay --bft 0.0.0.0:5000 --rest 0.0.0.0:3030 --peers $NODE_IP:4130 --validators $NODE_IP:5000 --verbosity $VERBOSITY --dev $NODE_ID --dev-num-validators $NUM_INSTANCES --validator --metrics" C-m + tmux send-keys -t "snarkos-session" "snarkos start --nodisplay --bft 0.0.0.0:5000 --rest 0.0.0.0:3030 --peers $NODE_IP:4130 --validators $NODE_IP:5000 --verbosity $VERBOSITY --dev $NODE_ID --dev-traffic --dev-num-validators $NUM_INSTANCES --validator --metrics" C-m exit # Exit root user EOF diff --git a/cli/src/commands/start.rs b/cli/src/commands/start.rs index 8205d35c05..7039744a92 100644 --- a/cli/src/commands/start.rs +++ b/cli/src/commands/start.rs @@ -137,6 +137,9 @@ pub struct Start { /// If development mode is enabled, specify the number of genesis validators (default: 4) #[clap(long)] pub dev_num_validators: Option, + /// If developtment mode is enabled, specify whether node 0 should generate traffic to drive the network + #[clap(long = "dev-traffic")] + pub dev_traffic: bool, /// Specify the path to a directory containing the ledger #[clap(long = "storage_path")] pub storage_path: Option, @@ -436,6 +439,10 @@ impl Start { if self.dev_num_validators.is_some() { eprintln!("The '--dev-num-validators' flag is ignored because '--dev' is not set"); } + // If the `dev_traffic` flag is set, inform the user that it is ignored. + if self.dev_traffic { + eprintln!("The '--dev-traffic' flag is ignored because '--dev' is not set"); + } Block::from_bytes_le(N::genesis_bytes()) } @@ -527,7 +534,7 @@ impl Start { // Initialize the node. let bft_ip = if self.dev.is_some() { self.bft } else { None }; match node_type { - NodeType::Validator => Node::new_validator(self.node, bft_ip, rest_ip, self.rest_rps, account, &trusted_peers, &trusted_validators, genesis, cdn, storage_mode).await, + NodeType::Validator => Node::new_validator(self.node, bft_ip, rest_ip, self.rest_rps, account, &trusted_peers, &trusted_validators, genesis, cdn, self.dev_traffic, storage_mode).await, NodeType::Prover => Node::new_prover(self.node, account, &trusted_peers, genesis, storage_mode).await, NodeType::Client => Node::new_client(self.node, rest_ip, self.rest_rps, account, &trusted_peers, genesis, cdn, storage_mode).await, } diff --git a/devnet.sh b/devnet.sh index e91627335a..f4458625a2 100755 --- a/devnet.sh +++ b/devnet.sh @@ -64,12 +64,12 @@ for validator_index in "${validator_indices[@]}"; do # Send the command to start the validator to the new window and capture output to the log file if [ "$validator_index" -eq 0 ]; then - tmux send-keys -t "devnet:window$validator_index" "snarkos start --nodisplay --dev $validator_index --dev-num-validators $total_validators --validator --logfile $log_file --metrics" C-m + tmux send-keys -t "devnet:window$validator_index" "snarkos start --nodisplay --dev $validator_index --dev-traffic --dev-num-validators $total_validators --validator --logfile $log_file --metrics" C-m else # Create a new window with a unique name window_index=$((validator_index + index_offset)) tmux new-window -t "devnet:$window_index" -n "window$validator_index" - tmux send-keys -t "devnet:window$validator_index" "snarkos start --nodisplay --dev $validator_index --dev-num-validators $total_validators --validator --logfile $log_file" C-m + tmux send-keys -t "devnet:window$validator_index" "snarkos start --nodisplay --dev $validator_index --dev-traffic --dev-num-validators $total_validators --validator --logfile $log_file" C-m fi done diff --git a/node/src/node.rs b/node/src/node.rs index e6435d6ef6..908812543c 100644 --- a/node/src/node.rs +++ b/node/src/node.rs @@ -49,6 +49,7 @@ impl Node { trusted_validators: &[SocketAddr], genesis: Block, cdn: Option, + dev_traffic: bool, storage_mode: StorageMode, ) -> Result { Ok(Self::Validator(Arc::new( @@ -62,6 +63,7 @@ impl Node { trusted_validators, genesis, cdn, + dev_traffic, storage_mode, ) .await?, diff --git a/node/src/validator/mod.rs b/node/src/validator/mod.rs index 7ac250f1a3..7066e85057 100644 --- a/node/src/validator/mod.rs +++ b/node/src/validator/mod.rs @@ -82,6 +82,7 @@ impl> Validator { trusted_validators: &[SocketAddr], genesis: Block, cdn: Option, + dev_traffic: bool, storage_mode: StorageMode, ) -> Result { // Prepare the shutdown flag. @@ -139,7 +140,7 @@ impl> Validator { shutdown, }; // Initialize the transaction pool. - node.initialize_transaction_pool(storage_mode)?; + node.initialize_transaction_pool(storage_mode, dev_traffic)?; // Initialize the REST server. if let Some(rest_ip) = rest_ip { @@ -339,7 +340,7 @@ impl> Validator { // } /// Initialize the transaction pool. - fn initialize_transaction_pool(&self, storage_mode: StorageMode) -> Result<()> { + fn initialize_transaction_pool(&self, storage_mode: StorageMode, dev_traffic: bool) -> Result<()> { use snarkvm::console::{ program::{Identifier, Literal, ProgramID, Value}, types::U64, @@ -353,8 +354,8 @@ impl> Validator { match storage_mode { // If the node is running in development mode, only generate if you are allowed. StorageMode::Development(id) => { - // If the node is not the first node, do not start the loop. - if id != 0 { + // If the node is not the first node, or if we should not create dev traffic, do not start the loop. + if id != 0 || !dev_traffic { return Ok(()); } } @@ -472,6 +473,7 @@ mod tests { let node = SocketAddr::from_str("0.0.0.0:4130").unwrap(); let rest = SocketAddr::from_str("0.0.0.0:3030").unwrap(); let storage_mode = StorageMode::Development(0); + let dev_traffic = true; // Initialize an (insecure) fixed RNG. let mut rng = ChaChaRng::seed_from_u64(1234567890u64); @@ -494,6 +496,7 @@ mod tests { &[], genesis, None, + dev_traffic, storage_mode, ) .await diff --git a/node/tests/common/node.rs b/node/tests/common/node.rs index 80c0262903..f62fc7a295 100644 --- a/node/tests/common/node.rs +++ b/node/tests/common/node.rs @@ -58,6 +58,7 @@ pub async fn validator() -> Validator Date: Tue, 27 Feb 2024 12:12:31 +0100 Subject: [PATCH 2/7] Clean up where we warn about --dev-traffic --- cli/src/commands/start.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cli/src/commands/start.rs b/cli/src/commands/start.rs index 7039744a92..d9d71c0941 100644 --- a/cli/src/commands/start.rs +++ b/cli/src/commands/start.rs @@ -439,10 +439,6 @@ impl Start { if self.dev_num_validators.is_some() { eprintln!("The '--dev-num-validators' flag is ignored because '--dev' is not set"); } - // If the `dev_traffic` flag is set, inform the user that it is ignored. - if self.dev_traffic { - eprintln!("The '--dev-traffic' flag is ignored because '--dev' is not set"); - } Block::from_bytes_le(N::genesis_bytes()) } @@ -531,10 +527,22 @@ impl Start { None => StorageMode::from(self.dev), }; + // Determine whether to generate background traffic in dev mode. + let dev_traffic = match self.dev { + Some(_) => self.dev_traffic, + None => { + // If the `dev_traffic` flag is set, inform the user that it is ignored. + if self.dev_traffic { + eprintln!("The '--dev-traffic' flag is ignored because '--dev' is not set"); + } + false + } + }; + // Initialize the node. let bft_ip = if self.dev.is_some() { self.bft } else { None }; match node_type { - NodeType::Validator => Node::new_validator(self.node, bft_ip, rest_ip, self.rest_rps, account, &trusted_peers, &trusted_validators, genesis, cdn, self.dev_traffic, storage_mode).await, + NodeType::Validator => Node::new_validator(self.node, bft_ip, rest_ip, self.rest_rps, account, &trusted_peers, &trusted_validators, genesis, cdn, dev_traffic, storage_mode).await, NodeType::Prover => Node::new_prover(self.node, account, &trusted_peers, genesis, storage_mode).await, NodeType::Client => Node::new_client(self.node, rest_ip, self.rest_rps, account, &trusted_peers, genesis, cdn, storage_mode).await, } From 71230f240337c0743f62d2e8e870abfb34ab6b9d Mon Sep 17 00:00:00 2001 From: Victor Sint Nicolaas Date: Sun, 3 Mar 2024 19:38:43 +0100 Subject: [PATCH 3/7] Re-order dev_traffic argument --- cli/src/commands/start.rs | 2 +- node/src/node.rs | 4 ++-- node/src/validator/mod.rs | 4 ++-- node/tests/common/node.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/src/commands/start.rs b/cli/src/commands/start.rs index d9d71c0941..ab9b7666ec 100644 --- a/cli/src/commands/start.rs +++ b/cli/src/commands/start.rs @@ -542,7 +542,7 @@ impl Start { // Initialize the node. let bft_ip = if self.dev.is_some() { self.bft } else { None }; match node_type { - NodeType::Validator => Node::new_validator(self.node, bft_ip, rest_ip, self.rest_rps, account, &trusted_peers, &trusted_validators, genesis, cdn, dev_traffic, storage_mode).await, + NodeType::Validator => Node::new_validator(self.node, bft_ip, rest_ip, self.rest_rps, account, &trusted_peers, &trusted_validators, genesis, cdn, storage_mode, dev_traffic).await, NodeType::Prover => Node::new_prover(self.node, account, &trusted_peers, genesis, storage_mode).await, NodeType::Client => Node::new_client(self.node, rest_ip, self.rest_rps, account, &trusted_peers, genesis, cdn, storage_mode).await, } diff --git a/node/src/node.rs b/node/src/node.rs index 908812543c..0203f505e0 100644 --- a/node/src/node.rs +++ b/node/src/node.rs @@ -49,8 +49,8 @@ impl Node { trusted_validators: &[SocketAddr], genesis: Block, cdn: Option, - dev_traffic: bool, storage_mode: StorageMode, + dev_traffic: bool, ) -> Result { Ok(Self::Validator(Arc::new( Validator::new( @@ -63,8 +63,8 @@ impl Node { trusted_validators, genesis, cdn, - dev_traffic, storage_mode, + dev_traffic, ) .await?, ))) diff --git a/node/src/validator/mod.rs b/node/src/validator/mod.rs index 7066e85057..0c3431ddc4 100644 --- a/node/src/validator/mod.rs +++ b/node/src/validator/mod.rs @@ -82,8 +82,8 @@ impl> Validator { trusted_validators: &[SocketAddr], genesis: Block, cdn: Option, - dev_traffic: bool, storage_mode: StorageMode, + dev_traffic: bool, ) -> Result { // Prepare the shutdown flag. let shutdown: Arc = Default::default(); @@ -496,8 +496,8 @@ mod tests { &[], genesis, None, - dev_traffic, storage_mode, + dev_traffic, ) .await .unwrap(); diff --git a/node/tests/common/node.rs b/node/tests/common/node.rs index f62fc7a295..81630cc9da 100644 --- a/node/tests/common/node.rs +++ b/node/tests/common/node.rs @@ -58,8 +58,8 @@ pub async fn validator() -> Validator Date: Sun, 3 Mar 2024 19:58:08 +0100 Subject: [PATCH 4/7] Explicitly set default --dev-traffic value --- cli/src/commands/start.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/commands/start.rs b/cli/src/commands/start.rs index ab9b7666ec..ad2b1a7825 100644 --- a/cli/src/commands/start.rs +++ b/cli/src/commands/start.rs @@ -138,7 +138,7 @@ pub struct Start { #[clap(long)] pub dev_num_validators: Option, /// If developtment mode is enabled, specify whether node 0 should generate traffic to drive the network - #[clap(long = "dev-traffic")] + #[clap(default_value = "false", long = "dev-traffic")] pub dev_traffic: bool, /// Specify the path to a directory containing the ledger #[clap(long = "storage_path")] From 281acb5d355f2ed5166b3217084eaf910afa0b90 Mon Sep 17 00:00:00 2001 From: Victor Sint Nicolaas Date: Sun, 3 Mar 2024 19:58:46 +0100 Subject: [PATCH 5/7] add --dev-traffic usage to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fa2186ca0..2807478563 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ OPTIONS: In the first terminal, start the first validator by running: ``` -cargo run --release -- start --nodisplay --dev 0 --validator +cargo run --release -- start --nodisplay --dev 0 --validator --dev-traffic ``` In the second terminal, start the second validator by running: ``` From de2bd055c2bd8dce1c7b7a634accedb466091cde Mon Sep 17 00:00:00 2001 From: Victor Sint Nicolaas Date: Sat, 9 Mar 2024 10:13:16 +0100 Subject: [PATCH 6/7] Rename dev_traffic to no_dev_txs; ensure tx generation remains the default --- .devnet/start.sh | 2 +- cli/src/commands/start.rs | 18 +++++++++--------- devnet.sh | 4 ++-- node/src/node.rs | 4 ++-- node/src/validator/mod.rs | 12 ++++++------ 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.devnet/start.sh b/.devnet/start.sh index 5214836d71..f61cea6af0 100755 --- a/.devnet/start.sh +++ b/.devnet/start.sh @@ -37,7 +37,7 @@ start_snarkos_in_tmux() { tmux new-session -d -s snarkos-session # Send the snarkOS start command to the tmux session with the NODE_ID - tmux send-keys -t "snarkos-session" "snarkos start --nodisplay --bft 0.0.0.0:5000 --rest 0.0.0.0:3030 --peers $NODE_IP:4130 --validators $NODE_IP:5000 --verbosity $VERBOSITY --dev $NODE_ID --dev-traffic --dev-num-validators $NUM_INSTANCES --validator --metrics" C-m + tmux send-keys -t "snarkos-session" "snarkos start --nodisplay --bft 0.0.0.0:5000 --rest 0.0.0.0:3030 --peers $NODE_IP:4130 --validators $NODE_IP:5000 --verbosity $VERBOSITY --dev $NODE_ID --dev-num-validators $NUM_INSTANCES --validator --metrics" C-m exit # Exit root user EOF diff --git a/cli/src/commands/start.rs b/cli/src/commands/start.rs index ad2b1a7825..e0b149c6bd 100644 --- a/cli/src/commands/start.rs +++ b/cli/src/commands/start.rs @@ -138,8 +138,8 @@ pub struct Start { #[clap(long)] pub dev_num_validators: Option, /// If developtment mode is enabled, specify whether node 0 should generate traffic to drive the network - #[clap(default_value = "false", long = "dev-traffic")] - pub dev_traffic: bool, + #[clap(default_value = "false", long = "no-dev-txs")] + pub no_dev_txs: bool, /// Specify the path to a directory containing the ledger #[clap(long = "storage_path")] pub storage_path: Option, @@ -527,13 +527,13 @@ impl Start { None => StorageMode::from(self.dev), }; - // Determine whether to generate background traffic in dev mode. - let dev_traffic = match self.dev { - Some(_) => self.dev_traffic, + // Determine whether to generate background transactions in dev mode. + let dev_txs = match self.dev { + Some(_) => !self.no_dev_txs, None => { - // If the `dev_traffic` flag is set, inform the user that it is ignored. - if self.dev_traffic { - eprintln!("The '--dev-traffic' flag is ignored because '--dev' is not set"); + // If the `no_dev_txs` flag is set, inform the user that it is ignored. + if self.no_dev_txs { + eprintln!("The '--no-dev-txs' flag is ignored because '--dev' is not set"); } false } @@ -542,7 +542,7 @@ impl Start { // Initialize the node. let bft_ip = if self.dev.is_some() { self.bft } else { None }; match node_type { - NodeType::Validator => Node::new_validator(self.node, bft_ip, rest_ip, self.rest_rps, account, &trusted_peers, &trusted_validators, genesis, cdn, storage_mode, dev_traffic).await, + NodeType::Validator => Node::new_validator(self.node, bft_ip, rest_ip, self.rest_rps, account, &trusted_peers, &trusted_validators, genesis, cdn, storage_mode, dev_txs).await, NodeType::Prover => Node::new_prover(self.node, account, &trusted_peers, genesis, storage_mode).await, NodeType::Client => Node::new_client(self.node, rest_ip, self.rest_rps, account, &trusted_peers, genesis, cdn, storage_mode).await, } diff --git a/devnet.sh b/devnet.sh index f4458625a2..e91627335a 100755 --- a/devnet.sh +++ b/devnet.sh @@ -64,12 +64,12 @@ for validator_index in "${validator_indices[@]}"; do # Send the command to start the validator to the new window and capture output to the log file if [ "$validator_index" -eq 0 ]; then - tmux send-keys -t "devnet:window$validator_index" "snarkos start --nodisplay --dev $validator_index --dev-traffic --dev-num-validators $total_validators --validator --logfile $log_file --metrics" C-m + tmux send-keys -t "devnet:window$validator_index" "snarkos start --nodisplay --dev $validator_index --dev-num-validators $total_validators --validator --logfile $log_file --metrics" C-m else # Create a new window with a unique name window_index=$((validator_index + index_offset)) tmux new-window -t "devnet:$window_index" -n "window$validator_index" - tmux send-keys -t "devnet:window$validator_index" "snarkos start --nodisplay --dev $validator_index --dev-traffic --dev-num-validators $total_validators --validator --logfile $log_file" C-m + tmux send-keys -t "devnet:window$validator_index" "snarkos start --nodisplay --dev $validator_index --dev-num-validators $total_validators --validator --logfile $log_file" C-m fi done diff --git a/node/src/node.rs b/node/src/node.rs index 0203f505e0..d98376d384 100644 --- a/node/src/node.rs +++ b/node/src/node.rs @@ -50,7 +50,7 @@ impl Node { genesis: Block, cdn: Option, storage_mode: StorageMode, - dev_traffic: bool, + dev_txs: bool, ) -> Result { Ok(Self::Validator(Arc::new( Validator::new( @@ -64,7 +64,7 @@ impl Node { genesis, cdn, storage_mode, - dev_traffic, + dev_txs, ) .await?, ))) diff --git a/node/src/validator/mod.rs b/node/src/validator/mod.rs index 0c3431ddc4..23b4f76920 100644 --- a/node/src/validator/mod.rs +++ b/node/src/validator/mod.rs @@ -83,7 +83,7 @@ impl> Validator { genesis: Block, cdn: Option, storage_mode: StorageMode, - dev_traffic: bool, + dev_txs: bool, ) -> Result { // Prepare the shutdown flag. let shutdown: Arc = Default::default(); @@ -140,7 +140,7 @@ impl> Validator { shutdown, }; // Initialize the transaction pool. - node.initialize_transaction_pool(storage_mode, dev_traffic)?; + node.initialize_transaction_pool(storage_mode, dev_txs)?; // Initialize the REST server. if let Some(rest_ip) = rest_ip { @@ -340,7 +340,7 @@ impl> Validator { // } /// Initialize the transaction pool. - fn initialize_transaction_pool(&self, storage_mode: StorageMode, dev_traffic: bool) -> Result<()> { + fn initialize_transaction_pool(&self, storage_mode: StorageMode, dev_txs: bool) -> Result<()> { use snarkvm::console::{ program::{Identifier, Literal, ProgramID, Value}, types::U64, @@ -355,7 +355,7 @@ impl> Validator { // If the node is running in development mode, only generate if you are allowed. StorageMode::Development(id) => { // If the node is not the first node, or if we should not create dev traffic, do not start the loop. - if id != 0 || !dev_traffic { + if id != 0 || !dev_txs { return Ok(()); } } @@ -473,7 +473,7 @@ mod tests { let node = SocketAddr::from_str("0.0.0.0:4130").unwrap(); let rest = SocketAddr::from_str("0.0.0.0:3030").unwrap(); let storage_mode = StorageMode::Development(0); - let dev_traffic = true; + let dev_txs = true; // Initialize an (insecure) fixed RNG. let mut rng = ChaChaRng::seed_from_u64(1234567890u64); @@ -497,7 +497,7 @@ mod tests { genesis, None, storage_mode, - dev_traffic, + dev_txs, ) .await .unwrap(); From 8a0145c356366e2e747d95851bca37311ea7482f Mon Sep 17 00:00:00 2001 From: Victor Sint Nicolaas Date: Sat, 9 Mar 2024 10:13:24 +0100 Subject: [PATCH 7/7] Revert "add --dev-traffic usage to README" This reverts commit 281acb5d355f2ed5166b3217084eaf910afa0b90. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2807478563..6fa2186ca0 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ OPTIONS: In the first terminal, start the first validator by running: ``` -cargo run --release -- start --nodisplay --dev 0 --validator --dev-traffic +cargo run --release -- start --nodisplay --dev 0 --validator ``` In the second terminal, start the second validator by running: ```