Skip to content

Commit 5cd1d09

Browse files
committed
Better handling of comma-separated CL_NODE
1 parent aede488 commit 5cd1d09

10 files changed

Lines changed: 81 additions & 14 deletions

File tree

default.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ LOG_LEVEL=info
297297
JWT_SECRET=
298298
# Authenticated execution client endpoint. This default uses the execution node container.
299299
EL_NODE=http://execution:8551
300-
# Consensus client address. This could be comma-separated for Lighthouse, Nimbus or Teku VC clients, with failover,
300+
# Consensus client address. This could be a comma-separated list with failover,
301301
# or could just be a remote consensus client URL for "validator only" setups.
302302
CL_NODE=http://consensus:5052
303303
# Used by "ethd keys", adjust this if you have multiple Eth Docker stacks connected to the same Docker bridge network

ethdo/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install
99
adduser \
1010
bash \
1111
jq \
12+
curl \
1213
&& gosu nobody true \
1314
&& apt-get clean \
1415
&& rm -rf /var/lib/apt/lists/*

ethdo/docker-entrypoint.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,20 @@ if [[ "$*" =~ "--offline" ]]; then
8383
chown ethdo:ethdo /app/offline-preparation.json
8484
fi
8585
else
86-
# Get just the first CL_NODE
87-
__args=( "${__args[@]:0:1}" "--connection" "$(cut -d, -f1 <<<"${CL_NODE}")" "${__args[@]:1}" )
86+
nodes=$(echo "${CL_NODE}" | tr ',' ' ')
87+
for node in ${nodes}; do
88+
if curl -s -m 5 -o /dev/null -w "%{http_code}" "${node}" | grep -q "^[23]"; then
89+
node_reachable=1
90+
break
91+
fi
92+
done
93+
94+
if [[ "${node_reachable}" -eq 0 ]]; then
95+
echo "No consensus client node is reachable via any URL in ${CL_NODE}"
96+
exit 1
97+
fi
98+
99+
__args=( "${__args[@]:0:1}" "--connection" "${node}" "${__args[@]:1}" )
88100
fi
89101

90102
set +e

lighthouse-vc-only.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ services:
9393
depends_on:
9494
lighthouse-builder:
9595
condition: service_completed_successfully
96+
environment:
97+
- CL_NODE=${CL_NODE}
9698
volumes:
9799
- lhvalidator-data:/var/lib/lighthouse
98100
- ./.eth/validator_keys:/validator_keys
@@ -103,8 +105,6 @@ services:
103105
- account
104106
- validator
105107
- exit
106-
- --beacon-node
107-
- ${CL_NODE:-http://consensus:5052}
108108
- --datadir
109109
- /var/lib/lighthouse
110110
- --network

lighthouse.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ services:
177177
condition: service_started
178178
lighthouse-builder:
179179
condition: service_completed_successfully
180+
environment:
181+
- CL_NODE=${CL_NODE}
180182
volumes:
181183
- lhvalidator-data:/var/lib/lighthouse
182184
- ./.eth/validator_keys:/validator_keys
@@ -187,8 +189,6 @@ services:
187189
- account
188190
- validator
189191
- exit
190-
- --beacon-node
191-
- http://consensus:5052
192192
- --datadir
193193
- /var/lib/lighthouse
194194
- --network

lighthouse/validator-exit.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,21 @@ if [[ "$(id -u)" -eq 0 ]]; then
99
exec gosu lhvalidator "${BASH_SOURCE[0]}" "$@"
1010
fi
1111

12+
nodes=$(echo "${CL_NODE}" | tr ',' ' ')
13+
for node in ${nodes}; do
14+
if curl -s -m 5 -o /dev/null -w "%{http_code}" "${node}" | grep -q "^[23]"; then
15+
node_reachable=1
16+
break
17+
fi
18+
done
19+
20+
if [[ "${node_reachable}" -eq 0 ]]; then
21+
echo "No consensus client node is reachable via any URL in ${CL_NODE}"
22+
sleep 30
23+
exit 1
24+
fi
25+
26+
# Insert the --beacon-node after the 4th position
27+
set -- "${@:1:4}" "--beacon-node" "${node}" "${@:5}"
28+
1229
exec "$@"

siren.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ services:
2525
- NODE_OPTIONS="--dns-result-order=ipv4first"
2626
<<: *logging
2727
entrypoint:
28-
- docker-entrypoint.sh
28+
- /bin/bash
29+
- -c
30+
command:
31+
- |
32+
export BEACON_URL="$${BEACON_URL%%,*}"
33+
exec /app/docker-assets/docker-entrypoint.sh
2934
labels:
3035
- traefik.enable=true
3136
- traefik.http.routers.$(SIREN_HOST:-siren}.service=${SIREN_HOST:-siren}

teku-vc-only.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ services:
9797
entrypoint:
9898
- /opt/teku/bin/teku
9999
- voluntary-exit
100-
- --beacon-node-api-endpoint=${CL_NODE:-http://consensus:5052}
100+
- --beacon-node-api-endpoints=${CL_NODE:-http://consensus:5052}
101101
- --validator-keys=/var/lib/teku/validator-keys:/var/lib/teku/validator-passwords
102102
- --validator-keys=/var/lib/teku/validator/key-manager/local:/var/lib/teku/validator/key-manager/local-passwords
103103

teku.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ services:
176176
entrypoint:
177177
- /opt/teku/bin/teku
178178
- voluntary-exit
179-
- --beacon-node-api-endpoint=${CL_NODE:-http://consensus:5052}
179+
- --beacon-node-api-endpoints=${CL_NODE:-http://consensus:5052}
180180
- --validator-keys=/var/lib/teku/validator-keys:/var/lib/teku/validator-passwords
181181
- --validator-keys=/var/lib/teku/validator/key-manager/local:/var/lib/teku/validator/key-manager/local-passwords
182182

vc-utils/keymanager.sh

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,35 @@ else
9696

9797
__call_cl_api() {
9898
local exitstatus
99+
local nodes
100+
local node
101+
local node_reachable=0
102+
103+
nodes=$(echo "${CL_NODE}" | tr ',' ' ')
104+
for node in ${nodes}; do
105+
if curl -s -m 5 -o /dev/null -w "%{http_code}" "${node}" | grep -q "^[23]"; then
106+
node_reachable=1
107+
break
108+
fi
109+
done
110+
111+
if [[ "${node_reachable}" -eq 0 ]]; then
112+
echo "No consensus client node is reachable via any URL in ${CL_NODE}"
113+
exit 1
114+
fi
99115

100116
set +e
101117
if [[ -z "${__api_data}" ]]; then
102118
__code=$(curl -m 60 -s --show-error -o /tmp/result.txt -w "%{http_code}" -X "${__http_method}" -H "Accept: application/json" \
103-
"${CL_NODE}"/"${__api_path}")
119+
"${node}"/"${__api_path}")
104120
else
105121
__code=$(curl -m 60 -s --show-error -o /tmp/result.txt -w "%{http_code}" -X "${__http_method}" -H "Accept: application/json" -H "Content-Type: application/json" \
106-
--data "${__api_data}" "${CL_NODE}"/"${__api_path}")
122+
--data "${__api_data}" "${node}"/"${__api_path}")
107123
fi
108124
exitstatus=$?
109125
if [[ "${exitstatus}" -ne 0 ]]; then
110126
echo "Error encountered while trying to call the consensus client REST API via curl."
111-
echo "Please make sure the ${CL_NODE} URL is reachable."
127+
echo "Please make sure the ${node} URL is reachable."
112128
echo "Error code ${exitstatus}"
113129
exit ${exitstatus}
114130
fi
@@ -585,6 +601,9 @@ validator-list() {
585601

586602

587603
validator-count() {
604+
local nodes
605+
local node
606+
local node_reachable=0
588607
local vc_api_container
589608
local vc_service
590609
local vc_api_port
@@ -635,9 +654,22 @@ validator-count() {
635654
fi
636655
fi
637656

657+
nodes=$(echo "${CL_NODE}" | tr ',' ' ')
658+
for node in ${nodes}; do
659+
if curl -s -m 5 -o /dev/null -w "%{http_code}" "${node}" | grep -q "^[23]"; then
660+
node_reachable=1
661+
break
662+
fi
663+
done
664+
665+
if [[ "${node_reachable}" -eq 0 ]]; then
666+
echo "No consensus client node is reachable via any URL in ${CL_NODE}"
667+
exit 1
668+
fi
669+
638670
echo "Querying validator state, this may take a minute"
639671
for __pubkey in $(echo "${vals}" | jq -r '.data[].validating_pubkey'); do
640-
val_state=$(curl -k -m 60 -s --show-error "${CL_NODE}/eth/v1/beacon/states/head/validators/${__pubkey}" | jq -r .data.status)
672+
val_state=$(curl -k -m 60 -s --show-error "${node}/eth/v1/beacon/states/head/validators/${__pubkey}" | jq -r .data.status)
641673
case "${val_state}" in
642674
active_ongoing) ((vals_active++));;
643675
active_exiting) ((vals_exiting++));;

0 commit comments

Comments
 (0)