From 43059eaa5903cafbfca9fae2f8328ab1486ad985 Mon Sep 17 00:00:00 2001 From: Yorick Downe Date: Fri, 1 Sep 2023 17:11:06 +0000 Subject: [PATCH] Besu custom testnet --- besu.yml | 5 +---- besu/Dockerfile.binary | 2 +- besu/Dockerfile.source | 1 + besu/docker-entrypoint.sh | 28 +++++++++++++++++++++++++++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/besu.yml b/besu.yml index 1fe4437b..bb846fd6 100644 --- a/besu.yml +++ b/besu.yml @@ -24,6 +24,7 @@ services: - JWT_SECRET=${JWT_SECRET:-} - EL_EXTRAS=${EL_EXTRAS:-} - ARCHIVE_NODE=${ARCHIVE_NODE:-} + - NETWORK=${NETWORK} volumes: - besu-eth1-data:/var/lib/besu - /etc/localtime:/etc/localtime:ro @@ -44,8 +45,6 @@ services: - --p2p-port - ${EL_P2P_PORT:-30303} - --rpc-http-enabled - - --rpc-http-api - - "WEB3,ETH,NET" - --rpc-http-host - 0.0.0.0 - --rpc-http-port @@ -68,8 +67,6 @@ services: - --engine-rpc-port=${EE_PORT:-8551} - --logging - ${LOG_LEVEL} - - --network - - ${NETWORK} - --metrics-enabled - --metrics-host - 0.0.0.0 diff --git a/besu/Dockerfile.binary b/besu/Dockerfile.binary index 90809c5e..43c88053 100644 --- a/besu/Dockerfile.binary +++ b/besu/Dockerfile.binary @@ -15,7 +15,7 @@ USER root RUN groupmod -g "${GID}" besu && usermod -u "${UID}" -g "${GID}" besu RUN set -eux; \ - apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y gosu ca-certificates tzdata; \ + apt-get update && 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/besu/Dockerfile.source b/besu/Dockerfile.source index e6c233e3..275086ac 100644 --- a/besu/Dockerfile.source +++ b/besu/Dockerfile.source @@ -24,6 +24,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install tzdata \ gosu \ libjemalloc-dev \ + git \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/besu/docker-entrypoint.sh b/besu/docker-entrypoint.sh index 1ad6f28e..96a4ccc9 100755 --- a/besu/docker-entrypoint.sh +++ b/besu/docker-entrypoint.sh @@ -26,6 +26,32 @@ if [[ -O "/var/lib/besu/ee-secret/jwtsecret" ]]; then chmod 666 /var/lib/besu/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/besu/testnet/${config_dir}" ]; then + mkdir -p /var/lib/besu/testnet + cd /var/lib/besu/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/besu/testnet/${config_dir}/bootnode.txt")" + set +e + __network="--genesis-file=/var/lib/besu/testnet/${config_dir}/besu.json --bootnodes=${bootnodes} \ +--kzg-trusted-setup=/var/lib/besu/testnet/${config_dir}/trusted_setup.txt --Xfilter-on-enr-fork-id=true \ +--rpc-http-api=ADMIN,CLIQUE,MINER,ETH,NET,DEBUG,TXPOOL,ENGINE,TRACE,WEB3" +else + __network="--network ${NETWORK} --rpc-http-api WEB3,ETH,NET" +fi + if [ "${ARCHIVE_NODE}" = "true" ]; then echo "Besu archive node without pruning" __prune="--data-storage-format=FOREST --sync-mode=FULL" @@ -35,4 +61,4 @@ fi # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 -exec "$@" ${__prune} ${EL_EXTRAS} +exec "$@" ${__network} ${__prune} ${EL_EXTRAS}