From ca2b6c005107e648b2fd237cb8e47453edf6e92e Mon Sep 17 00:00:00 2001 From: dappnodedev Date: Thu, 27 Jun 2024 17:04:09 +0200 Subject: [PATCH] Handle P2P port on compose files --- besu/Dockerfile | 7 +- besu/entrypoint.sh | 80 +++++++++++---------- package_variants/holesky/docker-compose.yml | 1 + package_variants/mainnet/docker-compose.yml | 1 + 4 files changed, 51 insertions(+), 38 deletions(-) diff --git a/besu/Dockerfile b/besu/Dockerfile index 554eea3..c4d151a 100644 --- a/besu/Dockerfile +++ b/besu/Dockerfile @@ -1,8 +1,10 @@ ARG UPSTREAM_VERSION -ARG NETWORK FROM hyperledger/besu:${UPSTREAM_VERSION} +ARG NETWORK +ARG P2P_PORT + COPY security /security COPY entrypoint.sh /usr/local/bin/entrypoint.sh @@ -25,7 +27,8 @@ ENV BESU_RPC_WS_HOST=0.0.0.0 \ BESU_METRICS_ENABLED=true \ BESU_METRICS_HOST=0.0.0.0 \ BESU_DATA_PATH=/var/lib/besu \ - NETWORK=${NETWORK} + NETWORK=${NETWORK} \ + P2P_PORT=${P2P_PORT} USER besu diff --git a/besu/entrypoint.sh b/besu/entrypoint.sh index 2156b4a..76bbde5 100755 --- a/besu/entrypoint.sh +++ b/besu/entrypoint.sh @@ -1,47 +1,55 @@ #!/bin/sh -set_jwt_path() { - CLIENT=$1 - echo "Using $CLIENT JWT" - JWT_PATH="/security/$CLIENT/jwtsecret.hex" -} - set_network_specific_config() { - CONSENSUS_DNP=$1 - P2P_PORT=$2 - echo "[INFO - entrypoint] Initializing $NETWORK specific config for client" + set_consensus_dnp + # If consensus client is prysm-prater.dnp.dappnode.eth --> CLIENT=prysm - CLIENT=$(echo "$CONSENSUS_DNP" | cut -d'.' -f1 | cut -d'-' -f1) + consensus_client=$(echo "$CONSENSUS_DNP" | cut -d'.' -f1 | cut -d'-' -f1) + + set_jwt_path "$consensus_client" +} - set_jwt_path "$CLIENT" +set_consensus_dnp() { + uppercase_network=$(echo "$NETWORK" | tr '[:lower:]' '[:upper:]') + consensus_dnp_var="_DAPPNODE_GLOBAL_CONSENSUS_CLIENT_${uppercase_network}" + eval "CONSENSUS_DNP=\${$consensus_dnp_var}" +} +set_jwt_path() { + consensus_client=$1 + echo "[INFO - entrypoint] Using $consensus_client JWT" + JWT_PATH="/security/$consensus_client/jwtsecret.hex" + + if [ ! -f "${JWT_PATH}" ]; then + echo "[ERROR - entrypoint] JWT not found at ${JWT_PATH}" + exit 1 + fi } -case "$NETWORK" in -"holesky") set_network_specific_config "$_DAPPNODE_GLOBAL_CONSENSUS_CLIENT_HOLESKY" 30415 ;; -"mainnet") set_network_specific_config "$_DAPPNODE_GLOBAL_CONSENSUS_CLIENT_MAINNET" 30414 ;; -*) - echo "Unsupported network: $NETWORK" - exit 1 - ;; -esac - -# Check if curl is installed (not installed in ARM64 arch) -if command -v curl >/dev/null 2>&1; then - # Print the jwt to the dappmanager +post_jwt_to_dappmanager() { + echo "[INFO - entrypoint] Posting JWT to DAppManager" JWT=$(cat "${JWT_PATH}") - curl -X POST "http://my.dappnode/data-send?key=jwt&data=${JWT}" -else - echo "curl is not installed in ARM64 arch. Skipping the JWT post to package info." -fi - -exec besu --rpc-ws-enabled="${WS_ENABLED}" \ - --engine-jwt-secret="${JWT_PATH}" \ - --data-storage-format="${STORAGE_FORMAT}" \ - --sync-mode="${SYNC_MODE}" \ - --rpc-http-max-active-connections="${MAX_HTTP_CONNECTIONS}" \ - --p2p-port="${P2P_PORT}" \ - --network="${NETWORK}" \ - "${EXTRA_OPTS}" + + curl -X POST "http://my.dappnode/data-send?key=jwt&data=${JWT}" || { + echo "[ERROR - entrypoint] JWT could not be posted to package info" + } +} + +run_client() { + echo "[INFO - entrypoint] Running client" + + exec besu --rpc-ws-enabled="${WS_ENABLED}" \ + --engine-jwt-secret="${JWT_PATH}" \ + --data-storage-format="${STORAGE_FORMAT}" \ + --sync-mode="${SYNC_MODE}" \ + --rpc-http-max-active-connections="${MAX_HTTP_CONNECTIONS}" \ + --p2p-port="${P2P_PORT}" \ + --network="${NETWORK}" \ + "${EXTRA_OPTS}" +} + +set_network_specific_config +post_jwt_to_dappmanager +run_client diff --git a/package_variants/holesky/docker-compose.yml b/package_variants/holesky/docker-compose.yml index 9fa3861..e876f11 100644 --- a/package_variants/holesky/docker-compose.yml +++ b/package_variants/holesky/docker-compose.yml @@ -4,6 +4,7 @@ services: build: args: NETWORK: holesky + P2P_PORT: 30415 ports: - 30415:30415/tcp - 30415:30415/udp diff --git a/package_variants/mainnet/docker-compose.yml b/package_variants/mainnet/docker-compose.yml index 365baac..c0380f7 100644 --- a/package_variants/mainnet/docker-compose.yml +++ b/package_variants/mainnet/docker-compose.yml @@ -4,6 +4,7 @@ services: build: args: NETWORK: mainnet + P2P_PORT: 30414 ports: - 30414:30414/tcp - 30414:30414/udp