Skip to content

Commit

Permalink
Geth custom testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdowne committed Sep 1, 2023
1 parent e0e6816 commit df2cc54
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions erigon/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ if [[ "${NETWORK}" =~ ^https?:// ]]; then
else
__network="--chain ${NETWORK} --http.api web3,eth,net,engine"
fi

# Check for network, and set prune accordingly

if [ "${ARCHIVE_NODE}" = "true" ]; then
Expand Down
4 changes: 1 addition & 3 deletions geth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
- LOG_LEVEL=${LOG_LEVEL:-info}
- EL_EXTRAS=${EL_EXTRAS:-}
- ARCHIVE_NODE=${ARCHIVE_NODE:-}
- NETWORK=${NETWORK}
volumes:
- geth-eth1-data:/var/lib/goethereum
- /etc/localtime:/etc/localtime:ro
Expand All @@ -44,8 +45,6 @@ services:
- 0.0.0.0
- --http.vhosts=*
- --http.corsdomain=*
- --http.api
- web3,eth,net
- --datadir
- /var/lib/goethereum
- --port
Expand All @@ -60,7 +59,6 @@ services:
- --ws.api
- web3,eth,net
- --ws.origins=*
- --${NETWORK}
- --metrics
- --metrics.expensive
- --pprof
Expand Down
2 changes: 1 addition & 1 deletion geth/Dockerfile.binary
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ARG UID=10001
# GID 10002 is deliberate so it can exchange secret with CL
ARG GID=10002

RUN apk update && apk add --no-cache ca-certificates tzdata bash su-exec
RUN apk update && apk add --no-cache ca-certificates tzdata bash su-exec git jq

RUN addgroup \
--gid "${GID}" \
Expand Down
2 changes: 1 addition & 1 deletion geth/Dockerfile.source
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ARG UID=10001
# GID 10002 is deliberate so it can exchange secret with CL
ARG GID=10002

RUN apk add --no-cache ca-certificates tzdata bash su-exec
RUN apk add --no-cache ca-certificates tzdata bash su-exec git jq

RUN addgroup \
--gid "${GID}" \
Expand Down
33 changes: 31 additions & 2 deletions geth/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,35 @@ if [[ -O "/var/lib/goethereum/ee-secret/jwtsecret" ]]; then
chmod 666 /var/lib/goethereum/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/goethereum/testnet/${config_dir}" ]; then
mkdir -p /var/lib/goethereum/testnet
cd /var/lib/goethereum/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/goethereum/testnet/${config_dir}/bootnode.txt")"
networkid="$(jq -r '.config.chainId' "/var/lib/goethereum/testnet/${config_dir}/genesis.json")"
set +e
__network="--bootnodes=${bootnodes} --networkid=${networkid} --http.api=eth,net,web3,debug,admin,txpool"
if [ ! -f /var/lib/goethereum/setupdone ]; then
geth init --datadir /var/lib/goethereum "/var/lib/goethereum/testnet/${config_dir}/genesis.json"
touch /var/lib/goethereum/setupdone
fi
else
__network="--${NETWORK} --http.api web3,eth,net"
fi

# Set verbosity
shopt -s nocasematch
case ${LOG_LEVEL} in
Expand Down Expand Up @@ -72,9 +101,9 @@ if [ -f /var/lib/goethereum/prune-marker ]; then
fi
# Word splitting is desired for the command line parameters
# shellcheck disable=SC2086
exec "$@" ${EL_EXTRAS} snapshot prune-state
exec "$@" ${__network} ${EL_EXTRAS} snapshot prune-state
else
# Word splitting is desired for the command line parameters
# shellcheck disable=SC2086
exec "$@" ${__prune} ${__verbosity} ${EL_EXTRAS}
exec "$@" ${__network} ${__prune} ${__verbosity} ${EL_EXTRAS}
fi

0 comments on commit df2cc54

Please sign in to comment.