Files
modules/state-crdts/hyper-p2p-crdt-grow-only-set/docs/architecture.md
T
2026-05-20 23:36:32 -04:00

1.8 KiB

Architecture: hyper-p2p-crdt-grow-only-set

Category: State CRDTs

Protocol: crdt-grow-only-set/v1

Layer diagram

flowchart TB
  App[Application] --> GOS[HyperP2PCrdtGrowOnlySet]
  GOS --> Set["_added Set"]
  GOS --> SW[Hyperswarm initModuleSwarm]
  SW --> MUX[Protomux per connection]
  MUX --> CH["Channel crdt-grow-only-set/v1"]
  CH --> Wire[crdt-grow-only-set-sync]

Wire messages

type fields direction behavior
crdt-grow-only-set-sync el (string) bidirectional Set.add(String(el)); idempotent merge

Full envelope example:

{ "type": "crdt-grow-only-set-sync", "el": "member-id" }

State model

Structure Role
_added Set<string> — authoritative merged G-Set
_stats { ops, gossipIn, gossipOut }
swarm Hyperswarm instance after ready()
_peerMsgs Map<peerHex, msg> — Protomux send handles for gossip fan-out

CRDT semantics: union-only; no tombstones; duplicates from network are ignored locally (add returns false).

Composition

Module Relationship
hyper-p2p-crdt-two-phase-set 2P-set uses separate add/remove sets; G-Set is the add side pattern
hyper-p2p-crdt-version-vector Track causality of related writes
hyper-p2p-presence Who is online before trusting gossiped membership

Typical stack: Hyperswarm topic → G-Set for replicated allowlist → app RPC on top.

Operational notes

  • No persistence: restart clears local set unless you snapshot values() yourself.
  • ready() without topic is a no-op for networking; use for tests that only need local CRDT math.
  • Gossip is fire-and-forget to all open _peerMsgs; no ack or anti-entropy loop.