-
Notifications
You must be signed in to change notification settings - Fork 2
/
devnet.sh
executable file
·81 lines (63 loc) · 3.36 KB
/
devnet.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
total_validators=4
total_clients=2
validators_private_key=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH
# 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}
# Clear the ledger logs for each validator if the user chooses to clear ledger
if [[ $clear_ledger == "y" ]]; then
# Create an array to store background processes
clean_processes=()
for ((validator_index = 0; validator_index < total_validators; validator_index++)); do
# Run 'snarkos clean' for each validator in the background
snarkos clean --dev $validator_index &
# Store the process ID of the background task
clean_processes+=($!)
done
# Wait for all 'snarkos clean' processes to finish
for process_id in "${clean_processes[@]}"; do
wait "$process_id"
done
fi
# Create a timestamp-based directory for log files
log_dir=".logs-$(date +"%Y%m%d%H%M%S")"
mkdir -p "$log_dir"
# Create a new tmux session named "devnet"
tmux new-session -d -s "devnet" -n "window0"
# Get the tmux's base-index for windows
# we have to create all windows with index offseted by this much
index_offset="$(tmux show-option -gv base-index)"
if [ -z "$index_offset" ]; then
index_offset=0
fi
# Generate validator indices from 0 to (total_validators - 1)
validator_indices=($(seq 0 $((total_validators - 1))))
# Loop through the list of validator indices and create a new window for each
for validator_index in "${validator_indices[@]}"; do
# Generate a unique and incrementing log file name based on the validator index
log_file="$log_dir/validator-$validator_index.log"
# 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 --private-key ${validators_private_key} --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 --private-key ${validators_private_key} --logfile $log_file" C-m
fi
done
# Generate client indices from 0 to (total_clients - 1)
client_indices=($(seq 0 $((total_clients - 1))))
# Loop through the list of client indices and create a new window for each
for client_index in "${client_indices[@]}"; do
# Generate a unique and incrementing log file name based on the client index
log_file="$log_dir/client-$client_index.log"
window_index=$((client_index + total_validators + index_offset))
# Create a new window with a unique name
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
done
# Attach to the tmux session to view and interact with the windows
tmux attach-session -t "devnet"