Expand description
Delta-state G-Counter and PN-Counter for constrained mesh links.
This crate is the PRODUCT half of the SafeMesh verification-guided loop:
a thin no_std + alloc implementation of exactly the model proven in
lean/SafeMesh/ (carrier = join-semilattice, merge = join, delta =
single-coordinate bump), held to those proofs by a differential
conformance test (tests/conformance.rs) that replays a Lean-emitted
JSON corpus through this code and compares state vectors, sets, read vectors,
numeric values, ownership decisions and optional allocation/sequence results
with the parsed expectations.
What is PROVEN (in Lean, kernel-checked) vs what is TESTED (here): the Lean theorems are universal; this crate is checked against them over a finite corpus. The bridge (Lean compiled eval → JSON → this crate) is the named trusted component. See the repo README for the full TCB statement.
Modules§
- laws
- local
- Linux/local-filesystem packet-A adapter. All writers for a replica set must use the same directory and fixed configuration. Keep fence files in place. LocalReplica acknowledges in memory; DurableReplica commits before acknowledgement and offers checked ordinary restart of an existing committed store.
- ownership
- Transcription of SafeMesh.RecordKernel ownership rules. The existing Lean corpus binds these decisions to their specification; no Lean runtime is used.
- wire
- Canonical wire codec implementations for the CRDT types.
Structs§
- Collection
Limits - Optional count budget for each built-in collection and collection delta.
- Collision
Report - The wire message that carries collision alarms to a peer.
- Decode
Limits - Record and collection limits for
EventLog::from_wire_bytes_with_limits. - Enable
Wins Flag - Enable-wins boolean flag.
- Event
Log - Append-only, deduplicating event log for CRDT deltas. Equality compares log data, excluding the in-memory first-admission binding flag and the in-memory collision register.
- GCounter
- A grow-only counter: one tally per replica, join = pointwise max.
- GCounter
Delta - Delta for a grow-only counter: one replica coordinate and its asserted tally.
- GSet
- A grow-only set: merge = union.
- InMemory
Transport - Deterministic in-memory adapter for coverage-contract fault campaigns.
- LwwDot
- Total-order dot for last-writer-wins registers.
- LwwEntry
- One LWW register assignment.
- LwwMap
- Last-writer-wins map.
- LwwRegister
- Last-writer-wins register.
- LwwRegister
Delta - Delta for a last-writer-wins register.
- OrSet
- Observed-remove set with add-wins semantics.
- PnCounter
- An increment/decrement counter: a pair of G-Counters (increments
P, decrementsN), join = componentwise. - Record
- An event-log record carrying a CRDT delta.
- Record
Collision - One record ID held with two different payloads.
- Record
Id - Stable identity for an event-log record.
- Replica
- Owned state and admitted history. A nonempty initial state need not be reproducible from its initially empty log.
- Rga
- RGA-family sequence state: positioned values plus tombstoned positions.
- Transport
Envelope - Version
Vector - Per-replica contiguous prefixes for anti-entropy pulls.
- Version
Vector Limits - Optional collection budgets for
VersionVector::from_peer_prefixes_with_limits. - Wire
Cursor - Borrowed, bounds-checked reader for canonical wire primitives.
Enums§
- Admission
- Full decoded payload equality distinguishes redelivery from an ID collision.
- Append
Error - Collision
Verdict - What merging one report entry did to the receiving log.
- Coordinate
Error - Rejection of an invalid counter domain or replica coordinate.
- Decode
Error - Failure from the bounded event-log decoder.
Separate from
WireErrorto preserve existing exhaustive matches. - Enable
Wins Flag Delta - Delta for an observed-token enable-wins flag.
- Legacy
Frame - An EventLog frame layout written by an earlier encoder, named by
WireError::LegacyEventLogFrame. - LwwMap
Delta - Delta for a last-writer-wins map.
- Merge
Error - Error raised by full-state merge (
mergeortry_merge). - OrSet
Delta - Delta for an observed-remove set.
- PnCounter
Delta - Replica
Error - The operation that failed; invalid admission remains a verdict.
- RgaDelta
- Delta for an RGA-family ordered sequence.
- Transport
Error - Version
Vector Error - Version
Vector Limit Error - Failure from opt-in bounded peer-version reconstruction.
Separate from
VersionVectorErrorto preserve existing exhaustive matches. - Wire
Error
Traits§
- Crdt
- Delta application surface for CRDT product types.
- Mergeable
- State-based merge contract:
mergeis expected to be a semilattice join. - Transport
Adapter - Engineered transport coverage contract.
- Wire
Decode - Decode one payload from a shared cursor using its public read methods.
Self::from_wire_bytesadditionally rejects trailing bytes. - Wire
Encode - Encode a payload using the canonical wire primitives.
- Wire
Schema - Stable, versioned identity for persisted payloads, independent of Rust names.
External implementations must use a globally unique schema and change it when
the wire interpretation changes. Never reuse a built-in
safemesh/identity.
Functions§
- anti_
entropy - Queue repair and admit the deliveries available for
to, returning every record ID and verdict with its sending peer. In particular, Invalid is reported again on every retry, with its original reason. Refusals are not acknowledgements and are not cached: fixing the receiver permits the next ordinary sync to admit the record. Dropped or partitioned packets retain the adapter’s usual delivery semantics. - queue_
anti_ entropy - Queue missing records. Admission happens at the receiver; use
anti_entropywhen both replicas are available to observe refusals. - write_
bytes - Append a
u32length prefix followed by the bytes verbatim. ReturnsLengthOverflowwithout changingoutif the slice length exceedsu32::MAX. Read the prefix withWireCursor::read_lenand the payload withWireCursor::read_exact. - write_
len - Append
lenas a four-byte little-endianu32. ReturnsLengthOverflowwithout changingoutiflenexceedsu32::MAX. The result can be read withWireCursor::read_len. - write_
u8 - Append one byte in the same format as
WireCursor::read_u8. - write_
u32 - Append a
u32as four little-endian bytes, matchingWireCursor::read_u32. - write_
u64 - Append a
u64as eight little-endian bytes, matchingWireCursor::read_u64.