diff --git a/docs/roadmap.md b/docs/roadmap.md new file mode 100644 index 0000000..ba32453 --- /dev/null +++ b/docs/roadmap.md @@ -0,0 +1,76 @@ +# Lattice Roadmap + +## Milestone 1: Single-Node Append-Only Log + +**Goal:** A single node can create, sign, and persist entries to its own log. No networking yet. + +### Deliverables + +- [x] HLC timestamps +- [x] Node identity (Ed25519 keypair, save/load) +- [x] Entry signing & verification +- [x] Log file I/O (append, read, hash verification) +- [x] SigChain (validate entries before appending) +- [x] Store (redb) — `kv` + `meta` tables, log replay +- [ ] Interactive CLI: `init`, `put`, `get`, `delete`, `status`, `quit` + +### Success Criteria + +- Can create a new identity +- Can append entries to local log +- Can replay log to reconstruct KV state +- All operations survive restart + +### Multi-KV Refactoring (before M2) + +Current code assumes single store. Changes needed: +- [ ] DataDir → support `stores/{uuid}/` subdirectories +- [ ] SigChain → scoped to (store_id, author_id) +- [ ] Store → per-store state.db, not global +- [ ] Log paths → `stores/{uuid}/logs/{author}.log` +- [ ] Add global meta.db for stores table +- [ ] CLI → `create-store`, `list-stores`, `use ` + +--- + +## Milestone 2: Two-Node Sync + +**Goal:** Two nodes can sync their logs over the network. + +### Deliverables + +- [ ] Store: add `applied_frontiers` table (sync state per author) +- [ ] VectorClock module (diff, merge, missing entries) +- [ ] Sync protocol (push missing entries) +- [ ] Iroh integration (peer discovery, connection) +- [ ] Multi-author log merging +- [ ] CLI: `peers`, `connect`/`join` commands + +### Success Criteria + +- Node A writes, Node B syncs, both have same state +- Works offline-first (sync when connected) + +--- + +## Milestone 3: Multi-Node Mesh + +**Goal:** N nodes form a gossip mesh with watermark consensus. + +### Deliverables + +- [ ] Gossip protocol +- [ ] Watermark tracking & log pruning +- [ ] Node invitation (sigchain membership) +- [ ] Conflict detection (LWW resolution) + +--- + +## Future + +- Mobile (iOS/Android) clients +- Key rotation +- Secure storage (Keychain, TPM) +- Snapshots for fast bootstrap +- FUSE filesystem mount + - Note: FUSE requires u64 inode numbers → maintain `BiMap` in redb diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 0000000..56a0199 --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,74 @@ +# Testing Scenarios (Validation Apps) + +These apps test HLC ordering, gossip convergence, and conflict resolution. + +## Level 1: Pixel Board (Visual Convergence) + +50x50 collaborative grid where users paint pixels. + +**Data Model:** `/canvas/{x}_{y}` → `{hex_color}` + +**Tests:** +- Visualize sync disagreements immediately +- High write volume (log performance) +- Simultaneous writes (HLC tiebreaker) + +**Scenario:** Node A paints all red (offline), Node B paints all blue (offline), connect. Board must be identical on both. + +--- + +## Level 2: Shared Grocery List (LWW Trap) + +List with add/check/delete operations. + +**Data Model:** `/list/{item_uuid}` → `{ name, status: "needed"|"bought" }` + +**Tests:** Exposes LWW weakness (resurrection bug) + +**Scenario:** +1. Alice syncs, sees "Milk", goes offline, marks "bought" +2. Bob syncs, sees "Milk", deletes it +3. Reconnect + +**Result:** Item either resurrects or vanishes based on timestamp. Forces tombstone pattern. + +--- + +## Level 3: Chat Room (Causal Ordering) + +Group chat application. + +**Data Model:** `/chat/{channel}/{timestamp}_{node_id}` → `{ msg }` + +**Tests:** +- HLC causal ordering +- Prefix queries (redb range scans) +- Gap detection via vector clocks + +**Scenario:** +1. Node A sends "Msg 1" +2. Node B sees it, replies "Msg 2" +3. Node C comes online, connects only to B + +**Success:** Node C receives "Msg 1" before/with "Msg 2" (transitive sync). + +--- + +## Level 4: Chaos Monkey (Automated Simulation) + +Tokio-based simulation harness with in-memory networking. + +**Setup:** +- 5 node threads in one process +- In-memory network (tokio channels) +- Chaos monkey randomly: cuts connections, writes random keys, sleeps threads + +**Assertion:** +```rust +let state_0 = nodes[0].dump_state_hash(); +for i in 1..5 { + assert_eq!(state_0, nodes[i].dump_state_hash()); +} +``` + +Catches HLC clamping edge cases that manual testing misses.