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

[Feature] Add --no-dev-txs flag #3132

Merged
merged 7 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 16 additions & 1 deletion cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u16>,
/// 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<PathBuf>,
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 2 additions & 0 deletions node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl<N: Network> Node<N> {
genesis: Block<N>,
cdn: Option<String>,
storage_mode: StorageMode,
dev_txs: bool,
) -> Result<Self> {
Ok(Self::Validator(Arc::new(
Validator::new(
Expand All @@ -63,6 +64,7 @@ impl<N: Network> Node<N> {
genesis,
cdn,
storage_mode,
dev_txs,
)
.await?,
)))
Expand Down
11 changes: 7 additions & 4 deletions node/src/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl<N: Network, C: ConsensusStorage<N>> Validator<N, C> {
genesis: Block<N>,
cdn: Option<String>,
storage_mode: StorageMode,
dev_txs: bool,
) -> Result<Self> {
// Prepare the shutdown flag.
let shutdown: Arc<AtomicBool> = Default::default();
Expand Down Expand Up @@ -139,7 +140,7 @@ impl<N: Network, C: ConsensusStorage<N>> Validator<N, C> {
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 {
Expand Down Expand Up @@ -339,7 +340,7 @@ impl<N: Network, C: ConsensusStorage<N>> Validator<N, C> {
// }

/// 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,
Expand All @@ -353,8 +354,8 @@ impl<N: Network, C: ConsensusStorage<N>> Validator<N, C> {
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(());
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -495,6 +497,7 @@ mod tests {
genesis,
None,
storage_mode,
dev_txs,
)
.await
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions node/tests/common/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub async fn validator() -> Validator<CurrentNetwork, ConsensusMemory<CurrentNet
sample_genesis_block(), // Should load the current network's genesis block.
None, // No CDN.
StorageMode::Production,
false, // No dev traffic in production mode.
)
.await
.expect("couldn't create validator instance")
Expand Down