Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions cluster/scripts/charon-add-validator/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# VARS
SERVICE_OK=0
ATTEMPTS=0
MAX_ATTEMPTS=10
INFO="[ INFO | container-add-validator:]"

# Function that runs the validator addition logic
run_validator_logic() {
echo "${INFO} Add validators for $CHARON_SERVICE_NAME"

# Check if ADD_VALIDATOR is setting in config for current running service
if [[ "$ADD_VALIDATOR_TARGET_CLUSTER" == "$CHARON_SERVICE_NAME" ]]; then
echo "${INFO} Start running charon add-validators command"

charon alpha add-validators \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please override the default relays list (see --p2p-relays) to use just https://4.relay.obol.dev - we keep this as an isolated relay for DKGs to not interfere with the default [0, 1 & 2] which are used for running clusters.

The command uses p2p network under the hood. An isolated relay ensures that add-validators instances will not interfere with charon run instances (those running a live cluster).
Otherwise, relay starts rejecting new connections because theses are the same peers having the same peer ID and they cannot connect twice to the same relay.

Hope this makes sense.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback! Do we need to have option to set any other relays in future? I mean, do I need to add optional not required (by default) field for setting non default (https://4.relay.obol.dev in our case) p2p-relays during add-validators?

--data-dir="$CHARON_ROOT_DIR" \
--num-validators "$ADD_VALIDATOR_NUM_VALIDATORS" \
--withdrawal-addresses="$ADD_VALIDATOR_WITHDRAWAL_ADDRESS" \
--fee-recipient-addresses="$ADD_VALIDATOR_FEE_RECEPIENT_ADDRESS" \
--output-dir=/tmp/.charon

if [[ $? -ne 0 ]]; then
echo "${INFO} charon add-validators failed. Exiting..."
rm -f /import/add_validator
exit 1
fi

echo "${INFO} Stopping charon and lodestar during upgrade processes..."
supervisorctl stop charon lodestar

echo "${INFO} Upgrade .charon directory with backing up previous .charon to /tmp/.charon"
mv "$CHARON_ROOT_DIR" /tmp/.charon.bck && mv /tmp/.charon "$CHARON_ROOT_DIR"

echo "${INFO} Starting charon and lodestar processes..."
supervisorctl start charon lodestar

while [[ "$ATTEMPTS" -lt "$MAX_ATTEMPTS" ]]; do
if supervisorctl status charon | grep -q "RUNNING"; then
SERVICE_OK=1
break
fi

echo "${INFO} charon not ready, waiting 2 seconds... (Attempt ${ATTEMPTS}/${MAX_ATTEMPTS})"
sleep 3
ATTEMPTS=$((ATTEMPTS + 1))
done

if [[ "$SERVICE_OK" -eq 1 ]]; then
echo "${INFO} Validator(s) added, charon is running."
touch "$CHARON_ROOT_DIR/.charon_added_validator_state"
else
echo "${INFO} Validator(s) was not added, restoring .charon state folder to previous one and restart cluster. Check logs for more details"
mv /tmp/.charon.bck "$CHARON_ROOT_DIR"
supervisorctl restart charon lodestar
fi
fi
}

# Watch for the creation of /import/add_validator and trigger logic
inotifywait -m /import -e create |
while read path action file; do
if [ "$file" == "add_validator" ]; then
echo "${INFO} Trigger file detected, executing validator logic..."
run_validator_logic
rm -f /import/add_validator
fi
done
8 changes: 4 additions & 4 deletions cluster/scripts/charon/run-charon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ENR_FILE=${CHARON_ROOT_DIR}/enr
DEFINITION_FILE_URL_FILE=${CHARON_ROOT_DIR}/definition_file_url.txt

CHARON_LOCK_FILE=${CHARON_ROOT_DIR}/cluster-lock.json
CHARON_ADDED_VALIDATOR_STATE_FILE=${CHARON_ROOT_DIR}/.charon_added_validator_state

if [ -n "$DEFINITION_FILE_URL" ]; then
echo "$DEFINITION_FILE_URL" >$DEFINITION_FILE_URL_FILE
Expand Down Expand Up @@ -106,11 +107,10 @@ function check_DKG() {
}

function run_charon() {
if [ "$ENABLE_MEV_BOOST" = true ]; then
CHARON_EXTRA_OPTS="--builder-api $CHARON_EXTRA_OPTS"
if [ "$ENABLE_MEV_BOOST" = true ] || [ -f $CHARON_ADDED_VALIDATOR_STATE_FILE ]; then
CHARON_EXTRA_OPTS="--builder-api --no-verify $CHARON_EXTRA_OPTS"
exec charon run --private-key-file=$ENR_PRIVATE_KEY_FILE --lock-file=$CHARON_LOCK_FILE ${CHARON_EXTRA_OPTS}
fi

exec charon run --private-key-file=$ENR_PRIVATE_KEY_FILE --lock-file=$CHARON_LOCK_FILE ${CHARON_EXTRA_OPTS}
}

########
Expand Down
12 changes: 11 additions & 1 deletion cluster/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ autorestart = true # Should not be required to start automatically
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
stderr_logfile_maxbytes = 0

[program:addvalidator]
command = /usr/local/bin/scripts/charon-add-validator/main.sh
priority = 3
autostart = true
autorestart = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
CHARON_LOG_LEVEL: info
CHARON_LOKI_ADDRESSES: http://loki.dms.dappnode:3100/loki/api/v1/push
CHARON_P2P_RELAYS: https://0.relay.obol.tech,https://1.relay.obol.tech/
CHARON_SERVICE_NAME: cluster-1
CHARON_LOKI_SERVICE: cluster-1
ENABLE_MEV_BOOST: "false"
CHARON_EXTRA_OPTS: ""
Expand Down Expand Up @@ -51,6 +52,7 @@ services:
CHARON_P2P_RELAYS: https://0.relay.obol.tech,https://1.relay.obol.tech/
CHARON_P2P_TCP_ADDRESS: ""
CHARON_P2P_UDP_ADDRESS: ""
CHARON_SERVICE_NAME: cluster-2
CHARON_LOKI_SERVICE: cluster-2
ENABLE_MEV_BOOST: "false"
CHARON_EXTRA_OPTS: ""
Expand Down Expand Up @@ -83,6 +85,7 @@ services:
CHARON_LOG_LEVEL: info
CHARON_LOKI_ADDRESSES: http://loki.dms.dappnode:3100/loki/api/v1/push
CHARON_P2P_RELAYS: https://0.relay.obol.tech,https://1.relay.obol.tech/
CHARON_SERVICE_NAME: cluster-3
CHARON_LOKI_SERVICE: cluster-3
ENABLE_MEV_BOOST: "false"
CHARON_EXTRA_OPTS: ""
Expand Down Expand Up @@ -115,6 +118,7 @@ services:
CHARON_LOG_LEVEL: info
CHARON_LOKI_ADDRESSES: http://loki.dms.dappnode:3100/loki/api/v1/push
CHARON_P2P_RELAYS: https://0.relay.obol.tech,https://1.relay.obol.tech/
CHARON_SERVICE_NAME: cluster-4
CHARON_LOKI_SERVICE: cluster-4
ENABLE_MEV_BOOST: "false"
CHARON_EXTRA_OPTS: ""
Expand Down Expand Up @@ -147,6 +151,7 @@ services:
CHARON_LOG_LEVEL: info
CHARON_LOKI_ADDRESSES: http://loki.dms.dappnode:3100/loki/api/v1/push
CHARON_P2P_RELAYS: https://0.relay.obol.tech,https://1.relay.obol.tech/
CHARON_SERVICE_NAME: cluster-1
Comment thread
serjs marked this conversation as resolved.
Outdated
CHARON_LOKI_SERVICE: cluster-5
ENABLE_MEV_BOOST: "false"
CHARON_EXTRA_OPTS: ""
Expand Down