-
Notifications
You must be signed in to change notification settings - Fork 36
/
all_nodes_joined.sh
executable file
·60 lines (49 loc) · 1.78 KB
/
all_nodes_joined.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
#!/usr/bin/env bash
if ! command -v rg &> /dev/null
then
echo "ripgrep could not be found and is required"
exit 1
fi
DEFAULT_NODE_COUNT=30
DEFAULT_LOG_DIR="$HOME/.safe/node/local-test-network"
NODE_COUNT="${NODE_COUNT:-$DEFAULT_NODE_COUNT}"
log_dir="${LOG_DIR:-$DEFAULT_LOG_DIR}"
echo "Checking nodes log files to verify all nodes have joined. Logs path: $log_dir"
# -u needed here to search log dirs
nodes_ips=$(rg "connection info:.*" "$log_dir" -g "*.log*" -u | rg "(127.0.0.1:\d{5})" -or '$1')
nodes_ips_count=$(echo "$nodes_ips" | wc -l)
echo "Number of nodes: $nodes_ips_count"
if [[ $nodes_ips_count -ne $NODE_COUNT ]]
then
echo "Unexpected number of joined nodes. Expected $NODE_COUNT, we have $nodes_ips_count:"
echo "$nodes_ips"
exit 100
else
echo "All nodes have joined. Nodes IPs:"
echo "$nodes_ips"
fi
# We'll use the logs from the last node that joined, to obtain the
# list of members in the network knowledge they share with AE messages.
last_node_log_dig="$log_dir/sn-node-$NODE_COUNT"
members=$(rg ".* msg: AntiEntropy \{.* kind: Update \{ members: \{(SectionSigned \{.*\})+ \}.*" -or '$1' "$last_node_log_dig" -g "*.log*" | tail -1 | rg "(127.0.0.1:\d{5})" -or '$1')
echo ""
echo "Checking if nodes in network knowledge match the list of nodes IPs..."
invalid_member_found=false
for m in $members
do
if grep -q "$m" <<< "$nodes_ips"
then
echo "Node $m is a valid member"
else
echo "Node $m in network knowledge was not found in the list of nodes IPs"
invalid_member_found=true
fi
done
echo ""
if $invalid_member_found
then
echo "At least one member in the network knowledge was found invalid"
exit 100
else
echo "All good, members in the network knowledge found in the list of nodes IPs!"
fi