1+ #! /usr/bin/env bash
2+
3+ #
4+ #
5+ # This is a test script used mostly in the CI pipeline
6+ #
7+ # It will search for all EL clients in a specified kurtosis enclave
8+ # and will check whether their blocks advance in a reasonable amount of time
9+ #
10+ # Usage:
11+ #
12+ # ./kurtosis-check-enclave-block-creation.sh <ENCLAVE_NAME> [TARGET_BLOCK_NUMBER] [NUMBER_OF_NAPS]
13+ #
14+ #
15+
16+ # Just so that we don't repeat ourselves
17+ ENCLAVES_API_URL=http://127.0.0.1:9779/api/enclaves
18+
19+ # We pass the enclave name and the target block as script arguments
20+ ENCLAVE_NAME=$1
21+ if [ -z " $ENCLAVE_NAME " ]; then
22+ echo " Please specify the enclave name as the first parameter"
23+ exit 1
24+ fi
25+
26+ # We default the target block to a good round 50
27+ TARGET_BLOCK=$2
28+ if [ -z " $TARGET_BLOCK " ]; then
29+ TARGET_BLOCK=50
30+ fi
31+
32+ # The number of sleeps the script will take
33+ NUM_NAPS=$3
34+ if [ -z " $NUM_NAPS " ]; then
35+ NUM_NAPS=100
36+ fi
37+
38+ echo " Checking whether EL clients in enclave $ENCLAVE_NAME reach target block $TARGET_BLOCK in reasonable time ($NUM_NAPS of 5s)"
39+
40+ # Get the enclave UUID from the API
41+ #
42+ # The API reponse is a JSON object with UUIDs as keys. To get the UUID we need to find a value
43+ # with a matching "name" property.
44+ #
45+ # The "| values" at the end of the jq transformation will convert null to an empty string
46+ ENCLAVE_ID=$( curl -s $ENCLAVES_API_URL | jq -r ' to_entries | map(select(.value.name == "' $ENCLAVE_NAME ' ")) | .[0].key | values' )
47+
48+ # Make sure we got something
49+ if [ -z " $ENCLAVE_ID " ]; then
50+ echo " No enclave found for enclave $ENCLAVE_NAME "
51+ exit 1
52+ fi
53+
54+ echo " Got enclave UUID: $ENCLAVE_ID "
55+
56+ # Now get all the EL client services
57+ #
58+ # We assume the convention is to name them op-el-xxx
59+ ENCLAVE_SERVICES=$( curl -s $ENCLAVES_API_URL /$ENCLAVE_ID /services)
60+ ENCLAVE_EL_SERVICES=$( echo $ENCLAVE_SERVICES | jq -r ' to_entries | map(select(.key | startswith("op-el-"))) | map(.value)' )
61+
62+ # Now get the EL client names and RPC ports and arrange them into single-line space-delimited strings
63+ #
64+ # This is useful for bash iteration below
65+ ENCLAVE_EL_SERVICE_NAMES=$( echo $ENCLAVE_EL_SERVICES | jq -r ' map(.name) | join(" ")' )
66+ ENCLAVE_EL_SERVICE_RPC_PORTS=$( echo $ENCLAVE_EL_SERVICES | jq -r ' map(.public_ports.rpc.number) | join(" ")' )
67+
68+ # Make sure we got something
69+ if [ -z " $ENCLAVE_EL_SERVICE_NAMES " ]; then
70+ echo " No EL clients found for enclave $ENCLAVE_NAME "
71+ exit 1
72+ fi
73+
74+ echo " Got enclave EL services: $ENCLAVE_EL_SERVICE_NAMES "
75+ echo " Got enclave EL RPC ports: $ENCLAVE_EL_SERVICE_RPC_PORTS "
76+
77+ # Convert the lists into bash arrays
78+ ENCLAVE_EL_SERVICE_NAMES_ARRAY=($ENCLAVE_EL_SERVICE_NAMES )
79+ ENCLAVE_EL_SERVICE_RPC_PORTS_ARRAY=($ENCLAVE_EL_SERVICE_RPC_PORTS )
80+
81+ # Now check that the clients advance
82+ for STEP in $( seq 1 $NUM_NAPS ) ; do
83+ echo " Check $STEP /$NUM_NAPS "
84+
85+ # Iterate over the names/RPC ports arrays
86+ for I in " ${! ENCLAVE_EL_SERVICE_NAMES_ARRAY[@]} " ; do
87+ SERVICE_NAME=${ENCLAVE_EL_SERVICE_NAMES_ARRAY[$I]}
88+ SERVICE_RPC_PORT=${ENCLAVE_EL_SERVICE_RPC_PORTS_ARRAY[$I]}
89+ SERVICE_RPC_URL=" http://127.0.0.1:$SERVICE_RPC_PORT "
90+
91+ BLOCK_NUMBER=$( cast bn --rpc-url $SERVICE_RPC_URL )
92+ echo " Got block for $SERVICE_NAME : $BLOCK_NUMBER "
93+
94+ # Check whether we reached the target block
95+ if [ " $BLOCK_NUMBER " -gt " $TARGET_BLOCK " ]; then
96+ echo " Target block $TARGET_BLOCK reached for $SERVICE_NAME "
97+
98+ # If so, we remove the service from the array
99+ unset ENCLAVE_EL_SERVICE_NAMES_ARRAY[$I ]
100+ unset ENCLAVE_EL_SERVICE_RPC_PORTS_ARRAY[$I ]
101+ fi
102+ done
103+
104+ # Since we used unset, we need to reindex the arrays, we need to remove any gaps left behind
105+ ENCLAVE_EL_SERVICE_NAMES_ARRAY=(" ${ENCLAVE_EL_SERVICE_NAMES_ARRAY[@]} " )
106+ ENCLAVE_EL_SERVICE_RPC_PORTS_ARRAY=(" ${ENCLAVE_EL_SERVICE_RPC_PORTS_ARRAY[@]} " )
107+
108+ # Now we check whether the arrays are empty
109+ #
110+ # This means all target blocks have been reached and we can exit fine
111+ if [ ${# ENCLAVE_EL_SERVICE_NAMES_ARRAY[@]} -eq 0 ]; then
112+ echo " All target blocks have been reached. Exiting."
113+ exit 0
114+ fi
115+
116+ sleep 5
117+ done
118+
119+ echo " Target blocks have not been reached for the following services:"
120+
121+ for I in " ${! ENCLAVE_EL_SERVICE_NAMES_ARRAY[@]} " ; do
122+ SERVICE_NAME=${ENCLAVE_EL_SERVICE_NAMES_ARRAY[$I]}
123+
124+ echo " $SERVICE_NAME "
125+ done
126+
127+ exit 1
0 commit comments