From 8f55792e3625d3ed7b5860a0a83ccddef3bc4ed6 Mon Sep 17 00:00:00 2001 From: Yorick Downe Date: Fri, 1 Sep 2023 17:28:38 +0000 Subject: [PATCH] Erigon custom testnet --- erigon.yml | 5 +---- erigon/Dockerfile.binary | 2 +- erigon/Dockerfile.source | 2 +- erigon/docker-entrypoint.sh | 30 +++++++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/erigon.yml b/erigon.yml index 1f66bd29..699c542a 100644 --- a/erigon.yml +++ b/erigon.yml @@ -23,6 +23,7 @@ services: - JWT_SECRET=${JWT_SECRET} - EL_EXTRAS=${EL_EXTRAS:-} - ARCHIVE_NODE=${ARCHIVE_NODE:-} + - NETWORK=${NETWORK} volumes: - erigon-el-data:/var/lib/erigon - /etc/localtime:/etc/localtime:ro @@ -57,8 +58,6 @@ services: - ${ERIGON_TORRENT_PORT:-42069} - --nat - any - - --chain - - ${NETWORK} - --log.console.verbosity - ${LOG_LEVEL} - --metrics @@ -71,8 +70,6 @@ services: - ${EL_RPC_PORT} - --http.vhosts=* - --http.corsdomain=* - - --http.api - - web3,eth,net,engine - --ws # Allow RocketPool >=1.9 watchtower queries - --rpc.returndata.limit diff --git a/erigon/Dockerfile.binary b/erigon/Dockerfile.binary index 2352e72e..670f1827 100644 --- a/erigon/Dockerfile.binary +++ b/erigon/Dockerfile.binary @@ -12,7 +12,7 @@ ARG GID=10002 USER root -RUN apk --no-cache add shadow bash su-exec && groupmod -g "${GID}" ${USER} && usermod -u "${UID}" -g "${GID}" ${USER} +RUN apk --no-cache add shadow bash su-exec git jq && groupmod -g "${GID}" ${USER} && usermod -u "${UID}" -g "${GID}" ${USER} RUN mkdir -p /var/lib/erigon/ee-secret && chown -R ${USER}:${USER} /var/lib/erigon && chmod -R 700 /var/lib/erigon && chmod 777 /var/lib/erigon/ee-secret diff --git a/erigon/Dockerfile.source b/erigon/Dockerfile.source index 1970f928..ab7ddc17 100644 --- a/erigon/Dockerfile.source +++ b/erigon/Dockerfile.source @@ -20,7 +20,7 @@ ARG UID=10001 # GID 10002 is deliberate so it can exchange secret with CL ARG GID=10002 -RUN apk add --no-cache libgcc libstdc++ bash ca-certificates tzdata su-exec +RUN apk add --no-cache libgcc libstdc++ bash ca-certificates tzdata su-exec git jq RUN addgroup \ --gid "${GID}" \ diff --git a/erigon/docker-entrypoint.sh b/erigon/docker-entrypoint.sh index c476d1c8..fd27f660 100755 --- a/erigon/docker-entrypoint.sh +++ b/erigon/docker-entrypoint.sh @@ -26,6 +26,34 @@ if [[ -O "/var/lib/erigon/ee-secret/jwtsecret" ]]; then chmod 666 /var/lib/erigon/ee-secret/jwtsecret fi +if [[ "${NETWORK}" =~ ^https?:// ]]; then + echo "Custom testnet at ${NETWORK}" + repo=$(awk -F'/tree/' '{print $1}' <<< "${NETWORK}") + branch=$(awk -F'/tree/' '{print $2}' <<< "${NETWORK}" | cut -d'/' -f1) + config_dir=$(awk -F'/tree/' '{print $2}' <<< "${NETWORK}" | cut -d'/' -f2-) + echo "This appears to be the ${repo} repo, branch ${branch} and config directory ${config_dir}." + # For want of something more amazing, let's just fail if git fails to pull this + set -e + if [ ! -d "/var/lib/erigon/testnet/${config_dir}" ]; then + mkdir -p /var/lib/erigon/testnet + cd /var/lib/erigon/testnet + git init --initial-branch="${branch}" + git remote add origin "${repo}" + git config core.sparseCheckout true + echo "${config_dir}" > .git/info/sparse-checkout + git pull origin "${branch}" + fi + bootnodes="$(paste -s -d, "/var/lib/erigon/testnet/${config_dir}/bootnode.txt")" + networkid="$(jq -r '.config.chainId' "/var/lib/erigon/testnet/${config_dir}/genesis.json")" + set +e + __network="--bootnodes=${bootnodes} --networkid=${networkid} --http.api=eth,erigon,engine,web3,net,debug,trace,txpool,admin" + if [ ! -f /var/lib/erigon/setupdone ]; then + erigon init --datadir /var/lib/erigon "/var/lib/erigon/testnet/${config_dir}/genesis.json" + touch /var/lib/erigon/setupdone + fi +else + __network="--chain ${NETWORK} --http.api web3,eth,net,engine" +fi # Check for network, and set prune accordingly if [ "${ARCHIVE_NODE}" = "true" ]; then @@ -52,4 +80,4 @@ fi # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 -exec "$@" ${__prune} ${EL_EXTRAS} +exec "$@" ${__network} ${__prune} ${EL_EXTRAS}