Skip to content

Commit

Permalink
Enable custom testnet use (eth-educators#1493)
Browse files Browse the repository at this point in the history
* Prysm source build uses Go 1.21

* Remove unused vars from ethd

* Teku custom testnet
  • Loading branch information
yorickdowne authored Sep 1, 2023
1 parent c52d3d5 commit 943a375
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 44 deletions.
51 changes: 32 additions & 19 deletions ethd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions lodestar-cl-only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,8 +69,6 @@ services:
- ${CL_MIN_PEER_COUNT:-50}
- --logLevel
- ${LOG_LEVEL}
- --network
- ${NETWORK}
- --suggestedFeeRecipient
- ${FEE_RECIPIENT}
labels:
Expand Down
3 changes: 1 addition & 2 deletions lodestar-vc-only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,8 +62,6 @@ services:
- 0.0.0.0
- --logLevel
- ${LOG_LEVEL}
- --network
- ${NETWORK}
- --suggestedFeeRecipient
- ${FEE_RECIPIENT}
- --force
Expand Down
3 changes: 1 addition & 2 deletions lodestar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,8 +69,6 @@ services:
- ${CL_MAX_PEER_COUNT:-50}
- --logLevel
- ${LOG_LEVEL}
- --network
- ${NETWORK}
- --suggestedFeeRecipient
- ${FEE_RECIPIENT}

Expand Down
2 changes: 1 addition & 1 deletion lodestar/Dockerfile.binary
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lodestar/Dockerfile.source
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion lodestar/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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}
5 changes: 1 addition & 4 deletions nethermind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -80,8 +79,6 @@ services:
- ""
- --Metrics.ExposePort
- "6060"
- --config
- ${NETWORK}
- --Sync.AncientBodiesBarrier
- "1"
- --Sync.AncientReceiptsBarrier
Expand Down
2 changes: 1 addition & 1 deletion nethermind/Dockerfile.binary
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nethermind/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nethermind/Dockerfile.source
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion nethermind/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}
2 changes: 1 addition & 1 deletion prysm/Dockerfile.source
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion teku-cl-only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion teku.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion teku/Dockerfile.binary
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions teku/Dockerfile.source
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand Down
38 changes: 34 additions & 4 deletions teku/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"
Expand All @@ -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"
Expand All @@ -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

0 comments on commit 943a375

Please sign in to comment.