MDK Logo

Run an Antspace Worker

Start an MDK Worker for a Bitmain Antspace container.

TL;DR

Run mdk run from your project folder (holding mdk.yaml). Runtime: mdk run, which writes the Kernel key to .mdk/kernel.key, or a host script, which writes it to ~/.mdk/.kernel-key wherever you run it.

  • Under mdk run, mock: true starts the Worker's own mock; a host script needs npm run mock hk3 18001, run from the repository root
  • Check the device reports telemetry with curl through the Gateway: READY proves the Worker registered, not that its device answers

Overview

This page details how to run the Bitmain Antspace container Worker. The package is a directory-loaded Worker Plugin (mdk-contract.json plus handler files) that mdk run hosts from mdk.yaml, or that your own Node.js service hosts on WorkerRuntimeV2. Select the development (mock) or real-container path.

Prerequisites

Deployment-specific requirements:

  • An MDK project with mdk.yaml (mdk onboard), or a Node.js service or script in your deployment that hosts the Worker. @tetherto/mdk-worker-antspace is not published to npm, so the package resolves only through the workspace of an MDK repository clone after npm install at its root: keep the project or script inside that clone
  • A supported Antspace container reachable from the machine or container running the Worker over its REST HTTP API, typically port 8000

Development

Run against a mock

The Antspace Worker ships a mock container that answers its HTTP API with canned data. Declare the Worker under spec.workers in the mdk.yaml mdk onboard wrote, replacing any entry onboarding seeded for it, with mock: true, and mdk run starts one mock per device, on the port each device names:

spec:
  workers:
    - name: antspace
      package: '@tetherto/mdk-worker-antspace'
      config:
        mock: true
        devices:
          - id: HK3-DEV
            opts: { address: 127.0.0.1, port: 18001, model: hk3 }
mdk run

Expected output includes a line for the Worker, with your own key:

✔ worker antspace ready 7473f43be06d59af

A warning that the Worker may be missing device options can print with it: Worker troubleshooting covers what it checks.

Check the stack from a second terminal in the project directory:

mdk status

Expected output ends with:

  WORKER    REGISTERED  STATE  HEALTH   DEVICES
  antspace  yes         READY  HEALTHY  1

✔ Health: healthy

READY and HEALTHY prove the Worker registered, not that its device answers: what a healthy run shows covers the difference. To see a reading, check the device reports telemetry.

To host the Worker yourself instead of with mdk run, stop mdk run first, since its mock holds the same port. Then run the mock in one terminal and a host script in a second, both from the repository root:

  1. Start a mock HK3 container:

    npm run mock hk3 18001
  2. Save this script as antspace-dev.js in the repository root. It is the boot call from Connect a container, pointed at 127.0.0.1:

    'use strict'
    
    const os = require('os')
    const path = require('path')
    const { getKernel } = require('@tetherto/mdk-core')
    const { WorkerRuntimeV2 } = require('@tetherto/mdk-worker')
    
    const main = async () => {
      const kernel = await getKernel({ handleSignals: true })
    
      const runtime = new WorkerRuntimeV2(path.dirname(require.resolve('@tetherto/mdk-worker-antspace/package.json')), {
        workerId: 'antspace-dev',
        storeDir: path.join(os.tmpdir(), 'mdk-dev', 'antspace'),
        allowedKeys: [kernel.getClientPublicKey()],
        devices: [{ deviceId: 'HK3-DEV', config: { address: '127.0.0.1', port: 18001, model: 'hk3' } }]
      })
      await runtime.start()
      const registration = await kernel.registerWorker(runtime.getPublicKey())
      if (!registration.registered) throw new Error(`Worker not registered: ${registration.error}`)
      kernel._cleanup.push(() => runtime.stop()) // Ctrl+C stops the Worker before the Kernel
    
      console.log('Worker registered:', registration.workerId)
      console.log('Kernel HRPC key:', kernel.getPublicKey().toString('hex'))
      console.log('Ctrl+C to stop.')
    }
    
    main().catch((err) => { console.error(err); process.exit(1) })
  3. Run the script in a second terminal:

    node antspace-dev.js

Expected output, with your own key:

Worker registered: antspace-dev
Kernel HRPC key: de61f30cd7bd65923d9c8089e4fa684335a37371600e1610823a4fc20aba0247
Ctrl+C to stop.

A Kernel that refuses the Worker stops the script with Error: Worker not registered: <error> and a stack trace instead: Worker troubleshooting covers each error.

Ctrl+C stops the Worker, then the Kernel; stop the services cleanly covers the contract. Stop the mock with Ctrl+C in its own terminal when you are done; nothing else stops it.

Either way, the Worker serves live telemetry (temperatures, cooling status) from the mock. In the host script, the telemetry check reads it. The mock's model and port options are in the Antspace README.

The Kernel keeps its state in ~/.mdk, wherever you run a host script: its store, its trusted keys, and its key in ~/.mdk/.kernel-key. To run more than one Kernel on a machine, keep each one's state next to its Worker's.

Keep the Kernel's state next to the Worker's

Pass the Kernel a root and key file under the same temp folder as the Worker's store:

const kernelRoot = path.join(os.tmpdir(), 'mdk-dev', 'antspace-kernel')
const kernel = await getKernel({
  handleSignals: true,
  root: kernelRoot,
  keyFile: path.join(kernelRoot, '.kernel-key')
})

A Gateway in another process needs this keyFile and trustedKeysDir: path.join(kernelRoot, '.trusted-keys'); one started in the same process with kernel needs neither. The telemetry check in Worker troubleshooting spreads its own root and keyFile: false into getKernel(), so use it or this change, not both.

Connect a container

2.1 Pick your model

Use the Antspace README to confirm the model value for your container: hk3 or immersion. This guide uses hk3, replace it with the value for your container.

2.2 Declare your container

Point the mdk.yaml entry at the real container and drop mock:

spec:
  workers:
    - name: antspace
      package: '@tetherto/mdk-worker-antspace'
      config:
        devices:
          - id: HK3-A
            opts: { address: 192.168.1.100, port: 8000, model: hk3 }

Without mdk run, add this to the Node.js service or script that hosts the Worker. The snippet declares one Antspace container; replace the example address and port with your container's values:

const path = require('path')
const { getKernel } = require('@tetherto/mdk-core')
const { WorkerRuntimeV2 } = require('@tetherto/mdk-worker')

const main = async () => {
  const kernel = await getKernel()

  const runtime = new WorkerRuntimeV2(path.dirname(require.resolve('@tetherto/mdk-worker-antspace/package.json')), {
    workerId: 'antspace-rack-1',
    storeDir: './store/antspace-rack-1',
    allowedKeys: [kernel.getClientPublicKey()],
    devices: [{ deviceId: 'HK3-A', config: { address: '192.168.1.100', port: 8000, model: 'hk3' } }]
  })
  await runtime.start()
  const registration = await kernel.registerWorker(runtime.getPublicKey())
  if (!registration.registered) throw new Error(`Worker not registered: ${registration.error}`)
}

main().catch((err) => { console.error(err); process.exit(1) })

allowedKeys lists the RPC callers the Worker accepts. The Worker refuses to start without it (ERR_WORKER_ALLOWED_KEYS_REQUIRED), so pass the Kernel's client key.

Make sure each container's address is reachable from the machine or container running the Worker before registering. Commands affect live cooling for racks of miners, prioritize thermal safety.

The device list is fixed at construction. There is no registerThing/updateThing/forgetThings equivalent: adding, updating, or removing a container means editing the device list and restarting the Worker.

The full device option reference, the telemetry and command tables, and the shared install pattern are in the Antspace README and the install pattern.

Check the device reports telemetry

Under mdk run, add the telemetry route to an app once, sign in, then read the device from a second terminal:

curl -sS -H "Authorization: Bearer $TOKEN" http://localhost:3847/apps/fleet/api/fleet/devices/HK3-DEV/telemetry

Expected output against the mock, with your own values, shortened:

{"deviceId":"HK3-DEV","metrics":{"inlet_temp":49,"outlet_temp":43,"liquid_supply_temp":35,"cooling_status":"running",...

For a real container, put its device ID, HK3-A, in the path.

In a script that boots your Kernel, add the telemetry check instead. In antspace-dev.js, call it after the line that prints the Kernel key:

const { checkKernelOpts, checkTelemetry } = require('./check-telemetry')

const kernel = await getKernel({ handleSignals: true, ...checkKernelOpts })
// ...
console.log('Kernel HRPC key:', kernel.getPublicKey().toString('hex'))
await checkTelemetry(kernel, 'HK3-DEV')
console.log('Ctrl+C to stop.')

For a real container, make the same change to the script from Connect a container and pass its device ID, HK3-A.

Expected output against the mock, with your own key and values:

Worker registered: antspace-dev
Kernel HRPC key: 10a8ff609ec4954cabb359fa04e09cc7041558aa269a33970e5e416ac583ed82
Telemetry from HK3-DEV:
  inlet_temp: 49
  outlet_temp: 43
  liquid_supply_temp: 35
  cooling_status: running
Ctrl+C to stop.

An error instead of a value? Read a failed check.

Troubleshooting

An unreachable container doesn't fail at load time: the Worker reports the device online and the failure surfaces as ERR_CONTAINER_UNREACHABLE inside the telemetry channel or command response that touched the network. If the Worker doesn't come up, or a mock port is already in use, the network and port checks in Worker troubleshooting apply here too: the underlying HRPC and DHT requirements are the same across every Worker.

If you replace a Worker after deleting its storeDir, the Kernel may still hold its old key or device bindings. An authorized client can call terminateWorker(oldWorkerId) to release those bindings before registering the replacement. See Worker bindings.

Next steps

On this page