constraint-crdt
CRDT-backed constraint states for distributed fleet consensus.
Core insight
CRDTs satisfy three algebraic laws (commutative, associative, idempotent). Constraint satisfaction requires closure under lattice operations. These are the same algebraic structure — a semilattice.
This crate extracts the CRDT merge protocol from SmartCRDT and fuses it with constraint-theory-core semantics.
What you get
| Type | Description |
|---|---|
Merge trait |
Semilattice join (C/A/I laws verified) |
ConstraintGCounter |
Distributed satisfaction counting |
PNCounter |
Positive/negative counting |
ConstraintORSet |
Add-wins constraint tracking with tombstone GC |
EisensteinRegister |
Lattice positions as LWW registers (lower norm wins) |
FleetTile |
PLATO tiles as mergeable CRDTs with content integrity |
ConstraintState |
Composite: all sub-CRDTs in one mergeable unit |
VectorClock |
Causal ordering (happened-before, concurrent detection) |
DeltaTracker |
Send only changes, not full state |
StateHash |
Merkle-style state hashes for efficient sync detection |
GossipNode |
Anti-entropy gossip protocol state machine |
Simulation |
Deterministic network simulation (loss, latency, partitions) |
PlatoClient |
HTTP client for PLATO tile server (plato feature) |
Usage
use *;
// Two fleet nodes, independent
let mut node_a = new;
node_a.add_constraint;
node_a.record_satisfied;
let mut node_b = new;
node_b.add_constraint;
node_b.record_satisfied;
// Merge without coordination — always consistent
let merged = node_a.merged;
assert_eq!;
// Gossip protocol for automatic convergence
let mut a = new;
let mut b = new;
a.add_constraint;
b.add_constraint;
gossip_exchange;
gossip_exchange;
// Both nodes now have both constraints
// Deterministic simulation with message loss
let mut sim = new.with_loss_rate;
for i in 0..5
let converged_at = sim.run_until_converged;
assert!;
Benchmarks (Ryzen AI 9 HX 370)
| Operation | Latency | Throughput |
|---|---|---|
| G-Counter merge | 76 ns | 13.1M ops/s |
| Full state merge (50+50 constraints) | 12 µs | 82.8K ops/s |
| Vector clock compare (6 nodes) | 369 ns | 2.7M ops/s |
| Delta generation | 76 ns | 13.2M ops/s |
CLI
Tests
85 tests — every CRDT type verified for commutativity, associativity, idempotence. Gossip convergence tested with 2, 3, 5 nodes. Simulation tested with 30% message loss.
Origin
Extracted from SmartCRDT's OR-Set, G-Counter, PN-Counter, and Merge trait, specialized for the Cocapn fleet's constraint theory ecosystem.
License
MIT