@@ -14,6 +14,8 @@ min_height=250
1414num_validators=40
1515
1616# The number of clients that are syncing
17+ # Note: Because the first indexes 0-39 are resevered for validators, the first client will have index 40.
18+ # The script works around this by manually setting the storage, ports, and log files for the clients.
1719num_clients=1
1820
1921# Adjust this to show more/less log messages
@@ -22,8 +24,12 @@ log_filter="info,snarkos_node::client=trace,snarkos_node_sync=trace,snarkos_node
2224max_wait=2400 # Wait for up to 40 minutes
2325poll_interval=1 # Check block heights every second
2426
27+ # shellcheck source=SCRIPTDIR/utils.sh
2528. ./.ci/utils.sh
2629
30+ # Create log directory
31+ init_log_dir
32+
2733# Running sums for variance: use sum and sumsq for unbiased sample variance
2834sum_speed=0
2935sumsq_speed=0
@@ -45,13 +51,13 @@ function sample_sync_speeds() {
4551
4652 # Skip null or empty
4753 if [[ -z " $speed " ]] || [[ " $speed " == " null" ]]; then
48- echo " Invalid speed value $speed "
54+ log " Invalid speed value $speed "
4955 continue
5056 fi
5157
5258 # Validate numeric (allow exponent)
5359 if ! (is_float " $speed " ); then
54- echo " Invalid speed value $speed "
60+ log " Invalid speed value $speed "
5561 continue
5662 fi
5763
@@ -73,24 +79,19 @@ function sample_sync_speeds() {
7379}
7480
7581branch_name=$( git rev-parse --abbrev-ref HEAD)
76- echo " On branch: ${branch_name} "
82+ log " On branch: ${branch_name} "
7783
7884network_name=$( get_network_name $network_id )
79- echo " Using network: $network_name (ID: $network_id )"
85+ log " Using network: $network_name (ID: $network_id )"
8086
8187snapshot_info=$( < info.txt)
82- echo " Snapshot_info: ${snapshot_info} "
83-
84- # Create log directory
85- log_dir=" .logs-$( date +" %Y%m%d%H%M%S" ) "
86- mkdir -p " $log_dir "
88+ log " Snapshot_info: ${snapshot_info} "
8789
8890# Define a trap handler that cleans up all processes on exit.
8991trap stop_nodes EXIT
90- trap child_exit_handler CHLD
9192
9293# Define a trap handler that prints a message when an error occurs.
93- trap ' echo "⛔️ Error in $BASH_SOURCE at line $LINENO: \"$BASH_COMMAND\" failed (exit $?)"' ERR
94+ trap ' log "⛔️ Error in $BASH_SOURCE at line $LINENO: \"$BASH_COMMAND\" failed (exit $?)"' ERR
9495
9596# Shared flags between all nodes
9697common_flags=(
@@ -104,41 +105,47 @@ common_flags=(
104105
105106# The client that has the ledger
106107# (runs on the first two cores)
107- $TASKSET1 snarkos start --dev 0 --client " ${common_flags[@]} " \
108- --logfile=" $log_dir /client-0.log" &
108+ # shellcheck disable=SC2086
109+ run_with_prefix " client-0" $TASKSET1 snarkos start " --dev=$num_validators " --client " ${common_flags[@]} " \
110+ " --logfile=$log_dir /client-0.log" " --storage=.ledger-$network_id -0" \
111+ " --node=127.0.0.1:4130" " --rest=127.0.0.1:3030"
109112PIDS[0]=$!
110113
111114# Spawn the clients that will sync the ledger
112115# (running on the other two cores)
113116for client_index in $( seq 1 " $num_clients " ) ; do
117+ node_index=$(( num_validators + client_index))
114118 prev_port=$(( 4130 + client_index- 1 ))
119+ node_addr=" 127.0.0.1:$(( 4130 + client_index)) "
115120 name=" client-$client_index "
116121
117122 # Ensure there are no old ledger files and the node syncs from scratch
118- snarkos clean " --dev=$client_index " " --network=$network_id " || true
123+ snarkos clean " --dev=$node_index " " --network=$network_id " " --path=.ledger- $network_id - $client_index " || true
119124
120- $TASKSET2 snarkos start " --dev=$client_index " --client \
121- " ${common_flags[@]} " " --peers=127.0.0.1:$prev_port " \
122- " --logfile=$log_dir /$name .log" &
125+ # shellcheck disable=SC2086
126+ run_with_prefix " $name " $TASKSET2 snarkos start " --dev=$node_index " --client \
127+ " ${common_flags[@]} " " --peers=127.0.0.1:$prev_port " " --node=$node_addr " \
128+ " --rest=127.0.0.1:$(( 3030 + client_index)) " \
129+ " --logfile=$log_dir /$name .log" " --storage=.ledger-$network_id -$client_index "
123130 PIDS[client_index]=$!
124131
125132 # Add 1-second delay between starting nodes to avoid hitting rate limits
126133 sleep 1
127134done
128135
129136# Block until nodes are running and connected to each other.
130- wait_for_nodes 0 $(( num_clients+ 1 ))
137+ wait_for_nodes $(( num_clients+ 1 )) 0 " $network_name "
131138
132139# It takes about 30s for nodes to connect. Do not measure this time.
133140SECONDS=0
134141for node_index in $( seq 0 " $num_clients " ) ; do
135- if ! (wait_for_peers " $node_index " $num_clients ); then
142+ if ! (wait_for_peers " $node_index " $num_clients " $network_name " ); then
136143 exit 1
137144 fi
138145done
139146
140147connect_time=$SECONDS
141- echo " ℹ️ Nodes are fully connected (took $connect_time secs). Starting block sync measurement."
148+ log " ℹ️ Nodes are fully connected (took $connect_time secs). Starting block sync measurement."
142149
143150# Ensure the first node actually has the ledger snapshot.
144151# This should succeed instantly in most cases
@@ -149,10 +156,12 @@ while (( SECONDS < 30 )); do
149156 has_blocks=true
150157 break
151158 fi
159+
160+ sleep $poll_interval
152161done
153162
154163if ! $has_blocks ; then
155- echo " Node #0 has not reached the expected height. Maybe the ledger snapshot is corrupted or outdated?"
164+ log " Node #0 has not reached the expected height. Maybe the ledger snapshot is corrupted or outdated?"
156165 exit 1
157166fi
158167
@@ -178,7 +187,7 @@ while (( SECONDS < max_wait )); do
178187 variance=$( echo " scale=8; 0" | bc -l)
179188 fi
180189
181- echo " 🎉 P2P sync benchmark done! Waited $total_wait seconds for $min_height blocks. Throughput was $throughput blocks/s."
190+ log " 🎉 P2P sync benchmark done! Waited $total_wait seconds for $min_height blocks. Throughput was $throughput blocks/s."
182191
183192 # Append data to results file.
184193 printf " { \" name\" : \" p2p-sync\" , \" unit\" : \" blocks/s\" , \" value\" : %.3f, \" extra\" : \" total_wait=%is, target_height=%i, connect_time=%is, %s\" },\n" \
@@ -193,13 +202,9 @@ while (( SECONDS < max_wait )); do
193202 sleep $poll_interval
194203done
195204
196- echo " ❌ Benchmark failed! Clients did not sync within 40 minutes."
205+ log " ❌ Benchmark failed! Clients did not sync within 40 minutes."
197206
198207# Print logs for debugging
199- echo " Last 20 lines of client logs:"
200- for (( client_index = 0 ; client_index < num_clients; client_index++ )) ; do
201- echo " === Client $client_index logs ==="
202- tail -n 20 " $log_dir /client-$client_index .log"
203- done
208+ print_client_logs " $log_dir " " $num_validators " " $num_clients "
204209
205210exit 1
0 commit comments