From e433d44a9383748fddf385032d17d01bac502b9d Mon Sep 17 00:00:00 2001 From: goldsquid Date: Sun, 23 Nov 2025 13:24:57 +0700 Subject: [PATCH] generalize haqq initialization --- haqq/haqq.Dockerfile | 9 ++++ haqq/haqq/haqq-mainnet-haqq-pruned.yml | 22 +++++++-- haqq/scripts/init.sh | 63 ++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 haqq/haqq.Dockerfile create mode 100644 haqq/scripts/init.sh diff --git a/haqq/haqq.Dockerfile b/haqq/haqq.Dockerfile new file mode 100644 index 00000000..d21a34d3 --- /dev/null +++ b/haqq/haqq.Dockerfile @@ -0,0 +1,9 @@ +ARG HAQQ_HAQQ_IMAGE +ARG HAQQ_HAQQ_VERSION +FROM ${HAQQ_HAQQ_IMAGE}:${HAQQ_HAQQ_VERSION} + +COPY ./scripts/init.sh /usr/local/bin/init.sh + +RUN chmod +x /usr/local/bin/init.sh + +ENTRYPOINT [ "init.sh" ] \ No newline at end of file diff --git a/haqq/haqq/haqq-mainnet-haqq-pruned.yml b/haqq/haqq/haqq-mainnet-haqq-pruned.yml index 24a18cb3..5cb5c6cf 100644 --- a/haqq/haqq/haqq-mainnet-haqq-pruned.yml +++ b/haqq/haqq/haqq-mainnet-haqq-pruned.yml @@ -30,7 +30,12 @@ x-logging-defaults: &logging-defaults services: haqq-mainnet: - image: ${HAQQ_HAQQ_IMAGE:-alhaqq/haqq}:${HAQQ_MAINNET_HAQQ_VERSION:-v1.9.1} + build: + context: ./haqq + dockerfile: haqq.Dockerfile + args: + HAQQ_HAQQ_VERSION: ${HAQQ_MAINNET_HAQQ_VERSION:-v1.8.5} + HAQQ_HAQQ_IMAGE: ${HAQQ_MAINNET_HAQQ_IMAGE:-alhaqq/haqq} sysctls: # TCP Performance net.ipv4.tcp_slow_start_after_idle: 0 # Disable slow start after idle @@ -51,18 +56,24 @@ services: expose: - 8545 - 8546 - entrypoint: [haqqd, start] - command: --p2p.laddr=tcp://0.0.0.0:10465 + - 6065 + environment: + - IP=${IP} + - MONIKER=d${DOMAIN:-local} + - P2P_PORT=10465 restart: unless-stopped stop_grace_period: 5m networks: - chains volumes: - - ${HAQQ_MAINNET_HAQQ_PRUNED_DATA:-haqq-mainnet-haqq-pruned}:/root/.haqqd + - ${HAQQ_MAINNET_HAQQ_PRUNED_DATA:-haqq-mainnet-haqq-pruned}:/root/.haqqd/data - /slowdisk:/slowdisk + - haqq-mainnet-haqq-pruned_config:/root/.haqqd/config logging: *logging-defaults labels: - - prometheus-scrape.enabled=false + - prometheus-scrape.enabled=true + - prometheus-scrape.port=6065 + - prometheus-scrape.path=/metrics - traefik.enable=true - traefik.http.middlewares.haqq-mainnet-haqq-pruned-stripprefix.stripprefix.prefixes=/haqq-mainnet - traefik.http.services.haqq-mainnet-haqq-pruned.loadbalancer.server.port=8545 @@ -84,6 +95,7 @@ services: volumes: haqq-mainnet-haqq-pruned: + haqq-mainnet-haqq-pruned_config: x-upstreams: - id: $${ID} diff --git a/haqq/scripts/init.sh b/haqq/scripts/init.sh new file mode 100644 index 00000000..7902d7c6 --- /dev/null +++ b/haqq/scripts/init.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +set -e # Exit on failure + +echo "MONIKER: $MONIKER" + +CHAINID=${CHAINID:-haqq_11235-1} +CHAINNAME=${CHAINNAME:-mainnet} + +CONFIG_DIR="/root/.haqqd/config" + +# Create config directory +mkdir -p "$CONFIG_DIR" + +JWTSECRET="$(cat /jwtsecret)" # needs to go to the config dir (default path) +P2P_STRING="tcp:\\/\\/0\\.0\\.0\\.0\\:${P2P_PORT:-10465}" +NAT_STRING="${IP}:${P2P_PORT:-10465}" + +env + +# this goes first because it won't overwrite shit +apk add curl +if [ $? -ne 0 ]; then exit 1; fi + +if haqqd init ${MONIKER} --chain-id ${CHAINID} --home /root/.haqqd/; then + # Define variables + GENESIS_URL="https://raw.githubusercontent.com/haqq-network/${CHAINNAME}/master/genesis.json" + ADDRESSBOOK_URL="https://raw.githubusercontent.com/haqq-network/${CHAINNAME}/master/addrbook.json" + + # Download config files + curl -sL "$GENESIS_URL" -o "$CONFIG_DIR/genesis.json" + curl -sL "$ADDRESSBOOK_URL" -o "$CONFIG_DIR/addressbook.json" + + # somehow it's better to make home static to /root + sed -i 's|~/|/root/|g' "$CONFIG_DIR/config.toml" + sed -i 's|~/|/root/|g' "$CONFIG_DIR/app.toml" +else + echo "Already initialized, continuing!" >&2 +fi + + +# apply a port change to the config +sed -i "/^\[p2p\]/,/^\[/{s|^laddr = .*|laddr = \"$P2P_STRING\"|}" "$CONFIG_DIR/config.toml" +#sed -i "s/^laddr = \".*\"/laddr = \"$P2P_STRING\"/" "$CONFIG_DIR/config.toml" +sed -i "/^\[p2p\]/,/^\[/{s|^external_address = .*|external_address = \"$NAT_STRING\"|}" "$CONFIG_DIR/config.toml" + +#sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.01hqq"/g' $CONFIG_DIR/app.toml + +sed -i -e "s/^pruning *=.*/pruning = \"custom\"/" $CONFIG_DIR/app.toml +sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" $CONFIG_DIR/app.toml +sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"19\"/" $CONFIG_DIR/app.toml +sed -i -e "s/^indexer *=.*/indexer = \"null\"/" $CONFIG_DIR/config.toml + +sed -i "/^\[json-rpc\]/,/^\[/{s|^address = .*|address = \"tcp://0.0.0.0:8545\"|}" "$CONFIG_DIR/app.toml" +sed -i "/^\[json-rpc\]/,/^\[/{s|^ws-address = .*|ws-address = \"tcp://0.0.0.0:8546\"|}" "$CONFIG_DIR/app.toml" +sed -i "/^\[json-rpc\]/,/^\[/{s|^metrics-address = .*|metrics-address = \"tcp://0.0.0.0:6065\"|}" "$CONFIG_DIR/app.toml" + +# Update moniker if set +if [ -n "$MONIKER" ] && [ -f "$CONFIG_DIR/config.toml" ]; then + sed -i "s/^moniker = \".*\"/moniker = \"$MONIKER\"/" "$CONFIG_DIR/config.toml" +fi + +exec haqqd start --chain-id ${CHAINID} $@