From 943a3756cb3e8ee09a9e772fdb94120e162a4496 Mon Sep 17 00:00:00 2001 From: yorickdowne <71337066+yorickdowne@users.noreply.github.com> Date: Fri, 1 Sep 2023 05:16:47 -0400 Subject: [PATCH] Enable custom testnet use (#1493) * Prysm source build uses Go 1.21 * Remove unused vars from ethd * Teku custom testnet --- ethd | 51 +++++++++++++++++++++------------ lodestar-cl-only.yml | 3 +- lodestar-vc-only.yml | 3 +- lodestar.yml | 3 +- lodestar/Dockerfile.binary | 2 +- lodestar/Dockerfile.source | 2 +- lodestar/docker-entrypoint.sh | 28 +++++++++++++++++- nethermind.yml | 5 +--- nethermind/Dockerfile.binary | 2 +- nethermind/Dockerfile.dev | 2 +- nethermind/Dockerfile.source | 2 +- nethermind/docker-entrypoint.sh | 28 +++++++++++++++++- prysm/Dockerfile.source | 2 +- teku-cl-only.yml | 2 +- teku.yml | 2 +- teku/Dockerfile.binary | 2 +- teku/Dockerfile.source | 1 + teku/docker-entrypoint.sh | 38 +++++++++++++++++++++--- 18 files changed, 134 insertions(+), 44 deletions(-) diff --git a/ethd b/ethd index 830f5b8a..51f3d262 100755 --- a/ethd +++ b/ethd @@ -1303,12 +1303,7 @@ prep-keyimport() { exit 1 fi - __prysm=0 - __path='' __non_interactive=0 - if grep -q '^COMPOSE_FILE=.*prysm.*\.yml' "${ENV_FILE}" 2>/dev/null ; then - __prysm=1 - fi while : do @@ -1775,22 +1770,40 @@ query_network() { "goerli" "Görli (né Prater) Testnet" \ "mainnet" "Ethereum Mainnet" \ "gnosis" "Gnosis Chain (né xDai)" \ - "sepolia" "Sepolia Testnet (permissioned validators)" 3>&1 1>&2 2>&3) + "sepolia" "Sepolia Testnet (permissioned validators)" \ + "custom" "Custom Testnet (needs a URL)" 3>&1 1>&2 2>&3) case "${NETWORK}" in - "mainnet") - echo "You chose to run on Ethereum mainnet" - ;; - "gnosis") - echo "You chose to run on Gnosis Chain" - ;; - "goerli" | "sepolia" | "zhejiang" ) - echo "You chose to run on ${NETWORK} testnet" - ;; - *) - echo "You chose Cancel" - exit 1 - ;; + "mainnet") + echo "You chose to run on Ethereum mainnet" + ;; + "gnosis") + echo "You chose to run on Gnosis Chain" + ;; + "goerli" | "sepolia" | "zhejiang" ) + echo "You chose to run on ${NETWORK} testnet" + ;; + "custom" ) + while true; do + NETWORK=$(whiptail --title "Configure testnet URL" --inputbox "What is github URL of your custom testnet spec? (right-click to paste)" 10 60 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus -eq 0 ]; then + if [[ ${NETWORK} =~ ^https?:// ]]; then + echo "Your customer testnet URL is: ${NETWORK}" + break + else + whiptail --msgbox "${NETWORK} is not a valid URL. You can try again or Cancel on the next screen.\n\nCustom testnets only work with a URL to fetch their configuration from." 16 75 + fi + else + echo "You chose Cancel" + exit 1 + fi + done + ;; + *) + echo "You chose Cancel" + exit 1 + ;; esac } diff --git a/lodestar-cl-only.yml b/lodestar-cl-only.yml index bd7c9845..cc05eddc 100644 --- a/lodestar-cl-only.yml +++ b/lodestar-cl-only.yml @@ -35,6 +35,7 @@ services: - BEACON_STATS_MACHINE=${BEACON_STATS_MACHINE} - CL_EXTRAS=${CL_EXTRAS:-} - ARCHIVE_NODE=${ARCHIVE_NODE:-} + - NETWORK=${NETWORK} ports: - ${HOST_IP:-}${CL_P2P_PORT:-9000}:${CL_P2P_PORT:-9000}/tcp - ${HOST_IP:-}${CL_P2P_PORT:-9000}:${CL_P2P_PORT:-9000}/udp @@ -68,8 +69,6 @@ services: - ${CL_MIN_PEER_COUNT:-50} - --logLevel - ${LOG_LEVEL} - - --network - - ${NETWORK} - --suggestedFeeRecipient - ${FEE_RECIPIENT} labels: diff --git a/lodestar-vc-only.yml b/lodestar-vc-only.yml index 60b1999b..c08ce114 100644 --- a/lodestar-vc-only.yml +++ b/lodestar-vc-only.yml @@ -30,6 +30,7 @@ services: - GRAFFITI=${GRAFFITI:-} - DEFAULT_GRAFFITI=${DEFAULT_GRAFFITI:-false} - WEB3SIGNER=${WEB3SIGNER} + - NETWORK=${NETWORK} volumes: - lsvalidator-data:/var/lib/lodestar/validators - /etc/localtime:/etc/localtime:ro @@ -61,8 +62,6 @@ services: - 0.0.0.0 - --logLevel - ${LOG_LEVEL} - - --network - - ${NETWORK} - --suggestedFeeRecipient - ${FEE_RECIPIENT} - --force diff --git a/lodestar.yml b/lodestar.yml index d1a63f7b..0c191860 100644 --- a/lodestar.yml +++ b/lodestar.yml @@ -35,6 +35,7 @@ services: - BEACON_STATS_MACHINE=${BEACON_STATS_MACHINE} - CL_EXTRAS=${CL_EXTRAS:-} - ARCHIVE_NODE=${ARCHIVE_NODE:-} + - NETWORK=${NETWORK} ports: - ${HOST_IP:-}${CL_P2P_PORT:-9000}:${CL_P2P_PORT:-9000}/tcp - ${HOST_IP:-}${CL_P2P_PORT:-9000}:${CL_P2P_PORT:-9000}/udp @@ -68,8 +69,6 @@ services: - ${CL_MAX_PEER_COUNT:-50} - --logLevel - ${LOG_LEVEL} - - --network - - ${NETWORK} - --suggestedFeeRecipient - ${FEE_RECIPIENT} diff --git a/lodestar/Dockerfile.binary b/lodestar/Dockerfile.binary index cda07523..51b5fef5 100644 --- a/lodestar/Dockerfile.binary +++ b/lodestar/Dockerfile.binary @@ -5,7 +5,7 @@ FROM chainsafe/lodestar:${DOCKER_TAG} # Here only to avoid build-time errors ARG BUILD_TARGET -RUN apk update && apk add --no-cache ca-certificates tzdata bash su-exec && rm -rf /var/cache/apk/* +RUN apk update && apk add --no-cache ca-certificates tzdata bash su-exec git && rm -rf /var/cache/apk/* ARG USER=lsconsensus ARG UID=10002 diff --git a/lodestar/Dockerfile.source b/lodestar/Dockerfile.source index 5a276c0c..8731b126 100644 --- a/lodestar/Dockerfile.source +++ b/lodestar/Dockerfile.source @@ -14,7 +14,7 @@ RUN bash -c "cd .. && rm -rf app && git clone https://github.com/ChainSafe/lodes FROM node:20-alpine -RUN apk update && apk add --no-cache ca-certificates tzdata bash su-exec && rm -rf /var/cache/apk/* +RUN apk update && apk add --no-cache ca-certificates tzdata bash su-exec git && rm -rf /var/cache/apk/* ARG USER=lsconsensus ARG UID=10002 diff --git a/lodestar/docker-entrypoint.sh b/lodestar/docker-entrypoint.sh index eb515e63..406952d7 100755 --- a/lodestar/docker-entrypoint.sh +++ b/lodestar/docker-entrypoint.sh @@ -29,6 +29,32 @@ if [[ -O "/var/lib/lodestar/consensus/ee-secret/jwtsecret" ]]; then chmod 666 /var/lib/lodestar/consensus/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/lodestar/consensus/testnet/${config_dir}" ]; then + mkdir -p /var/lib/lodestar/consensus/testnet + cd /var/lib/lodestar/consensus/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/lodestar/consensus/testnet/${config_dir}/bootstrap_nodes.txt")" + set +e + __network="--paramsFile=/var/lib/lodestar/consensus/testnet/${config_dir}/config.yaml --genesisStateFile=/var/lib/lodestar/consensus/testnet/${config_dir}/genesis.ssz \ +--bootnodes=${bootnodes} --network.connectToDiscv5Bootnodes --chain.trustedSetup=/var/lib/lodestar/consensus/testnet/${config_dir}/trusted_setup.txt \ +--rest.namespace=*" +else + __network="--network ${NETWORK}" +fi + # Check whether we should use MEV Boost if [ "${MEV_BOOST}" = "true" ]; then __mev_boost="--builder --builder.urls=${MEV_NODE:-http://mev-boost:18550}" @@ -60,4 +86,4 @@ fi # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 -exec "$@" ${__mev_boost} ${__beacon_stats} ${__rapid_sync} ${CL_EXTRAS} +exec "$@" ${__network} ${__mev_boost} ${__beacon_stats} ${__rapid_sync} ${CL_EXTRAS} diff --git a/nethermind.yml b/nethermind.yml index f2169159..ba9dfc6c 100644 --- a/nethermind.yml +++ b/nethermind.yml @@ -25,6 +25,7 @@ services: - EL_EXTRAS=${EL_EXTRAS:-} - ARCHIVE_NODE=${ARCHIVE_NODE:-} - AUTOPRUNE_NM=${AUTOPRUNE_NM:-true} + - NETWORK=${NETWORK} volumes: - nm-eth1-data:/var/lib/nethermind - /etc/localtime:/etc/localtime:ro @@ -67,8 +68,6 @@ services: - 0.0.0.0 - --JsonRpc.EnginePort - ${EE_PORT:-8551} - - --JsonRpc.EnabledModules - - "Web3,Eth,Subscribe,Net,Health,Parity,Proof,Trace,TxPool" - --JsonRpc.AdditionalRpcUrls=http://127.0.0.1:1337|http|admin - --JsonRpc.JwtSecretFile=/var/lib/nethermind/ee-secret/jwtsecret # Temporary Prysm workaround. Remove when no longer needed @@ -80,8 +79,6 @@ services: - "" - --Metrics.ExposePort - "6060" - - --config - - ${NETWORK} - --Sync.AncientBodiesBarrier - "1" - --Sync.AncientReceiptsBarrier diff --git a/nethermind/Dockerfile.binary b/nethermind/Dockerfile.binary index e0d2f583..cbb1d835 100644 --- a/nethermind/Dockerfile.binary +++ b/nethermind/Dockerfile.binary @@ -27,7 +27,7 @@ RUN adduser \ RUN set -eux; \ apt-get update; \ - DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y ca-certificates gosu tzdata wget; \ + DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y ca-certificates gosu tzdata wget git; \ rm -rf /var/lib/apt/lists/*; \ # verify that the binary works gosu nobody true diff --git a/nethermind/Dockerfile.dev b/nethermind/Dockerfile.dev index 954dfc42..cbe6b37b 100644 --- a/nethermind/Dockerfile.dev +++ b/nethermind/Dockerfile.dev @@ -27,7 +27,7 @@ RUN adduser \ RUN set -eux; \ apt-get update; \ - DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y ca-certificates gosu tzdata; \ + DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y ca-certificates gosu tzdata git; \ rm -rf /var/lib/apt/lists/*; \ # verify that the binary works gosu nobody true diff --git a/nethermind/Dockerfile.source b/nethermind/Dockerfile.source index e3f1230e..ab8baf06 100644 --- a/nethermind/Dockerfile.source +++ b/nethermind/Dockerfile.source @@ -21,7 +21,7 @@ RUN bash -c "\ FROM mcr.microsoft.com/dotnet/aspnet:7.0 -RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install libsnappy-dev libc6-dev libc6 ca-certificates gosu tzdata wget && rm -rf /var/lib/apt/lists/* +RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install libsnappy-dev libc6-dev libc6 ca-certificates gosu tzdata wget git && rm -rf /var/lib/apt/lists/* ARG USER=nethermind ARG UID=10001 diff --git a/nethermind/docker-entrypoint.sh b/nethermind/docker-entrypoint.sh index 47cd2816..d3205b47 100755 --- a/nethermind/docker-entrypoint.sh +++ b/nethermind/docker-entrypoint.sh @@ -31,6 +31,31 @@ if [[ -O "/var/lib/nethermind/ee-secret/jwtsecret" ]]; then chmod 666 /var/lib/nethermind/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}." + if [ ! -d "/var/lib/nethermind/testnet/${config_dir}" ]; then + # For want of something more amazing, let's just fail if git fails to pull this + set -e + mkdir -p /var/lib/nethermind/testnet + cd /var/lib/nethermind/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}" + set +e + fi + bootnodes="$(paste -s -d, "/var/lib/nethermind/testnet/${config_dir}/bootnode.txt")" + __network="--config none.cfg --Init.ChainSpecPath=/var/lib/nethermind/testnet/${config_dir}/chainspec.json --Discovery.Bootnodes=${bootnodes} \ +--JsonRpc.EnabledModules=Eth,Subscribe,Trace,TxPool,Web3,Personal,Proof,Net,Parity,Health,Rpc,Debug,Admin --Pruning.Mode=None --Init.IsMining=false" +else + __network="--config ${NETWORK} --JsonRpc.EnabledModules Web3,Eth,Subscribe,Net,Health,Parity,Proof,Trace,TxPool" +fi + __memtotal=$(awk '/MemTotal/ {printf "%d", int($2/1024/1024)}' /proc/meminfo) if [ "${ARCHIVE_NODE}" = "true" ]; then echo "Nethermind archive node without pruning" @@ -61,6 +86,7 @@ else echo "Using pruning parameters:" echo "${__prune}" fi + # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 -exec "$@" ${__memhint} ${__prune} ${EL_EXTRAS} +exec "$@" ${__network} ${__memhint} ${__prune} ${EL_EXTRAS} diff --git a/prysm/Dockerfile.source b/prysm/Dockerfile.source index aed510fa..44a9f646 100644 --- a/prysm/Dockerfile.source +++ b/prysm/Dockerfile.source @@ -1,5 +1,5 @@ # Build Prysm in a stock Go build container -FROM golang:1.20-bookworm as builder +FROM golang:1.21-bookworm as builder # Here only to avoid build-time errors ARG DOCKER_TAG diff --git a/teku-cl-only.yml b/teku-cl-only.yml index 284077fd..993c45ea 100644 --- a/teku-cl-only.yml +++ b/teku-cl-only.yml @@ -42,6 +42,7 @@ services: - DEFAULT_GRAFFITI=true - WEB3SIGNER=false - EMBEDDED_VC=false + - NETWORK=${NETWORK} ports: - ${HOST_IP:-}${CL_P2P_PORT:-9000}:${CL_P2P_PORT:-9000}/tcp - ${HOST_IP:-}${CL_P2P_PORT:-9000}:${CL_P2P_PORT:-9000}/udp @@ -55,7 +56,6 @@ services: - /opt/teku/bin/teku - --data-path=/var/lib/teku - --log-destination=CONSOLE - - --network=${NETWORK} - --ee-endpoint=${EL_NODE} - --ee-jwt-secret-file - /var/lib/teku/ee-secret/jwtsecret diff --git a/teku.yml b/teku.yml index 73c41282..cfc6f2da 100644 --- a/teku.yml +++ b/teku.yml @@ -42,6 +42,7 @@ services: - DEFAULT_GRAFFITI=${DEFAULT_GRAFFITI:-false} - WEB3SIGNER=${WEB3SIGNER:-false} - EMBEDDED_VC=true + - NETWORK=${NETWORK} ports: - ${HOST_IP:-}${CL_P2P_PORT:-9000}:${CL_P2P_PORT:-9000}/tcp - ${HOST_IP:-}${CL_P2P_PORT:-9000}:${CL_P2P_PORT:-9000}/udp @@ -55,7 +56,6 @@ services: - /opt/teku/bin/teku - --data-path=/var/lib/teku - --log-destination=CONSOLE - - --network=${NETWORK} - --ee-endpoint=${EL_NODE} - --ee-jwt-secret-file - /var/lib/teku/ee-secret/jwtsecret diff --git a/teku/Dockerfile.binary b/teku/Dockerfile.binary index 67233ec6..b12a1891 100644 --- a/teku/Dockerfile.binary +++ b/teku/Dockerfile.binary @@ -14,7 +14,7 @@ RUN groupmod -g "${UID}" ${USER} && usermod -u "${UID}" -g "${UID}" ${USER} RUN set -eux; \ apt-get update; \ - DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y gosu ca-certificates tzdata; \ + DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y gosu ca-certificates tzdata git; \ rm -rf /var/lib/apt/lists/*; \ # verify that the binary works gosu nobody true diff --git a/teku/Dockerfile.source b/teku/Dockerfile.source index f747a7c8..acb5b5c7 100644 --- a/teku/Dockerfile.source +++ b/teku/Dockerfile.source @@ -27,6 +27,7 @@ ARG UID=10002 RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y --no-install-recommends \ ca-certificates \ tzdata \ + git \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/teku/docker-entrypoint.sh b/teku/docker-entrypoint.sh index 96f15dd2..e5e22b3e 100755 --- a/teku/docker-entrypoint.sh +++ b/teku/docker-entrypoint.sh @@ -40,7 +40,7 @@ fi # Check whether we should rapid sync if [ -n "${RAPID_SYNC_URL:+x}" ]; then if [ "${ARCHIVE_NODE}" = "true" ]; then - echo "Besu archive node cannot use checkpoint sync: Syncing from genesis." + echo "Teku archive node cannot use checkpoint sync: Syncing from genesis." __rapid_sync="" else __rapid_sync="--initial-state=${RAPID_SYNC_URL}/eth/v2/debug/beacon/states/finalized" @@ -50,6 +50,36 @@ else __rapid_sync="" 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/teku/testnet/${config_dir}" ]; then + mkdir -p /var/lib/teku/testnet + cd /var/lib/teku/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/teku/testnet/${config_dir}/bootstrap_nodes.txt")" + set +e + if [ -z "${__rapid_sync}" ]; then + __rapid_sync="--initial-state=/var/lib/teku/testnet/${config_dir}/genesis.ssz" + fi + __network="--network=/var/lib/teku/testnet/${config_dir}/config.yaml --p2p-discovery-bootnodes=${bootnodes} \ +--data-storage-non-canonical-blocks-enabled=true --Xlog-include-p2p-warnings-enabled \ +--metrics-block-timing-tracking-enabled --Xmetrics-blob-sidecars-storage-enabled=true --Xtrusted-setup=/var/lib/teku/testnet/${config_dir}/trusted_setup.txt \ +--Xpeer-rate-limit=100000 --Xpeer-request-limit=1000" +else + __network="--network=${NETWORK}" +fi + # Check whether we should use MEV Boost if [ "${MEV_BOOST}" = "true" ]; then __mev_boost="--validators-builder-registration-default-enabled --builder-endpoint=${MEV_NODE:-http://mev-boost:18550}" @@ -75,7 +105,7 @@ else fi if [ "${ARCHIVE_NODE}" = "true" ]; then - echo "Besu archive node without pruning" + echo "Teku archive node without pruning" __prune="--data-storage-mode=ARCHIVE" else __prune="--data-storage-mode=MINIMAL" @@ -100,9 +130,9 @@ fi if [ "${DEFAULT_GRAFFITI}" = "true" ]; then # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 - exec "$@" ${__w3s_url} ${__mev_boost} ${__rapid_sync} ${__prune} ${__beacon_stats} ${__doppel} ${CL_EXTRAS} ${VC_EXTRAS} + exec "$@" ${__network} ${__w3s_url} ${__mev_boost} ${__rapid_sync} ${__prune} ${__beacon_stats} ${__doppel} ${CL_EXTRAS} ${VC_EXTRAS} else # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 - exec "$@" "--validators-graffiti=${GRAFFITI}" ${__w3s_url} ${__mev_boost} ${__rapid_sync} ${__prune} ${__beacon_stats} ${__doppel} ${CL_EXTRAS} ${VC_EXTRAS} + exec "$@" ${__network} "--validators-graffiti=${GRAFFITI}" ${__w3s_url} ${__mev_boost} ${__rapid_sync} ${__prune} ${__beacon_stats} ${__doppel} ${CL_EXTRAS} ${VC_EXTRAS} fi