Skip to content

Commit 677d2c1

Browse files
chore: Add a script that checks block progression for test enclaves (#388)
Based on [my PR to `op-reth`](ethereum-optimism/op-reth#57) **Description** - Adds a smoke test that checks the block progression of the network under test - Adds a helper script that dumps logs formatted for github UI (using the collapsible groups) - Always stores log artifacts - there seem to be cases when the pipeline is green yet something somewhere did not go well (currently investigating two issues where this happened) - Encapsulate setup action into its own composite action not to duplicate code all over the place. Unfortunately, since the workflow needs to have the repo code in order to run this action, we cannot smack the checkout there as well
1 parent 9f7aaa2 commit 677d2c1

File tree

6 files changed

+234
-17
lines changed

6 files changed

+234
-17
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
#
5+
# This is a log script used mostly in the CI pipeline
6+
#
7+
# It will search for all OP clients in a specified kurtosis enclave
8+
# and will dump their logs in a CI-friendly manner
9+
#
10+
# Usage:
11+
#
12+
# ./kurtosis-dump-logs.sh <ENCLAVE_NAME>
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+
echo "Dumping logs of the OP services for enclave $ENCLAVE_NAME"
27+
28+
# Get the enclave UUID from the API
29+
#
30+
# The | values at the end of the j1 transformation will convert null to an empty string
31+
ENCLAVE_ID=$(curl -s $ENCLAVES_API_URL | jq -r 'to_entries | map(select(.value.name == "'$ENCLAVE_NAME'")) | .[0].key | values')
32+
33+
# Make sure we got something
34+
if [ -z "$ENCLAVE_ID" ]; then
35+
echo "No enclave found for enclave $ENCLAVE_NAME"
36+
exit 1
37+
fi
38+
39+
echo "Got enclave UUID: $ENCLAVE_ID"
40+
41+
# Now get all the service names
42+
ENCLAVE_SERVICES=$(curl -s $ENCLAVES_API_URL/$ENCLAVE_ID/services)
43+
ENCLAVE_SERVICES_NAMES=$(echo $ENCLAVE_SERVICES | jq -r 'keys_unsorted | join(" ")')
44+
45+
# Make sure we got something
46+
if [ -z "$ENCLAVE_SERVICES_NAMES" ]; then
47+
echo "No clients found for enclave $ENCLAVE_NAME"
48+
exit 0
49+
fi
50+
51+
echo "Got enclave services: $ENCLAVE_SERVICES_NAMES"
52+
53+
# Convert the list into a bash array
54+
ENCLAVE_SERVICE_NAMES_ARRAY=($ENCLAVE_SERVICES_NAMES)
55+
56+
# Iterate over the names/RPC ports arrays
57+
for SERVICE_NAME in "${ENCLAVE_SERVICE_NAMES_ARRAY[@]}"; do
58+
# We use the github actions grouping to get a nicer output
59+
echo "::group::$SERVICE_NAME"
60+
kurtosis service logs -a $ENCLAVE_NAME $SERVICE_NAME
61+
echo "::endgroup::"
62+
done

.github/workflows/actions/run-kurtosis-docker/action.yaml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,29 @@ runs:
1515
shell: bash
1616
run: kurtosis run . ${{ inputs.args-file && format('--args-file={0}', inputs.args-file) || '' }} --enclave=${{ inputs.enclave }} --verbosity detailed
1717

18-
- name: Dump kurtosis logs
18+
- name: Assert that clients advance
1919
shell: bash
20-
if: ${{ failure() }}
20+
run: ./.github/scripts/kurtosis-check-block-progression.sh ${{ inputs.enclave }}
21+
22+
- name: Dump kurtosis logs to console
23+
shell: bash
24+
if: ${{ always() }}
25+
run: ./.github/scripts/kurtosis-dump-logs.sh ${{ inputs.enclave }}
26+
27+
- name: Dump kurtosis logs to artifacts
28+
shell: bash
29+
if: ${{ always() }}
2130
run: kurtosis dump ./.kurtosis-dump
2231

32+
- name: Create log artifact key
33+
if: ${{ always() }}
34+
shell: bash
35+
id: create-artifact-key
36+
run: echo "artifact-key=$(echo "${{ inputs.args-file || 'no-args' }}" | tr '/.' '__')" >> $GITHUB_OUTPUT
37+
2338
- name: Store kurtosis logs
24-
if: ${{ failure() }}
39+
if: ${{ always() }}
2540
uses: actions/upload-artifact@v4
2641
with:
27-
name: kurtosis-logs
42+
name: kurtosis-dump-${{ inputs.enclave }}-${{ steps.create-artifact-key.outputs.artifact-key }}
2843
path: ./.kurtosis-dump/enclaves/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Setup environment
2+
description: Sets up the environment for CI pipelines
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Install mise
8+
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
9+
10+
- name: Install Foundry
11+
uses: foundry-rs/foundry-toolchain@82dee4ba654bd2146511f85f0d013af94670c4de # v1.4.0
12+
with:
13+
version: v1.3.2

.github/workflows/nightly.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626
steps:
2727
- name: Checkout Repository
2828
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29-
30-
- name: Install mise
31-
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
29+
30+
- name: Setup environment
31+
uses: ./.github/workflows/actions/setup-environment
3232

3333
- name: Run Starlark
3434
run: kurtosis run ${{ github.workspace }} --verbosity detailed --args-file ${{ matrix.file_name }} || echo "TEST_FAILED=true" >> $GITHUB_ENV
@@ -60,8 +60,8 @@ jobs:
6060
- name: Checkout Repository
6161
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6262

63-
- name: Install mise
64-
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
63+
- name: Setup environment
64+
uses: ./.github/workflows/actions/setup-environment
6565

6666
- name: Deploy L1
6767
run: kurtosis run --enclave test --args-file ./.github/tests/external-l1/ethereum.yaml github.com/ethpandaops/ethereum-package

.github/workflows/per-pr.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
- name: Checkout Repository
2222
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2323

24-
- name: Install mise
25-
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
24+
- name: Setup environment
25+
uses: ./.github/workflows/actions/setup-environment
2626

2727
- name: Run kurtosis
2828
uses: ./.github/workflows/actions/run-kurtosis-docker
@@ -37,8 +37,8 @@ jobs:
3737
- name: Checkout Repository
3838
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3939

40-
- name: Install mise
41-
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
40+
- name: Setup environment
41+
uses: ./.github/workflows/actions/setup-environment
4242

4343
- name: Run kurtosis
4444
uses: ./.github/workflows/actions/run-kurtosis-docker
@@ -55,8 +55,8 @@ jobs:
5555
- name: Checkout Repository
5656
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5757

58-
- name: Install mise
59-
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
58+
- name: Setup environment
59+
uses: ./.github/workflows/actions/setup-environment
6060

6161
- name: Run lint
6262
run: just lint
@@ -68,8 +68,8 @@ jobs:
6868
- name: Checkout Repository
6969
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
7070

71-
- name: Install mise
72-
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
71+
- name: Setup environment
72+
uses: ./.github/workflows/actions/setup-environment
7373

7474
- name: Run unit tests
7575
run: just test

0 commit comments

Comments
 (0)