Files
ethereum-rpc-docker/haqq/scripts/init.sh

65 lines
3.6 KiB
Bash
Executable File

#!/bin/sh
# haqq (haqqd) entrypoint — family C, pure CometBFT (no EL). Thin: sources the
# shared cometbft-common.sh and orchestrates init + statesync bootstrap + start.
# Serves CometBFT RPC :26657 (the dshackle/traefik upstream).
# Genesis replay across ~25 Haqq network upgrades is impractical, so we statesync
# near head with the current binary.
set -e
. /usr/local/bin/cometbft-common.sh
HOME_DIR="/root/.haqqd"
CONFIG_DIR="$HOME_DIR/config"
CHAIN_ID="${CHAINID:-haqq_11235-1}"
CHAINNAME="${CHAINNAME:-mainnet}"
GENESIS_URL="${GENESIS_URL:-https://raw.githubusercontent.com/haqq-network/${CHAINNAME}/master/genesis.json}"
ADDRBOOK_URL="${ADDRBOOK_URL:-https://snapshots.polkachu.com/addrbook/haqq/addrbook.json}"
STATESYNC_RPC="${STATESYNC_RPC:-https://haqq-rpc.polkachu.com:443}"
MIN_GAS="${MIN_GAS:-0.01hqq}"
MONIKER="${MONIKER:-rpc-node}"
# Polkachu seeds + official Haqq network seeds for reliable peer discovery
SEEDS="${SEEDS:-936e27a05f3cfb090507dd810395cbbd8efbffb0@65.109.115.172:24056,f4675b63b8872fb9216efa99428eb5b1fb297393@65.109.104.118:61256,6c9a6fc0e0d94bf303075e46560832e652cffc14@65.108.71.137:24056,7c153a83@peer.haqq.mainnet.dteam.tech:28656}"
# Optional persistent peers for additional bootstrap reliability
PERSISTENT_PEERS="${PERSISTENT_PEERS:-17e0fd08f04e062d18412808b8bf134e9ad34508@65.109.109.189:10656,e000b992a0066eae9e87c66e0d65229a76647509@198.96.92.242:32656,7c153a83@peer.haqq.mainnet.dteam.tech:28656,235ac65359582357b04754e838496545b3ba6429@haqq-seed-1.allnodes.me:26656,9573a569016378765444095484840d7f543d2800@haqq-seed-2.allnodes.me:26656}"
ct_apk curl jq
if haqqd init "$MONIKER" --chain-id "$CHAIN_ID" --home "$HOME_DIR" >/dev/null 2>&1; then
ct_log "fresh init; fetching genesis and addrbook"
ct_fetch "$GENESIS_URL" "$CONFIG_DIR/genesis.json" required
ct_set_addrbook "$CONFIG_DIR" "$ADDRBOOK_URL"
ct_localize_home "$CONFIG_DIR"
ct_set_min_gas_prices "$CONFIG_DIR/app.toml" "$MIN_GAS"
else
ct_log "already initialized, continuing"
# Auto-refresh addrbook from Polkachu when empty on startup
if [ ! -s "$CONFIG_DIR/addrbook.json" ]; then
ct_log "addrbook.json is empty, refreshing from Polkachu"
ct_set_addrbook "$CONFIG_DIR" "$ADDRBOOK_URL"
fi
fi
# Serve RPC on all interfaces (dshackle/traefik upstream); default is 127.0.0.1.
sed -i '/^\[rpc\]/,/^\[/{s|^laddr = .*|laddr = "tcp://0.0.0.0:8545"|}' "$CONFIG_DIR/config.toml"
ct_patch_p2p "$CONFIG_DIR/config.toml" "$IP" "${P2P_PORT:-10465}"
ct_merge_seeds "$CONFIG_DIR/config.toml" "$SEEDS" "$ADDRBOOK_URL"
ct_set_persistent_peers "$CONFIG_DIR/config.toml" "$PERSISTENT_PEERS"
ct_set_moniker "$CONFIG_DIR/config.toml" "$MONIKER"
ct_configure_statesync "$CONFIG_DIR/config.toml" "$STATESYNC_RPC"
ct_seed_priv_validator_state "$HOME_DIR"
# Haqq-specific config: enable API endpoints
sed -i "/^\[json-rpc\]/,/^\[/{s|^address = .*|address = \"0.0.0.0:8545\"|}" "$CONFIG_DIR/app.toml"
sed -i "/^\[json-rpc\]/,/^\[/{s|^ws-address = .*|ws-address = \"0.0.0.0:8546\"|}" "$CONFIG_DIR/app.toml"
sed -i "/^\[json-rpc\]/,/^\[/{s|^metrics-address = .*|metrics-address = \"0.0.0.0:6065\"|}" "$CONFIG_DIR/app.toml"
sed -i "/^\[json-rpc\]/,/^\[/{s|^api = .*|api = \"$API\"|}" "$CONFIG_DIR/app.toml"
# Custom pruning settings for RPC node
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"
exec haqqd start --chain-id "$CHAIN_ID" --home "$HOME_DIR" $@