DIM · Dagon Inference Marketplace

Rolling deploys and key rotation

The protocol's zero-downtime rule (A34) binds sellers too: no deploy, restart, key rotation or config change may fail a request that would otherwise have succeeded, or strand funds. The gateway implements this with generation takeover on Linux.

Requirements

  • Linux, Bun 1.4.5 or newer, a fixed public port.

  • The same private, local, file-backed ledger for both generations. Its management files (<ledgerPath>.deploy.sock and friends) live next to it; keep the path short enough for a Unix socket address and do not delete them while a gateway is live.

  • Optionally, net.ipv4.tcp_migrate_req=1, so connections accepted but not yet served move to the new listener when the old one closes:

    sudo sysctl -w net.ipv4.tcp_migrate_req=1

A rolling restart

Start the new generation with the new config (or the same one) and --takeover:

bun services/gateway/src/cli.ts --config /private/seller/next.json --takeover
  1. The candidate binds the same port with SO_REUSEPORT and prepares.
  2. The incumbent stops admitting: new Holds it receives get 503 gateway_draining with Retry-After: 1 before any claim or receipt, so the buyer resends the identical Hold, which the candidate admits. Capacity reports advertise headroom: 0 while draining.
  3. Admitted streams on the incumbent are never aborted. They finish, their receipts persist, and only then does it release the ledger and print Gateway drained.
  4. The candidate opens the ledger and prints Gateway ready on port N. Wait for this line before reporting success, and for Gateway drained from the old process before declaring it retired.

Receipt lookup and voucher posts stay available throughout. The handoff was tested with streams in flight: 11 of 11 requests completed and 87 µUSDC was acknowledged in both the takeover and the unchanged control run.

--takeover also starts a primary when no generation is live and the ledger on disk matches. That is recovery after an abrupt exit, not a graceful handoff: claims interrupted by the crash become failed receipts at 0 and are never redispatched.

Never use the embedding API's Gateway.close() for deploys; it aborts active work. Use drain()/release() or the listener's stop().

Maintenance windows

bun services/gateway/src/cli.ts --config /private/seller/next.json --control maintenance
bun services/gateway/src/cli.ts --config /private/seller/next.json --control resume

maintenance refuses new Holds with the same pre-claim 503, waits for admitted streams and keeps settlement endpoints up. The marker survives restarts, and a replacement inherits it. resume restores admission.

Rotating the receipt key

Receipt keys overlap so buyers never see a receipt under an unpublished key:

  1. Generate the new key and add it as nextReceiptKeyFile with a higher nextReceiptKeyEpoch, keeping the active key unchanged. Take over. The new public key now appears in the signed receipt_keys, unused.

  2. Confirm it is in the public listing.

  3. Promote it: set receiptKeyFile and keyEpoch to the new file and epoch, remove the next* fields, and list the old public key in retiredReceiptKeys:

    { "retiredReceiptKeys": [{ "key": "OLD_RECEIPT_PUBKEY", "keyEpoch": 0 }] }

    Take over again. The gateway refuses a takeover with an unannounced signer or a missing prior receipt key, and never lets the active epoch decrease.

  4. Keep the old key in retiredReceiptKeys while its receipts can still be vouchered and settled.

Rotating the settler key

Fund the new settler with SOL, set settlerKeyFile to it, and put the old settler's base58 public address in retainedSettlers:

{ "settlerKeyFile": "keys/settler-2.json", "retainedSettlers": ["OLD_SETTLER_PUBKEY"] }

New channels name the new settler. Channels that name the old one are still admitted and their vouchers redeemed, with the new key paying the fees; the old secret is not needed. Always keep the ledger's original settler address in this list.

Changing the listing key

The listing key is the seller identity and is hashed into every route ID, so it cannot be rotated in place. Publish the new identity with its own endpoint and ledger, move traffic to it, put the old identity into maintenance, and keep the old gateway serving its listing, receipts and vouchers until its channels are settled or closed. Never change listingKeyFile under a live identity.

Changing routes and prices

A compatible takeover keeps existing route IDs and schedules so already-signed Holds stay usable. To change a model identity, endpoint, concurrency or schedule, add a new route alongside the old one, let buyers migrate, and remove the old route in a later deploy. Do not remove a route in a live takeover. The gateway also refuses to start on a ledger with an interrupted request whose route or schedule is no longer configured.

Program upgrades

During an on-chain program upgrade slot, Agave can reject redeem with UnsupportedProgramId. The settler keeps the acknowledgment pending, waits for a later confirmed slot, rereads the channel's redeemed total and retries once with a fresh blockhash; a recurring error falls back to the normal settlement queue. A landed failed transaction can cost a fee; it never increases the redeemed amount. New program versions are installed at new addresses rather than upgraded in place (payouts).

Shared ledger mode

"ledgerMode": "shared" is an opt-in Linux mode in which both generations serve from one SQLite WAL with synchronous=FULL during the overlap. Both generations must set it explicitly; shared and exclusive ledgers refuse each other, and there is no automatic migration between them. It missed the 1 ms admission and 5 ms first-chunk budgets in every measured trial, so it is not latency-qualified. Use the default exclusive ledger unless you need the overlap.