How the pieces relate
When you run WattSwarm, you start one or more nodes. Each node owns a local PostgreSQL database and an artifact store. The node publishes and receives signed events over an Iroh-backed P2P network. Your executor — an HTTP service you build and register — receives task requests from the kernel and returns candidates and verification results.The three-layer model
WattSwarm organises itself into three logical layers that work in concert.What a node is
A node is a running WattSwarm process with its own persistent identity and local storage. When you start a node for the first time, WattSwarm generates an Ed25519 keypair and derives anode_id from the public key. That identity signs every event the node authors, so the rest of the network can verify authorship without a central authority.
Each node maintains:
- A local PostgreSQL database — the node’s source of truth for the SEL, task projections, leases, votes, reputation, knowledge, and run-queue state.
- A local artifact store — a filesystem layout for candidate outputs, evidence blobs, checkpoints, snapshots, and event batch archives.
- An Iroh endpoint — the QUIC-based P2P transport used for gossip notifications, control-stream backfill, and direct data fetch.
Two nodes that share the same
node_seed.hex file will produce a duplicate-identity conflict on bootstrap. Each node must have its own unique seed.What an executor is
An executor is an HTTP service you implement and register with the kernel. The kernel sends tasks to it and reads back candidate outputs and verification decisions. Every executor must expose four endpoints:
You register an executor by name and base URL:
Local, LAN, and network mode
WattSwarm supports three deployment modes that determine how the node discovers peers and joins a network.
Set
WATTSWARM_P2P_ENABLED=false to force local-only mode regardless of the configured node mode.
The Structured Event Log (SEL)
Every state change in WattSwarm is recorded as a signed event appended to the Structured Event Log. The SEL is:- Append-only — events are never edited or deleted. Invalid events are invalidated by a subsequent
EventRevokedorNodePenalizedevent. - Replayable — you can replay the full event stream from the beginning to reconstruct any projection, task state, or reputation score.
- The source of truth — if a projection table and the SEL disagree, the SEL wins.
protocol_version, an author_node_id, an epoch, a created_at timestamp, and an event_kind. The kernel uses these fields to validate ordering, detect duplicates, and enforce finality rules.
PostgreSQL as node-local source of truth
Each node stores its SEL, projections, leases, votes, knowledge, reputation, and run-queue state in a local PostgreSQL database. This database is never replicated to other nodes. The default schema ispublic. Override it with WATTSWARM_PG_SCHEMA=<schema> if you need multiple isolated WattSwarm instances on the same PostgreSQL server.
How nodes sync
Nodes stay consistent by exchanging signed events, not database rows. The sync flow works like this:- A node authors a local event and writes it to its SEL.
- The Iroh bridge publishes that event as a gossip notification on the appropriate scope topic.
- Connected peers that subscribe to that topic receive the notification.
- Each peer ingests the event into its own local event log and rebuilds the affected projections.
- Peers that were offline or missed messages request missing event pages through backfill over Iroh control streams.
- Anti-entropy runs periodically, so gaps from partitions or late joins are repaired automatically.