Skip to content

Commit

Permalink
Handle P2P port on compose files
Browse files Browse the repository at this point in the history
  • Loading branch information
dappnodedev committed Jun 27, 2024
1 parent 1fff815 commit ca2b6c0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 38 deletions.
7 changes: 5 additions & 2 deletions besu/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down
80 changes: 44 additions & 36 deletions besu/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions package_variants/holesky/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
build:
args:
NETWORK: holesky
P2P_PORT: 30415
ports:
- 30415:30415/tcp
- 30415:30415/udp
Expand Down
1 change: 1 addition & 0 deletions package_variants/mainnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
build:
args:
NETWORK: mainnet
P2P_PORT: 30414
ports:
- 30414:30414/tcp
- 30414:30414/udp
Expand Down

0 comments on commit ca2b6c0

Please sign in to comment.