From 50f77a1b85d32f700fedc57c840974c0251e5f65 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 4 Sep 2024 15:04:41 +0530 Subject: [PATCH] Add a service to run a lighthouse beacon node --- .../compose/docker-compose-eth.yml | 43 +++++++++++++++--- stack-orchestrator/config/eth/run-cl.sh | 45 +++++++++++++++++++ stack-orchestrator/config/eth/run-el.sh | 2 + 3 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 stack-orchestrator/config/eth/run-cl.sh diff --git a/stack-orchestrator/compose/docker-compose-eth.yml b/stack-orchestrator/compose/docker-compose-eth.yml index 5f3360d..83db8aa 100644 --- a/stack-orchestrator/compose/docker-compose-eth.yml +++ b/stack-orchestrator/compose/docker-compose-eth.yml @@ -2,21 +2,21 @@ services: eth-geth: restart: on-failure hostname: eth-geth + image: ethereum/client-go:alltools-v1.14.8 + env_file: + - ../config/eth/params.env environment: CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} CERC_NETWORK: ${CERC_NETWORK:-sepolia} CERC_ALLOW_UNPROTECTED_TXS: ${CERC_ALLOW_UNPROTECTED_TXS:-false} CERC_ETH_DATADIR: ${CERC_ETH_DATADIR:-/root/ethdata} CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY:-3} - env_file: - - ../config/eth/params.env - image: ethereum/client-go:alltools-v1.14.8 entrypoint: ["sh", "-c"] command: | - "/scripts/run-el.sh" + "/root/scripts/run-el.sh" volumes: - - eth_geth_data:/root/ethdata - - ../config/eth/run-el.sh:/scripts/run-el.sh + - eth_geth_data:/root/.ethereum + - ../config/eth/run-el.sh:/root/scripts/run-el.sh healthcheck: test: ["CMD", "nc", "-v", "localhost", "8545"] interval: 30s @@ -28,5 +28,36 @@ services: - "8546" - "6060" + eth-lighthouse: + restart: on-failure + hostname: eth-lighthouse + image: sigp/lighthouse:v5.3.0 + depends_on: + eth-geth: + condition: service_healthy + env_file: + - ../config/eth/params.env + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + ETH_ENDPOINT: "http://eth-geth:8545" + EXECUTION_ENDPOINT: "http://eth-geth:8551" + CERC_NETWORK: ${CERC_NETWORK:-sepolia} + CERC_LIGHTHOUSE_DATADIR: ${CERC_LIGHTHOUSE_DATADIR:-/root/.lighthouse} + CERC_CHECKPOINT_SYNC_URL: ${CERC_CHECKPOINT_SYNC_URL} + CERC_DEBUG_LEVEL: ${CERC_DEBUG_LEVEL:-info} + command: bash /root/scripts/run-cl.sh + volumes: + - eth_lighthouse_data:/root/.lighthouse + - ../config/eth/run-cl.sh:/root/scripts/run-cl.sh + healthcheck: + test: ["CMD", "wget", "--tries=1", "--connect-timeout=1", "--quiet", "-O", "-", "http://localhost:8001/eth/v2/beacon/blocks/head"] + interval: 30s + timeout: 10s + retries: 10 + start_period: 30s + ports: + - "8001" + volumes: eth_geth_data: + eth_lighthouse_data: diff --git a/stack-orchestrator/config/eth/run-cl.sh b/stack-orchestrator/config/eth/run-cl.sh new file mode 100644 index 0000000..3e7e2d7 --- /dev/null +++ b/stack-orchestrator/config/eth/run-cl.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +set -e +set -o pipefail +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +echo "Using the following env:" +echo "CERC_NETWORK: ${CERC_NETWORK}" +echo "CERC_LIGHTHOUSE_DATADIR: ${CERC_LIGHTHOUSE_DATADIR}" +echo "CERC_CHECKPOINT_SYNC_URL: ${CERC_CHECKPOINT_SYNC_URL}" +echo "CERC_DEBUG_LEVEL: ${CERC_DEBUG_LEVEL}" +echo "ETH_ENDPOINT: ${ETH_ENDPOINT}" +echo "EXECUTION_ENDPOINT: ${EXECUTION_ENDPOINT}" + +# See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script +cleanup() { + echo "Signal received, cleaning up..." + kill $(jobs -p) + + wait + echo "Done" +} +trap 'cleanup' SIGINT SIGTERM + +jwtsecret_file_path=/opt/jwtsecret +echo -n "$JWT" > $jwtsecret_file_path + +http_port=8001 +lighthouse bn \ + --network $CERC_NETWORK \ + --datadir $CERC_LIGHTHOUSE_DATADIR/$CERC_NETWORK \ + --execution-endpoint $EXECUTION_ENDPOINT \ + --execution-jwt $jwtsecret_file_path \ + --checkpoint-sync-url $CERC_CHECKPOINT_SYNC_URL \ + --disable-deposit-contract-sync \ + --debug-level $CERC_DEBUG_LEVEL \ + --http \ + --http-address 0.0.0.0 \ + --http-port $http_port \ + 2>&1 | tee /var/log/lighthouse_bn.log & + +beacon_pid=$! +wait $beacon_pid diff --git a/stack-orchestrator/config/eth/run-el.sh b/stack-orchestrator/config/eth/run-el.sh index ba12f35..ea7d5e2 100755 --- a/stack-orchestrator/config/eth/run-el.sh +++ b/stack-orchestrator/config/eth/run-el.sh @@ -1,5 +1,6 @@ #!/bin/sh +set -e if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi @@ -8,6 +9,7 @@ echo "Using the following env:" echo "CERC_NETWORK: ${CERC_NETWORK}" echo "CERC_ALLOW_UNPROTECTED_TXS: ${CERC_ALLOW_UNPROTECTED_TXS}" echo "CERC_ETH_DATADIR: ${CERC_ETH_DATADIR}" +echo "CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY}" # See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script cleanup() {