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 2 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
2 changes: 1 addition & 1 deletion .devnet/start.sh
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion cli/src/commands/start.rs
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(long = "dev-traffic")]
pub dev_traffic: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true by default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is false by default, made it explicit: d3cc72b

I realise this may lead to issues in the community because nodes require this flag to auto-advance blocks. But I think it is the right default for testing and the updated README 281acb5, devnet.sh should be sufficient guidance.

Let me know if you prefer an alternative dev-no-traffic command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be true by default.

Can use no-dev-txs as the flag name. Traffic implies network traffic among clients/validators.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// 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 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, 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,
}
Expand Down
4 changes: 2 additions & 2 deletions devnet.sh
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions node/src/node.rs
Expand Up @@ -49,6 +49,7 @@ impl<N: Network> Node<N> {
trusted_validators: &[SocketAddr],
genesis: Block<N>,
cdn: Option<String>,
dev_traffic: bool,
storage_mode: StorageMode,
) -> Result<Self> {
Ok(Self::Validator(Arc::new(
Expand All @@ -62,6 +63,7 @@ impl<N: Network> Node<N> {
trusted_validators,
genesis,
cdn,
dev_traffic,
storage_mode,
)
.await?,
Expand Down
11 changes: 7 additions & 4 deletions node/src/validator/mod.rs
Expand Up @@ -82,6 +82,7 @@ impl<N: Network, C: ConsensusStorage<N>> Validator<N, C> {
trusted_validators: &[SocketAddr],
genesis: Block<N>,
cdn: Option<String>,
dev_traffic: bool,
storage_mode: StorageMode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you swap the order between storage_mode and dev_traffic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

71230f2 Sure, though note cargo fmt then makes the comment indentation different:
Screenshot 2024-03-03 at 19 37 36

) -> Result<Self> {
// Prepare the shutdown flag.
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_traffic)?;

// 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_traffic: 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_traffic {
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_traffic = true;

// Initialize an (insecure) fixed RNG.
let mut rng = ChaChaRng::seed_from_u64(1234567890u64);
Expand All @@ -494,6 +496,7 @@ mod tests {
&[],
genesis,
None,
dev_traffic,
storage_mode,
)
.await
Expand Down
1 change: 1 addition & 0 deletions node/tests/common/node.rs
Expand Up @@ -58,6 +58,7 @@ pub async fn validator() -> Validator<CurrentNetwork, ConsensusMemory<CurrentNet
&[],
sample_genesis_block(), // Should load the current network's genesis block.
None, // No CDN.
false, // No dev traffic in production mode.
StorageMode::Production,
)
.await
Expand Down