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