From 8715a5d65f99ac1424a297b63bf404be6d12e406 Mon Sep 17 00:00:00 2001 From: yorickdowne <71337066+yorickdowne@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:10:13 -0400 Subject: [PATCH] Reth custom testnet (#1497) --- reth.yml | 3 +-- reth/Dockerfile.binary | 1 + reth/Dockerfile.source | 1 + reth/docker-entrypoint.sh | 26 +++++++++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/reth.yml b/reth.yml index 131800d0..792be8c2 100644 --- a/reth.yml +++ b/reth.yml @@ -25,6 +25,7 @@ services: - EL_EXTRAS=${EL_EXTRAS:-} - LOG_LEVEL=${LOG_LEVEL:-info} - ARCHIVE_NODE=${ARCHIVE_NODE:-} + - NETWORK=${NETWORK} # Make this RUST_LOG=${LOG_LEVEL:-info},engine=trace when requiring deep debug - RUST_LOG=${LOG_LEVEL:-info} - RUST_LOG_STYLE=never @@ -46,8 +47,6 @@ services: - node - --datadir - /var/lib/reth - - --chain - - ${NETWORK} - --metrics - 0.0.0.0:6060 - --port diff --git a/reth/Dockerfile.binary b/reth/Dockerfile.binary index d49139fa..acaad5b3 100644 --- a/reth/Dockerfile.binary +++ b/reth/Dockerfile.binary @@ -11,6 +11,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install ca-certificates \ tzdata \ gosu \ + git \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/reth/Dockerfile.source b/reth/Dockerfile.source index 673125e4..d284f230 100644 --- a/reth/Dockerfile.source +++ b/reth/Dockerfile.source @@ -24,6 +24,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install ca-certificates \ tzdata \ gosu \ + git \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/reth/docker-entrypoint.sh b/reth/docker-entrypoint.sh index f9c6a3a4..1061c5d5 100755 --- a/reth/docker-entrypoint.sh +++ b/reth/docker-entrypoint.sh @@ -26,6 +26,30 @@ if [[ -O "/var/lib/reth/ee-secret/jwtsecret" ]]; then chmod 666 /var/lib/reth/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/reth/testnet/${config_dir}" ]; then + mkdir -p /var/lib/reth/testnet + cd /var/lib/reth/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/reth/testnet/${config_dir}/bootnode.txt")" + set +e + __network="--chain=/var/lib/reth/testnet/${config_dir}/genesis.json --bootnodes=${bootnodes}" +else + __network="--chain ${NETWORK}" +fi + # Set verbosity shopt -s nocasematch case ${LOG_LEVEL} in @@ -59,4 +83,4 @@ fi # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 -exec "$@" ${__verbosity} ${__prune} ${EL_EXTRAS} +exec "$@" ${__network} ${__verbosity} ${__prune} ${EL_EXTRAS}