From 3b6c958f751262c17ad6370c7f3828854ff2b8f8 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 4 Sep 2024 12:10:57 +0530 Subject: [PATCH 1/6] Add a service to run a geth node --- README.md | 1 + .../compose/docker-compose-eth.yml | 32 +++++++++ stack-orchestrator/config/eth/params.env | 3 + stack-orchestrator/config/eth/run-el.sh | 68 +++++++++++++++++++ stack-orchestrator/stacks/eth/README.md | 56 +++++++++++++++ stack-orchestrator/stacks/eth/stack.yml | 7 ++ 6 files changed, 167 insertions(+) create mode 100644 stack-orchestrator/compose/docker-compose-eth.yml create mode 100644 stack-orchestrator/config/eth/params.env create mode 100755 stack-orchestrator/config/eth/run-el.sh create mode 100644 stack-orchestrator/stacks/eth/README.md create mode 100644 stack-orchestrator/stacks/eth/stack.yml diff --git a/README.md b/README.md index e69de29..d5f8e33 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +# eth-stack diff --git a/stack-orchestrator/compose/docker-compose-eth.yml b/stack-orchestrator/compose/docker-compose-eth.yml new file mode 100644 index 0000000..5f3360d --- /dev/null +++ b/stack-orchestrator/compose/docker-compose-eth.yml @@ -0,0 +1,32 @@ +services: + eth-geth: + restart: on-failure + hostname: eth-geth + 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" + volumes: + - eth_geth_data:/root/ethdata + - ../config/eth/run-el.sh:/scripts/run-el.sh + healthcheck: + test: ["CMD", "nc", "-v", "localhost", "8545"] + interval: 30s + timeout: 10s + retries: 10 + start_period: 3s + ports: + - "8545" + - "8546" + - "6060" + +volumes: + eth_geth_data: diff --git a/stack-orchestrator/config/eth/params.env b/stack-orchestrator/config/eth/params.env new file mode 100644 index 0000000..d8db9d1 --- /dev/null +++ b/stack-orchestrator/config/eth/params.env @@ -0,0 +1,3 @@ +# JWT shared by geth and lighthouse for authentication +# TODO: Generate using openssl +JWT="0x6cdcac3501046a08e186730dd8bd136cfaf0fdc1fc955f6e15ad3068c0ff2af0" diff --git a/stack-orchestrator/config/eth/run-el.sh b/stack-orchestrator/config/eth/run-el.sh new file mode 100755 index 0000000..ba12f35 --- /dev/null +++ b/stack-orchestrator/config/eth/run-el.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +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}" + +# See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script +cleanup() { + echo "Signal received, cleaning up..." + + # Kill the child process first (CERC_REMOTE_DEBUG=true uses dlv which starts geth as a child process) + pkill -P ${geth_pid} + sleep 2 + kill $(jobs -p) + + wait + echo "Done" +} +trap 'cleanup' SIGINT SIGTERM + +# Store the JWT secret +jwtsecret_file_path=/opt/jwtsecret +echo -n "$JWT" > $jwtsecret_file_path + +NETWORK_OPT="" +if [ "$CERC_NETWORK" = "sepolia" ] || [ "$CERC_NETWORK" = "holesky" ] || [ "$CERC_NETWORK" = "mainnet" ]; then + NETWORK_OPT="--${CERC_NETWORK}" +else + NETWORK_OPT="--networkid ${CERC_NETWORK}" +fi + +OTHER_OPTS="" +if [ "$CERC_ALLOW_UNPROTECTED_TXS" == "true" ]; then + # Allow for unprotected (non EIP155) txs to be submitted via RPC + OTHER_OPTS="--rpc.allow-unprotected-txs" +fi + +geth \ + ${NETWORK_OPT} \ + --datadir="${CERC_ETH_DATADIR}" \ + --authrpc.addr="0.0.0.0" \ + --authrpc.vhosts="*" \ + --authrpc.jwtsecret="$jwtsecret_file_path" \ + --http \ + --http.addr="0.0.0.0" \ + --http.vhosts="*" \ + --http.api="${CERC_GETH_HTTP_APIS:-eth,web3,net,admin,personal,debug}" \ + --http.corsdomain="*" \ + --ws \ + --ws.addr="0.0.0.0" \ + --ws.origins="*" \ + --ws.api="${CERC_GETH_WS_APIS:-eth,web3,net,admin,personal,debug}" \ + --state.scheme hash \ + --gcmode archive \ + --syncmode=full \ + --metrics \ + --metrics.addr="0.0.0.0" \ + --verbosity=${CERC_GETH_VERBOSITY} \ + ${OTHER_OPTS} \ + & + +geth_pid=$! +wait $geth_pid diff --git a/stack-orchestrator/stacks/eth/README.md b/stack-orchestrator/stacks/eth/README.md new file mode 100644 index 0000000..f7285f8 --- /dev/null +++ b/stack-orchestrator/stacks/eth/README.md @@ -0,0 +1,56 @@ +# eth + +## Setup + +* Clone the stack repo: + + ```bash + laconic-so fetch-stack git.vdb.to/cerc-io/eth-stack + ``` + +## Create a deployment + +* First, create a spec file for the deployment, which will map the stack's ports and volumes to the host: + + ```bash + laconic-so --stack ~/cerc/eth-stack/stack-orchestrator/stacks/eth deploy init --output eth-spec.yml + ``` + +* Once you've made any needed changes to the spec file, create a deployment from it: + + ```bash + laconic-so --stack ~/cerc/eth-stack/stack-orchestrator/stacks/eth deploy create --spec-file eth-spec.yml --deployment-dir eth-deployment + ``` + +* Inside the `eth-deployment` deployment directory, open `config.env` file and set following env variables: + + ```bash + # Optional + # Allow unprotected txs + CERC_ALLOW_UNPROTECTED_TXS=true + ``` + +## Start + +* Start the deployment: + + ```bash + laconic-so deployment --dir eth-deployment start + ``` + +## Clean up + +* To stop all services running in the background, while preserving chain data: + + ```bash + laconic-so deployment --dir eth-deployment stop + ``` + +* To stop all services and also delete chain data: + + ```bash + laconic-so deployment --dir eth-deployment stop --delete-volumes + + # Remove the deployment dir + sudo rm -rf eth-deployment + ``` diff --git a/stack-orchestrator/stacks/eth/stack.yml b/stack-orchestrator/stacks/eth/stack.yml new file mode 100644 index 0000000..b62c097 --- /dev/null +++ b/stack-orchestrator/stacks/eth/stack.yml @@ -0,0 +1,7 @@ +version: "1.0" +name: eth +description: "ETH stack" +repos: +containers: +pods: + - eth -- 2.45.2 From 50f77a1b85d32f700fedc57c840974c0251e5f65 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 4 Sep 2024 15:04:41 +0530 Subject: [PATCH 2/6] 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() { -- 2.45.2 From 6a5bbe1cd8b5e778437c55ae6db9fa410c1d4e98 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 4 Sep 2024 16:08:04 +0530 Subject: [PATCH 3/6] Generate required JWT secret using openssl --- README.md | 4 ++++ stack-orchestrator/compose/docker-compose-eth.yml | 13 +++++-------- stack-orchestrator/config/eth/params.env | 3 --- stack-orchestrator/config/eth/run-cl.sh | 7 +++++-- stack-orchestrator/config/eth/run-el.sh | 12 +++++++++--- 5 files changed, 23 insertions(+), 16 deletions(-) delete mode 100644 stack-orchestrator/config/eth/params.env diff --git a/README.md b/README.md index d5f8e33..bbcd435 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ # eth-stack + +Stack to run a Ethereum node (geth + lighthouse beacon node) + +* [Stack documentation](./stack-orchestrator/stacks/eth/README.md) diff --git a/stack-orchestrator/compose/docker-compose-eth.yml b/stack-orchestrator/compose/docker-compose-eth.yml index 83db8aa..0f5f135 100644 --- a/stack-orchestrator/compose/docker-compose-eth.yml +++ b/stack-orchestrator/compose/docker-compose-eth.yml @@ -3,19 +3,18 @@ services: 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_ETH_DATADIR: ${CERC_ETH_DATADIR:-/root/.ethereum} CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY:-3} entrypoint: ["sh", "-c"] command: | "/root/scripts/run-el.sh" volumes: - eth_geth_data:/root/.ethereum + - eth_secrets:/root/secrets - ../config/eth/run-el.sh:/root/scripts/run-el.sh healthcheck: test: ["CMD", "nc", "-v", "localhost", "8545"] @@ -32,11 +31,6 @@ services: 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" @@ -48,8 +42,10 @@ services: command: bash /root/scripts/run-cl.sh volumes: - eth_lighthouse_data:/root/.lighthouse + - eth_secrets:/root/secrets - ../config/eth/run-cl.sh:/root/scripts/run-cl.sh healthcheck: + # TODO: Update test: ["CMD", "wget", "--tries=1", "--connect-timeout=1", "--quiet", "-O", "-", "http://localhost:8001/eth/v2/beacon/blocks/head"] interval: 30s timeout: 10s @@ -61,3 +57,4 @@ services: volumes: eth_geth_data: eth_lighthouse_data: + eth_secrets: diff --git a/stack-orchestrator/config/eth/params.env b/stack-orchestrator/config/eth/params.env deleted file mode 100644 index d8db9d1..0000000 --- a/stack-orchestrator/config/eth/params.env +++ /dev/null @@ -1,3 +0,0 @@ -# JWT shared by geth and lighthouse for authentication -# TODO: Generate using openssl -JWT="0x6cdcac3501046a08e186730dd8bd136cfaf0fdc1fc955f6e15ad3068c0ff2af0" diff --git a/stack-orchestrator/config/eth/run-cl.sh b/stack-orchestrator/config/eth/run-cl.sh index 3e7e2d7..294235b 100644 --- a/stack-orchestrator/config/eth/run-cl.sh +++ b/stack-orchestrator/config/eth/run-cl.sh @@ -24,8 +24,11 @@ cleanup() { } trap 'cleanup' SIGINT SIGTERM -jwtsecret_file_path=/opt/jwtsecret -echo -n "$JWT" > $jwtsecret_file_path +# Create a JWT secret at shared path +jwtsecret_file_path=/root/secrets/jwtsecret +openssl rand -hex 32 | tr -d "\n" > $jwtsecret_file_path + +echo "Using the JWT secret generated at $jwtsecret_file_path" http_port=8001 lighthouse bn \ diff --git a/stack-orchestrator/config/eth/run-el.sh b/stack-orchestrator/config/eth/run-el.sh index ea7d5e2..9744ef4 100755 --- a/stack-orchestrator/config/eth/run-el.sh +++ b/stack-orchestrator/config/eth/run-el.sh @@ -25,9 +25,15 @@ cleanup() { } trap 'cleanup' SIGINT SIGTERM -# Store the JWT secret -jwtsecret_file_path=/opt/jwtsecret -echo -n "$JWT" > $jwtsecret_file_path +# Wait for the JWT secret to be generated +jwtsecret_file_path=/root/secrets/jwtsecret +retry_interval=3 +while [ ! -f "$jwtsecret_file_path" ]; do + echo "JWT secret not found, retrying after ${retry_interval}s..." + sleep $retry_interval +done + +echo "JWT secret found at $jwtsecret_file_path" NETWORK_OPT="" if [ "$CERC_NETWORK" = "sepolia" ] || [ "$CERC_NETWORK" = "holesky" ] || [ "$CERC_NETWORK" = "mainnet" ]; then -- 2.45.2 From 728b789aba9ed32f4ed22a0d1c37e70f370d2632 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 4 Sep 2024 16:52:50 +0530 Subject: [PATCH 4/6] Update instructions --- .../compose/docker-compose-eth.yml | 11 +--- stack-orchestrator/config/eth/run-cl.sh | 13 ++-- stack-orchestrator/config/eth/run-el.sh | 4 +- stack-orchestrator/stacks/eth/README.md | 66 +++++++++++++++++-- 4 files changed, 73 insertions(+), 21 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-eth.yml b/stack-orchestrator/compose/docker-compose-eth.yml index 0f5f135..8fc8ead 100644 --- a/stack-orchestrator/compose/docker-compose-eth.yml +++ b/stack-orchestrator/compose/docker-compose-eth.yml @@ -5,9 +5,9 @@ services: image: ethereum/client-go:alltools-v1.14.8 environment: CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + ETH_DATADIR: "/root/.ethereum" CERC_NETWORK: ${CERC_NETWORK:-sepolia} CERC_ALLOW_UNPROTECTED_TXS: ${CERC_ALLOW_UNPROTECTED_TXS:-false} - CERC_ETH_DATADIR: ${CERC_ETH_DATADIR:-/root/.ethereum} CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY:-3} entrypoint: ["sh", "-c"] command: | @@ -35,8 +35,8 @@ services: CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} ETH_ENDPOINT: "http://eth-geth:8545" EXECUTION_ENDPOINT: "http://eth-geth:8551" + LIGHTHOUSE_DATADIR: "/root/.lighthouse" 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 @@ -44,13 +44,6 @@ services: - eth_lighthouse_data:/root/.lighthouse - eth_secrets:/root/secrets - ../config/eth/run-cl.sh:/root/scripts/run-cl.sh - healthcheck: - # TODO: Update - 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" diff --git a/stack-orchestrator/config/eth/run-cl.sh b/stack-orchestrator/config/eth/run-cl.sh index 294235b..fbf9974 100644 --- a/stack-orchestrator/config/eth/run-cl.sh +++ b/stack-orchestrator/config/eth/run-cl.sh @@ -8,9 +8,9 @@ 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 "LIGHTHOUSE_DATADIR: ${LIGHTHOUSE_DATADIR}" echo "ETH_ENDPOINT: ${ETH_ENDPOINT}" echo "EXECUTION_ENDPOINT: ${EXECUTION_ENDPOINT}" @@ -24,16 +24,17 @@ cleanup() { } trap 'cleanup' SIGINT SIGTERM -# Create a JWT secret at shared path +# Create a JWT secret at shared path if not found jwtsecret_file_path=/root/secrets/jwtsecret -openssl rand -hex 32 | tr -d "\n" > $jwtsecret_file_path - -echo "Using the JWT secret generated at $jwtsecret_file_path" +if [ ! -f "$jwtsecret_file_path" ]; then + openssl rand -hex 32 | tr -d "\n" > $jwtsecret_file_path + echo "Generated JWT secret at $jwtsecret_file_path" +fi http_port=8001 lighthouse bn \ --network $CERC_NETWORK \ - --datadir $CERC_LIGHTHOUSE_DATADIR/$CERC_NETWORK \ + --datadir $LIGHTHOUSE_DATADIR/$CERC_NETWORK \ --execution-endpoint $EXECUTION_ENDPOINT \ --execution-jwt $jwtsecret_file_path \ --checkpoint-sync-url $CERC_CHECKPOINT_SYNC_URL \ diff --git a/stack-orchestrator/config/eth/run-el.sh b/stack-orchestrator/config/eth/run-el.sh index 9744ef4..bcd030b 100755 --- a/stack-orchestrator/config/eth/run-el.sh +++ b/stack-orchestrator/config/eth/run-el.sh @@ -8,8 +8,8 @@ fi 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}" +echo "ETH_DATADIR: ${ETH_DATADIR}" # See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script cleanup() { @@ -50,7 +50,7 @@ fi geth \ ${NETWORK_OPT} \ - --datadir="${CERC_ETH_DATADIR}" \ + --datadir="${ETH_DATADIR}" \ --authrpc.addr="0.0.0.0" \ --authrpc.vhosts="*" \ --authrpc.jwtsecret="$jwtsecret_file_path" \ diff --git a/stack-orchestrator/stacks/eth/README.md b/stack-orchestrator/stacks/eth/README.md index f7285f8..f8e3352 100644 --- a/stack-orchestrator/stacks/eth/README.md +++ b/stack-orchestrator/stacks/eth/README.md @@ -10,13 +10,27 @@ ## Create a deployment -* First, create a spec file for the deployment, which will map the stack's ports and volumes to the host: +* Create a spec file for the deployment, which will map the stack's ports and volumes to the host: ```bash laconic-so --stack ~/cerc/eth-stack/stack-orchestrator/stacks/eth deploy init --output eth-spec.yml ``` -* Once you've made any needed changes to the spec file, create a deployment from it: +* Edit `network` in the spec file to map container ports to host ports as required: + + ```yml + ... + network: + ports: + eth-geth: + - '8545:8545' + - '8546:8546' + - '6060:6060' + eth-lighthouse: + - '8001:8001' + ``` + +* Create a deployment from the spec file: ```bash laconic-so --stack ~/cerc/eth-stack/stack-orchestrator/stacks/eth deploy create --spec-file eth-spec.yml --deployment-dir eth-deployment @@ -26,8 +40,29 @@ ```bash # Optional - # Allow unprotected txs - CERC_ALLOW_UNPROTECTED_TXS=true + + # Network to run the ETH node for (default: sepolia) + # (one of mainnet, sepolia, holesky) + CERC_NETWORK= + + # Geth options (https://geth.ethereum.org/docs/fundamentals/command-line-options) + + # Allow unprotected txs (default: false) + CERC_ALLOW_UNPROTECTED_TXS= + + # Verbosity level (default: info) + CERC_GETH_VERBOSITY= + + # Lighthouse BN options (https://lighthouse-book.sigmaprime.io/help_bn.html) + + # Verbosity level (default: info) + CERC_DEBUG_LEVEL= + + # Required + + # Beacon node endpoint to use for checkpoint sync + # (https://eth-clients.github.io/checkpoint-sync-endpoints/) + CERC_CHECKPOINT_SYNC_URL= ``` ## Start @@ -38,6 +73,29 @@ laconic-so deployment --dir eth-deployment start ``` +## Check status + +* To list down and monitor the running containers: + + ```bash + # With status + docker ps -a + + # Follow logs for eth-geth container + laconic-so deployment --dir eth-deployment logs eth-geth -f + + # Follow logs for eth-lighthouse container + laconic-so deployment --dir eth-deployment logs eth-lighthouse -f + ``` + +* Once the node has caught up to head, make a request to get the latest block number: + + ```bash + curl -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \ + http://localhost:8545 + ``` + ## Clean up * To stop all services running in the background, while preserving chain data: -- 2.45.2 From bd8c533fd722ecc0725307106724215a0cb6fb89 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 4 Sep 2024 17:53:59 +0530 Subject: [PATCH 5/6] Map p2p ports to host for both services --- stack-orchestrator/compose/docker-compose-eth.yml | 4 ++++ stack-orchestrator/stacks/eth/README.md | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-eth.yml b/stack-orchestrator/compose/docker-compose-eth.yml index 8fc8ead..f4744fa 100644 --- a/stack-orchestrator/compose/docker-compose-eth.yml +++ b/stack-orchestrator/compose/docker-compose-eth.yml @@ -26,6 +26,8 @@ services: - "8545" - "8546" - "6060" + - "30303/tcp" + - "30303/udp" eth-lighthouse: restart: on-failure @@ -46,6 +48,8 @@ services: - ../config/eth/run-cl.sh:/root/scripts/run-cl.sh ports: - "8001" + - "9000/tcp" + - "9000/udp" volumes: eth_geth_data: diff --git a/stack-orchestrator/stacks/eth/README.md b/stack-orchestrator/stacks/eth/README.md index f8e3352..874308f 100644 --- a/stack-orchestrator/stacks/eth/README.md +++ b/stack-orchestrator/stacks/eth/README.md @@ -23,11 +23,15 @@ network: ports: eth-geth: - - '8545:8545' - - '8546:8546' - - '6060:6060' + - '8545:8545' + - '8546:8546' + - '6060:6060' + - '30303:30303/tcp' + - '30303:30303/udp' eth-lighthouse: - - '8001:8001' + - '8001:8001' + - '9000:9000/tcp' + - '9000:9000/udp' ``` * Create a deployment from the spec file: -- 2.45.2 From fc85a179123aecaa9de729071d46b1c306e2c30a Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 6 Sep 2024 11:40:35 +0530 Subject: [PATCH 6/6] Make geth sync and gc modes configurable --- stack-orchestrator/compose/docker-compose-eth.yml | 2 ++ stack-orchestrator/config/eth/run-el.sh | 10 ++++++---- stack-orchestrator/stacks/eth/README.md | 6 ++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-eth.yml b/stack-orchestrator/compose/docker-compose-eth.yml index f4744fa..3237377 100644 --- a/stack-orchestrator/compose/docker-compose-eth.yml +++ b/stack-orchestrator/compose/docker-compose-eth.yml @@ -8,6 +8,8 @@ services: ETH_DATADIR: "/root/.ethereum" CERC_NETWORK: ${CERC_NETWORK:-sepolia} CERC_ALLOW_UNPROTECTED_TXS: ${CERC_ALLOW_UNPROTECTED_TXS:-false} + CERC_SYNCMODE: ${CERC_SYNCMODE:-full} + CERC_GCMODE: ${CERC_GCMODE:-archive} CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY:-3} entrypoint: ["sh", "-c"] command: | diff --git a/stack-orchestrator/config/eth/run-el.sh b/stack-orchestrator/config/eth/run-el.sh index bcd030b..efa2f60 100755 --- a/stack-orchestrator/config/eth/run-el.sh +++ b/stack-orchestrator/config/eth/run-el.sh @@ -8,6 +8,8 @@ fi echo "Using the following env:" echo "CERC_NETWORK: ${CERC_NETWORK}" echo "CERC_ALLOW_UNPROTECTED_TXS: ${CERC_ALLOW_UNPROTECTED_TXS}" +echo "CERC_SYNCMODE: ${CERC_SYNCMODE}" +echo "CERC_GCMODE: ${CERC_GCMODE}" echo "CERC_GETH_VERBOSITY: ${CERC_GETH_VERBOSITY}" echo "ETH_DATADIR: ${ETH_DATADIR}" @@ -57,15 +59,15 @@ geth \ --http \ --http.addr="0.0.0.0" \ --http.vhosts="*" \ - --http.api="${CERC_GETH_HTTP_APIS:-eth,web3,net,admin,personal,debug}" \ + --http.api="eth,web3,net,admin,personal,debug" \ --http.corsdomain="*" \ --ws \ --ws.addr="0.0.0.0" \ --ws.origins="*" \ - --ws.api="${CERC_GETH_WS_APIS:-eth,web3,net,admin,personal,debug}" \ + --ws.api="eth,web3,net,admin,personal,debug" \ --state.scheme hash \ - --gcmode archive \ - --syncmode=full \ + --gcmode $CERC_GCMODE \ + --syncmode=$CERC_SYNCMODE \ --metrics \ --metrics.addr="0.0.0.0" \ --verbosity=${CERC_GETH_VERBOSITY} \ diff --git a/stack-orchestrator/stacks/eth/README.md b/stack-orchestrator/stacks/eth/README.md index 874308f..28f789b 100644 --- a/stack-orchestrator/stacks/eth/README.md +++ b/stack-orchestrator/stacks/eth/README.md @@ -54,6 +54,12 @@ # Allow unprotected txs (default: false) CERC_ALLOW_UNPROTECTED_TXS= + # Blockchain sync mode (default: full) + CERC_SYNCMODE= + + # Garbage collection mode (default: archive) + CERC_GCMODE= + # Verbosity level (default: info) CERC_GETH_VERBOSITY= -- 2.45.2