DIM · Dagon Inference Marketplace

Run an indexer

services/discovery is a Bun and SQLite indexer. It never probes sellers on the serving path: a background crawler fetches pinned sellers' listings and capacity, operators push observations, and every response is signed.

1. Attestation key

Generate a separate 32-byte seed as a 64-character hex file, with the same private-file procedure as an operator key (run a prober), for example at /var/lib/im-discovery/attestation.seed. Publish its public key out of band; clients pin it.

2. indexer.json

{
  "attestationKeyFile": "/var/lib/im-discovery/attestation.seed",
  "database": "/var/lib/im-discovery/routes.sqlite",
  "sellers": [{"origin":"https://seller.example","seller":"SELLER_LISTING_PUBKEY"}],
  "operators": ["OPERATOR_PUBKEY"],
  "hostname": "127.0.0.1",
  "port": 8700,
  "crawlIntervalMs": 30000,
  "crawlConcurrency": 64,
  "timeoutMs": 5000
}
Field Default Meaning
attestationKeyFile required Hex seed file.
database required SQLite path. Use WAL on local storage, not a network filesystem.
sellers required, ≤ 1,000 {origin, seller, completionOrigins?}: each pinned seller origin and listing key. This list is registration.
operators required, ≤ 32 Allowlisted probe operator keys.
hostname, port 127.0.0.1, 8700 Listener; put TLS in front.
crawlIntervalMs 30,000 Pause between crawl rounds.
crawlConcurrency 64 (1–128) Sellers crawled in parallel; one timeout covers both fetches per seller.
timeoutMs 5,000 (1–60,000) Per-seller crawl timeout.
signWorkers max(1, min(8, CPUs − 1)), 1–32 Signing worker pool for list pages.
mcpOrigins [] Browser origins allowed to call /mcp.
workerSigner unset {"module": "./kms-signer.ts", "options": "key-handle"}: a trusted local async signer, path relative to the config. The same key must still be in attestationKeyFile; remote-only keys are unsupported.

Startup rejects a fleet where ceil(sellers / crawlConcurrency) × timeoutMs + crawlIntervalMs ≥ 120,000 ms, because capacity would expire between crawls. Key and database paths are used as given (relative to the working directory); use absolute paths.

3. Run it

bun services/discovery/src/cli.ts http /etc/im-discovery/indexer.json

Wait for discovery listening: workers are warmed and the socket is bound. For local MCP clients, bun services/discovery/src/cli.ts stdio /etc/im-discovery/indexer.json serves MCP over standard I/O (stdout is reserved for MCP).

Behind TLS:

  • forward /v1/routes, /v1/routes/*, /v1/price-history, /v1/observations, /.well-known/im-indexer.json and /mcp;
  • use a 1 MiB proxy body limit so the application can enforce, and sign, its own 16 KiB limit on /v1/observations and /mcp;
  • set a request and header deadline (for example 10 s), and rate-limit observations per source (start at 30 per minute, burst 10);
  • keep idle upstream connection reuse at 10 s or less.

4. Verify the deployment

curl -s https://discovery.example/.well-known/im-indexer.json
curl -s 'https://discovery.example/v1/routes?family=llama-3.3-70b-instruct&limit=10'

Check that the attestation key matches your pin and that each response's query equals the request. capacity: null for a seller means the crawler got no valid fresh report; the log shows missing_capacity for sellers that serve none.

Hot reload and rolling restarts

  • Config changes (sellers, operators, keys, pins) reload without a restart: atomically replace the config or seed file on the same filesystem, then kill -HUP <pid> on every live indexer and wait for discovery reloaded. An invalid update leaves the current config serving.
  • Removing a compromised operator: remove it, reload every indexer, update client pins, and check that fresh reads no longer include its evidence and that a fresh submission under it is rejected. No database deletion is needed.
  • Rolling restart (Linux, fixed port, file database): start the replacement on the same address and port, wait for discovery listening, then SIGTERM the old process. It hands off new connections, answers existing ones with Connection: close, and gives idle connections up to 12 s. Allow more than 12 s plus your request deadline for shutdown.
  • Rotating the attestation key: publish the new key out of band, have clients pin both (discoveryKeys for probers, keys for the SDK), switch, then retire the old pin after in-flight work drains. For a suspected compromise, revoke immediately instead.

Capacity of one instance

On the reference Linux host, 1,000 routes with 100 observations each served route detail at 13.57 ms server p99 and cold filtered lists at 27.60 ms client p99; at 10,000 routes, cold filtered client p99 was 89.65 ms. One CLI instance supports up to 1,000 pinned sellers.