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

Development experience improvements to devnet.sh #3130

Draft
wants to merge 2 commits into
base: staging
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions devnet.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash

# Check if using a non-installed binary via environment variable (e.g. SNARKOS_BIN=target/release/snarkos)
executable=${SNARKOS_BIN:-"snarkos"}

if [[ $executable != "snarkos" ]]; then
echo "Using custom executable: $executable"
fi

# Read the total number of validators from the user or use a default value of 4
read -p "Enter the total number of validators (default: 4): " total_validators
total_validators=${total_validators:-4}
Expand All @@ -8,14 +15,22 @@ total_validators=${total_validators:-4}
read -p "Enter the total number of clients (default: 2): " total_clients
total_clients=${total_clients:-2}

# Ask the user if they want to run 'cargo install --locked --path .' or use a pre-installed binary
read -p "Do you want to run 'cargo install --locked --path .' to build the binary? (y/n, default: y): " build_binary
build_binary=${build_binary:-y}
# If using the installed executable,
if [[ $executable == "snarkos" ]]; then
# Ask the user if they want to run 'cargo install --locked --path .' or use a pre-installed binary
read -p "Do you want to run 'cargo install --locked --path .' to build the binary? (y/n, default: y): " build_binary
build_binary=${build_binary:-y}
fi

# Ask the user whether to clear the existing ledger history
read -p "Do you want to clear the existing ledger history? (y/n, default: n): " clear_ledger
clear_ledger=${clear_ledger:-n}

# Read the automatic restart delay in seconds
read -p "Enter the automatic validator restart delay in seconds, 0 to disable (default: 0): " restart_delay
restart_delay=${restart_delay:-0}


if [[ $build_binary == "y" ]]; then
# Build the binary using 'cargo install --path .'
cargo install --locked --path . || exit 1
Expand All @@ -28,7 +43,7 @@ if [[ $clear_ledger == "y" ]]; then

for ((index = 0; index < $((total_validators + total_clients)); index++)); do
# Run 'snarkos clean' for each node in the background
snarkos clean --dev $index &
$executable clean --dev $index &

# Store the process ID of the background task
clean_processes+=($!)
Expand Down Expand Up @@ -64,12 +79,22 @@ 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
if [ "$restart_delay" -gt 0 ]; then
tmux send-keys -t "devnet:window$validator_index" "while true; do $executable start --nodisplay --dev $validator_index --dev-num-validators $total_validators --validator --logfile $log_file --metrics; echo '--- Restarting in $restart_delay seconds ---'; sleep $restart_delay; done" C-m
else
tmux send-keys -t "devnet:window$validator_index" "$executable start --nodisplay --dev $validator_index --dev-num-validators $total_validators --validator --logfile $log_file --metrics" C-m
fi

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

if [ "$restart_delay" -gt 0 ]; then
tmux send-keys -t "devnet:window$validator_index" "while true; do $executable start --nodisplay --dev $validator_index --dev-num-validators $total_validators --validator --logfile $log_file; echo '--- Restarting in $restart_delay seconds ---'; sleep $restart_delay; done" C-m
else
tmux send-keys -t "devnet:window$validator_index" "$executable start --nodisplay --dev $validator_index --dev-num-validators $total_validators --validator --logfile $log_file" C-m
fi
fi
done

Expand All @@ -87,7 +112,7 @@ for client_index in "${client_indices[@]}"; do
tmux new-window -t "devnet:$window_index" -n "window-$window_index"

# Send the command to start the validator to the new window and capture output to the log file
tmux send-keys -t "devnet:window-$window_index" "snarkos start --nodisplay --dev $window_index --client --logfile $log_file" C-m
tmux send-keys -t "devnet:window-$window_index" "$executable start --nodisplay --dev $window_index --client --logfile $log_file" C-m
done

# Attach to the tmux session to view and interact with the windows
Expand Down