haqq: fix bootstrap config - correct addrbook filename, add Polkachu seeds, persistent peers, auto-refresh from Polkachu when empty

This commit is contained in:
2026-08-04 10:28:18 +00:00
parent 3be855a681
commit 223c694085
2 changed files with 271 additions and 47 deletions

95
haqq/scripts/init.sh Normal file → Executable file
View File

@@ -1,64 +1,65 @@
#!/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
set -e # Exit on failure
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}"
echo "MONIKER: $MONIKER"
# 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}"
CHAINID=${CHAINID:-haqq_11235-1}
CHAINNAME=${CHAINNAME:-mainnet}
API=${API:-eth,net,web3}
# Optional persistent peers for additional bootstrap reliability
PERSISTENT_PEERS="${PERSISTENT_PEERS:-17e0fd08f04e062d18412808b8bf134e9ad34508@65.109.109.189:10656,e000b992a0066eae9e87c66e0d65229a76647509@198.96.92.242:32656}"
CONFIG_DIR="/root/.haqqd/config"
ct_apk curl jq
# Create config directory
mkdir -p "$CONFIG_DIR"
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"
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
echo "Already initialized, continuing!" >&2
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"
# 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
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"
# Update moniker if set
if [ -n "$MONIKER" ] && [ -f "$CONFIG_DIR/config.toml" ]; then
sed -i "s/^moniker = \".*\"/moniker = \"$MONIKER\"/" "$CONFIG_DIR/config.toml"
fi
# 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 ${CHAINID} $@
exec haqqd start --chain-id "$CHAIN_ID" --home "$HOME_DIR" $@