Skip to content

Commit 96d332d

Browse files
Merge pull request #41 from backend-developers-ltd/ihm-miner-fixups
Allow configuration of worker_id overrides in IHP miner installer
2 parents 0b839a9 + edc9938 commit 96d332d

2 files changed

Lines changed: 84 additions & 6 deletions

File tree

installer/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ An installer for the APS miner (APScheduler-based miner) is also available:
6666
curl -s https://raw.githubusercontent.com/backend-developers-ltd/InfiniteHash/refs/heads/deploy-config-prod/installer/miner_install.sh | bash
6767
```
6868

69-
This script prompts for `WORKING_DIRECTORY` (default: `~/InfiniteHash-miner/`), then prompts for TOML configuration values and proxy mode. Worker configuration uses v2 grouped input (`hashratePHxcount`, e.g. `0.45x10,0.25x4`) and is written to `[workers.worker_sizes]` in `config.toml`. The installer then deploys the miner stack with Docker Compose and installs a cron job that keeps the compose file up to date by calling `installer/update_miner_compose.sh`.
69+
This script prompts for `WORKING_DIRECTORY` (default: `~/InfiniteHash-miner/`), then prompts for TOML configuration values and proxy mode. Wallet directory prompt is host-side (used for local hotkey lookup), while `config.toml` wallet directory is normalized for container runtime (`/root/.bittensor/wallets`). Worker configuration uses v2 grouped input (`hashratePHxcount`, e.g. `0.45x10,0.25x4`) and is written to `[workers.worker_sizes]` in `config.toml`. The installer then deploys the miner stack with Docker Compose and installs a cron job that keeps the compose file up to date by calling `installer/update_miner_compose.sh`.
7070

7171
For `ihp` mode, default proxy template files (`proxy/.env` and `proxy/pools.toml`) are generated directly by the installer script (inline templates), not downloaded from external template files.
7272

@@ -82,7 +82,7 @@ In `braiins` mode, the installer provisions Braiins Farm Proxy (`farm-proxy` and
8282
- APS miner updates subnet allocation by pool `name` in `proxy/pools.toml` (`[[pools.main]]` entry), not by host/port.
8383
- The miner container uses `APS_MINER_SUBNET_POOL_NAME` (default: `central-proxy`) to select which pool gets absolute `target_hashrate`.
8484
- The selected pool name must exist in `proxy/pools.toml`; otherwise no subnet target update is applied.
85-
- During installation, if `proxy/pools.toml` does not exist yet, the script asks for backup/private pool host/port and writes those values to `pools.backup`.
85+
- During installation, if `proxy/pools.toml` does not exist yet, the script asks for backup/private pool host/port, optional backup `worker_id` override, and for `central-proxy` asks whether to use suggested identity format or set `worker_id` manually (manual input may be empty for no override), then writes provided values to `pools.backup`/`[[pools.main]]`.
8686
- Installer default sets `[extranonce].extranonce2_size = 2`.
8787
- After updating `proxy/pools.toml`, APS miner touches reload sentinel `APS_MINER_IHP_RELOAD_SENTINEL` (default: `/root/src/proxy/.reload-ihp`); sidecar `ihp-proxy-reloader` then runs `kill -HUP 1` in `ihp-proxy` PID namespace.
8888

installer/miner_install.sh

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ fi
1313
GITHUB_URL="https://raw.githubusercontent.com/backend-developers-ltd/InfiniteHash/refs/heads"
1414
MAX_V2_WORKER_SIZE_PH="0.45"
1515
MAX_V2_TOTAL_WORKERS=1000
16+
DEFAULT_HOST_WALLET_DIRECTORY="${HOME}/.bittensor/wallets"
17+
CONTAINER_WALLET_DIRECTORY="/root/.bittensor/wallets"
1618

1719
mkdir -p "${WORKING_DIRECTORY}"
1820
WORKING_DIRECTORY=$(realpath "${WORKING_DIRECTORY}")
@@ -49,6 +51,8 @@ write_default_ihp_pools() {
4951
local destination="$1"
5052
local backup_pool_host="$2"
5153
local backup_pool_port="$3"
54+
local backup_pool_worker_id="${4:-}"
55+
local main_pool_worker_id="${5:-}"
5256

5357
cat > "${destination}" <<EOL
5458
[pools]
@@ -57,12 +61,29 @@ write_default_ihp_pools() {
5761
name = "private-backup"
5862
host = "${backup_pool_host}"
5963
port = ${backup_pool_port}
64+
EOL
65+
66+
if [ -n "${backup_pool_worker_id}" ]; then
67+
cat >> "${destination}" <<EOL
68+
worker_id = "${backup_pool_worker_id}"
69+
EOL
70+
fi
6071

72+
cat >> "${destination}" <<EOL
6173
[[pools.main]]
6274
name = "central-proxy"
6375
host = "stratum.infinitehash.xyz"
6476
port = 9332
6577
weight = 1
78+
EOL
79+
80+
if [ -n "${main_pool_worker_id}" ]; then
81+
cat >> "${destination}" <<EOL
82+
worker_id = "${main_pool_worker_id}"
83+
EOL
84+
fi
85+
86+
cat >> "${destination}" <<EOL
6687
6788
[extranonce]
6889
extranonce2_size = 2
@@ -94,8 +115,9 @@ if [ ! -f "${CONFIG_FILE}" ]; then
94115
BITTENSOR_NETUID=${BITTENSOR_NETUID:-89}
95116
BITTENSOR_NETUID=$(echo "${BITTENSOR_NETUID}" | tr -d '[:space:]')
96117

97-
read -r -p "Enter BITTENSOR_WALLET_DIRECTORY [~/.bittensor/wallets]: " BITTENSOR_WALLET_DIRECTORY </dev/tty
98-
BITTENSOR_WALLET_DIRECTORY=${BITTENSOR_WALLET_DIRECTORY:-~/.bittensor/wallets}
118+
read -r -p "Enter host BITTENSOR_WALLET_DIRECTORY [${DEFAULT_HOST_WALLET_DIRECTORY}]: " HOST_WALLET_DIRECTORY </dev/tty
119+
HOST_WALLET_DIRECTORY=${HOST_WALLET_DIRECTORY:-${DEFAULT_HOST_WALLET_DIRECTORY}}
120+
BITTENSOR_WALLET_DIRECTORY="${CONTAINER_WALLET_DIRECTORY}"
99121

100122
read -r -p "Enter BITTENSOR_WALLET_NAME [default]: " BITTENSOR_WALLET_NAME </dev/tty
101123
BITTENSOR_WALLET_NAME=${BITTENSOR_WALLET_NAME:-default}
@@ -235,6 +257,13 @@ else
235257
BITTENSOR_WALLET_NAME=${BITTENSOR_WALLET_NAME:-$(parse_toml_value "wallet" "name")}
236258
BITTENSOR_WALLET_HOTKEY_NAME=${BITTENSOR_WALLET_HOTKEY_NAME:-$(parse_toml_value "wallet" "hotkey_name")}
237259
BITTENSOR_WALLET_DIRECTORY=${BITTENSOR_WALLET_DIRECTORY:-$(parse_toml_value "wallet" "directory")}
260+
HOST_WALLET_DIRECTORY=${HOST_WALLET_DIRECTORY:-${BITTENSOR_WALLET_DIRECTORY}}
261+
262+
if [ "${BITTENSOR_WALLET_DIRECTORY}" != "${CONTAINER_WALLET_DIRECTORY}" ]; then
263+
echo "Updating wallet directory in ${CONFIG_FILE} for container runtime: ${BITTENSOR_WALLET_DIRECTORY} -> ${CONTAINER_WALLET_DIRECTORY}"
264+
sed -i "/^\\[wallet\\]/,/^\\[/{s|^directory = \".*\"|directory = \"${CONTAINER_WALLET_DIRECTORY}\"|}" "${CONFIG_FILE}"
265+
BITTENSOR_WALLET_DIRECTORY="${CONTAINER_WALLET_DIRECTORY}"
266+
fi
238267
fi
239268

240269
expand_path() {
@@ -248,8 +277,19 @@ expand_path() {
248277
fi
249278
}
250279

251-
WALLET_DIR_EXPANDED=$(expand_path "${BITTENSOR_WALLET_DIRECTORY}")
280+
if [ -z "${HOST_WALLET_DIRECTORY:-}" ] || [ "${HOST_WALLET_DIRECTORY}" = "${CONTAINER_WALLET_DIRECTORY}" ]; then
281+
HOST_WALLET_DIRECTORY="${DEFAULT_HOST_WALLET_DIRECTORY}"
282+
fi
283+
284+
WALLET_DIR_EXPANDED=$(expand_path "${HOST_WALLET_DIRECTORY}")
252285
HOTKEY_PUB_FILE="${WALLET_DIR_EXPANDED}/${BITTENSOR_WALLET_NAME}/hotkeys/${BITTENSOR_WALLET_HOTKEY_NAME}pub.txt"
286+
if [ ! -f "${HOTKEY_PUB_FILE}" ]; then
287+
FALLBACK_WALLET_DIR="${HOME}/.bittensor/wallets"
288+
FALLBACK_HOTKEY_PUB_FILE="${FALLBACK_WALLET_DIR}/${BITTENSOR_WALLET_NAME}/hotkeys/${BITTENSOR_WALLET_HOTKEY_NAME}pub.txt"
289+
if [ -f "${FALLBACK_HOTKEY_PUB_FILE}" ]; then
290+
HOTKEY_PUB_FILE="${FALLBACK_HOTKEY_PUB_FILE}"
291+
fi
292+
fi
253293
HOTKEY_SS58=""
254294
if [ -f "${HOTKEY_PUB_FILE}" ]; then
255295
HOTKEY_SS58=$(sed -n 's/.*"ss58Address":"\([^"]*\)".*/\1/p' "${HOTKEY_PUB_FILE}")
@@ -309,7 +349,28 @@ if [ "${PROXY_MODE}" = "ihp" ]; then
309349
PRIVATE_POOL_PORT=${PRIVATE_POOL_PORT:-${DEFAULT_PRIVATE_POOL_PORT}}
310350
PRIVATE_POOL_PORT=$(echo "${PRIVATE_POOL_PORT}" | tr -d '[:space:]')
311351

312-
write_default_ihp_pools "${NEW_PROXY_POOLS_FILE}" "${PRIVATE_POOL_HOST}" "${PRIVATE_POOL_PORT}"
352+
read -r -p "Enter IHP backup/private pool worker ID override (optional) []: " PRIVATE_POOL_WORKER_ID </dev/tty
353+
PRIVATE_POOL_WORKER_ID=$(echo "${PRIVATE_POOL_WORKER_ID}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
354+
355+
DEFAULT_MAIN_POOL_WORKER_ID="sn${BITTENSOR_NETUID}auction.${HOTKEY_IDENTIFIER}.worker1"
356+
echo ""
357+
echo "Configure IHP central-proxy worker ID override:"
358+
echo " 1) Use suggested value (${DEFAULT_MAIN_POOL_WORKER_ID})"
359+
echo " 2) Set manually (leave empty for no override)"
360+
read -r -p "Selection [1]: " MAIN_POOL_WORKER_ID_MODE </dev/tty
361+
MAIN_POOL_WORKER_ID_MODE=${MAIN_POOL_WORKER_ID_MODE:-1}
362+
363+
case "${MAIN_POOL_WORKER_ID_MODE}" in
364+
2)
365+
read -r -p "Enter IHP central-proxy worker ID override (optional) []: " MAIN_POOL_WORKER_ID </dev/tty
366+
MAIN_POOL_WORKER_ID=$(echo "${MAIN_POOL_WORKER_ID}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
367+
;;
368+
*)
369+
MAIN_POOL_WORKER_ID="${DEFAULT_MAIN_POOL_WORKER_ID}"
370+
;;
371+
esac
372+
373+
write_default_ihp_pools "${NEW_PROXY_POOLS_FILE}" "${PRIVATE_POOL_HOST}" "${PRIVATE_POOL_PORT}" "${PRIVATE_POOL_WORKER_ID}" "${MAIN_POOL_WORKER_ID}"
313374
else
314375
echo "Using existing InfiniteHash Proxy pools file at ${NEW_PROXY_POOLS_FILE}"
315376
fi
@@ -406,6 +467,23 @@ if ! /tmp/update_miner_compose.sh "${ENV_NAME}" "${WORKING_DIRECTORY}"; then
406467
fi
407468
echo "update_miner_compose.sh ran successfully."
408469

470+
echo "Pulling latest images and recreating services..."
471+
if command -v docker &> /dev/null && docker compose version &> /dev/null; then
472+
if ! (cd "${WORKING_DIRECTORY}" && docker compose pull && docker compose up -d --remove-orphans); then
473+
echo "Error: docker compose pull/up failed."
474+
exit 1
475+
fi
476+
elif command -v docker-compose &> /dev/null; then
477+
if ! (cd "${WORKING_DIRECTORY}" && docker-compose pull && docker-compose up -d --remove-orphans); then
478+
echo "Error: docker-compose pull/up failed."
479+
exit 1
480+
fi
481+
else
482+
echo "Error: Neither docker compose nor docker-compose is available."
483+
exit 1
484+
fi
485+
echo "Latest images applied successfully."
486+
409487
CRON_CMD="*/15 * * * * cd ${WORKING_DIRECTORY} && curl -s ${GITHUB_URL}/deploy-config-${ENV_NAME}/installer/update_miner_compose.sh > /tmp/update_miner_compose.sh && chmod +x /tmp/update_miner_compose.sh && /tmp/update_miner_compose.sh ${ENV_NAME} ${WORKING_DIRECTORY} # INFINITE_HASH_APS_MINER_UPDATE"
410488

411489
(crontab -l 2>/dev/null || echo "") | grep -v "INFINITE_HASH_APS_MINER_UPDATE" | { cat; echo "${CRON_CMD}"; } | crontab -

0 commit comments

Comments
 (0)