diff --git a/cli/src/commands/start.rs b/cli/src/commands/start.rs index 8205d35c05..e0b149c6bd 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(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, @@ -524,10 +527,22 @@ impl Start { None => StorageMode::from(self.dev), }; + // Determine whether to generate background transactions in dev mode. + let dev_txs = match self.dev { + Some(_) => !self.no_dev_txs, + None => { + // 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 + } + }; + // 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, 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/node/src/node.rs b/node/src/node.rs index e6435d6ef6..d98376d384 100644 --- a/node/src/node.rs +++ b/node/src/node.rs @@ -50,6 +50,7 @@ impl Node { genesis: Block, cdn: Option, storage_mode: StorageMode, + dev_txs: bool, ) -> Result { Ok(Self::Validator(Arc::new( Validator::new( @@ -63,6 +64,7 @@ impl Node { genesis, cdn, storage_mode, + dev_txs, ) .await?, ))) diff --git a/node/src/validator/mod.rs b/node/src/validator/mod.rs index 7ac250f1a3..23b4f76920 100644 --- a/node/src/validator/mod.rs +++ b/node/src/validator/mod.rs @@ -83,6 +83,7 @@ impl> Validator { genesis: Block, cdn: Option, storage_mode: StorageMode, + dev_txs: bool, ) -> Result { // Prepare the shutdown flag. let shutdown: Arc = Default::default(); @@ -139,7 +140,7 @@ impl> Validator { shutdown, }; // Initialize the transaction pool. - node.initialize_transaction_pool(storage_mode)?; + node.initialize_transaction_pool(storage_mode, dev_txs)?; // 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_txs: 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_txs { 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_txs = true; // Initialize an (insecure) fixed RNG. let mut rng = ChaChaRng::seed_from_u64(1234567890u64); @@ -495,6 +497,7 @@ mod tests { genesis, None, storage_mode, + dev_txs, ) .await .unwrap(); diff --git a/node/tests/common/node.rs b/node/tests/common/node.rs index 80c0262903..81630cc9da 100644 --- a/node/tests/common/node.rs +++ b/node/tests/common/node.rs @@ -59,6 +59,7 @@ pub async fn validator() -> Validator