Skip to content

Replicated Relays

Several relays can share one replicated log. Each relay runs a sidecar that appends its events to a Hypercore. Autobase merges the logs of all nodes into one order, Hyperbee holds the resulting state, and Hyperswarm connects the nodes directly, with encryption and NAT traversal.

How an event is replicated

  1. A relay validates an event and hands it to its sidecar, which appends it durably to the local log before the relay acknowledges it.
  2. The log replicates to the other nodes over Hyperswarm.
  3. Each node applies the same reducer: duplicates, replacement and deletion follow the event rules, so every node reaches the same state.
  4. Once a majority of indexers has acknowledged the order, the event is final and its position no longer changes.
  5. Every relay follows its sidecar's log and stores the events locally, so queries are answered from SQLite.

A minority of nodes keeps accepting events. They become final after the nodes are reunited.

Finality

curl http://127.0.0.1:7460/v1/finality/<event id>
{"known": true, "seq": 12, "finalized": true}

Membership

The cluster has an admin key. The node that holds the admin seed creates the log, announces its keys, and grants writer membership to nodes whose keys are listed in NODES. Every grant and revocation is signed by the admin key and recorded in the log itself. Connections from other keys are refused.

Revoke a node on the admin node's sidecar:

curl -X POST http://hyper-0:8080/v1/members/revoke -H "Authorization: Bearer $HYPER_TOKEN" -d '{"node":"<node key>"}'

A revoked node cannot rejoin.

Sidecar configuration

Variable Meaning
NODE_SEED Seed of the node key, 64 hex characters
CLUSTER Cluster name. Determines the Hyperswarm topic
NODES Keys of all member nodes
ADMIN_KEY Admin public key
ADMIN_SEED Admin seed, on one node only
NODE_TOKEN Token of the sidecar API, at least 16 characters
DHT_BOOTSTRAP host:port list of DHT nodes
DATA_DIR, KEY_FILE /data and /data/operator.key

Derive a public key from a seed with printf '%s\n' "$SEED" | docker run --rm -i relay-hyper:dev pubkey.

On joining, the node publishes a binding event (kind 30502) that proves that its operator key and node key belong together.

Sidecar API

All endpoints except /healthz need Authorization: Bearer <NODE_TOKEN>.

Method and path Purpose
GET /v1/status Node key, readiness, writer and indexer state, log length, signed length, peers
POST /v1/append Append an event durably
GET /v1/log?from=&version= Read the log. With version, waits up to 15 seconds for a change
GET /v1/finality/{id} Whether an event is final
GET /v1/state?key= or ?prefix= Read the state
POST /v1/members/revoke Revoke a node (admin node)