Auto-detect public IP for ElectrumX peer announcement

This commit is contained in:
2026-02-13 09:33:58 +01:00
parent f631edfc4d
commit 4f528f8a1e
3 changed files with 22 additions and 2 deletions

View File

@@ -1,5 +1,8 @@
FROM lukechilds/electrumx
# Install curl (needed by entrypoint for RPC calls and IP detection)
RUN apk add --no-cache curl || apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
# Copy Palladium coin definition and patch ElectrumX
COPY electrumx-patch/coins_plm.py /tmp/coins_plm.py

View File

@@ -59,8 +59,8 @@ services:
DB_DIRECTORY: "/data"
PEER_DISCOVERY: "on"
PEER_ANNOUNCE: "true"
# Set this to the server's public IP or hostname (required for peer discovery)
# REPORT_HOST: "your.public.ip.or.hostname"
# REPORT_SERVICES is auto-detected at startup. Set manually only to override.
# REPORT_SERVICES: "tcp://your.public.ip:50001,ssl://your.public.ip:50002"
INITIAL_CONCURRENT: "2"
COST_SOFT_LIMIT: "0"
COST_HARD_LIMIT: "0"

View File

@@ -43,6 +43,22 @@ fi
# Build DAEMON_URL with extracted credentials
export DAEMON_URL="http://${RPC_USER}:${RPC_PASSWORD}@palladiumd:${RPC_PORT}/"
# Auto-detect public IP and set REPORT_SERVICES for peer discovery
if [ -z "$REPORT_SERVICES" ]; then
echo "REPORT_SERVICES not set, detecting public IP..."
for url in https://icanhazip.com https://ifconfig.me https://api.ipify.org; do
PUBLIC_IP=$(curl -sf --max-time 5 "$url" 2>/dev/null | tr -d '[:space:]')
if [ -n "$PUBLIC_IP" ]; then
export REPORT_SERVICES="tcp://${PUBLIC_IP}:50001,ssl://${PUBLIC_IP}:50002"
echo ">> Auto-detected REPORT_SERVICES: ${REPORT_SERVICES}"
break
fi
done
if [ -z "$REPORT_SERVICES" ]; then
echo ">> WARNING: Could not detect public IP. Peer discovery will not announce this server."
fi
fi
echo "=========================================="
echo "ElectrumX Configuration"
echo "=========================================="
@@ -51,6 +67,7 @@ echo "Network: ${NET}"
echo "RPC User: ${RPC_USER}"
echo "RPC Port: ${RPC_PORT}"
echo "DAEMON_URL: http://${RPC_USER}:***@palladiumd:${RPC_PORT}/"
echo "REPORT_SERVICES: ${REPORT_SERVICES:-not set}"
echo "=========================================="
# Update TX_COUNT / TX_COUNT_HEIGHT in coins.py from the live node