Crate mdcs_merkle

Crate mdcs_merkle 

Source
Expand description

ยงmdcs-merkle

Merkle-Clock DAG implementation for the MDCS (Merkle-Delta CRDT Store).

This crate provides:

  • Content-addressed storage for causal history
  • Merkle-DAG structure for verifiable, tamper-proof history
  • DAGSyncer for gap-repair and synchronization
  • Broadcaster for gossip-based head dissemination

ยงArchitecture

The Merkle-Clock serves as a logical clock that:

  1. Provides verifiable causal ordering via hash-linked nodes
  2. Enables gap-repair through content-addressed fetching
  3. Supports open membership without metadata bloat
  4. Handles concurrent updates via multi-root DAGs

ยงExample

use mdcs_merkle::{MerkleNode, Payload, MemoryDAGStore, DAGStore, NodeBuilder};

// Create a DAG store
let mut store = MemoryDAGStore::new();

// Create the genesis node
let genesis = NodeBuilder::new()
    .with_payload(Payload::genesis())
    .build();
let genesis_cid = store.put(genesis).unwrap();

// Create a child node referencing the genesis
let child = NodeBuilder::new()
    .with_parents(vec![genesis_cid])
    .with_payload(Payload::delta(vec![1, 2, 3]))
    .build();
let child_cid = store.put(child).unwrap();

// The child is now a head
assert_eq!(store.heads(), vec![child_cid]);

Modulesยง

broadcaster ๐Ÿ”’
Gossip-based broadcasting for head dissemination.
hash ๐Ÿ”’
Content-addressed hashing for Merkle nodes.
node ๐Ÿ”’
Merkle node definition and builder.
store ๐Ÿ”’
DAG storage trait and implementations.
syncer ๐Ÿ”’
DAG synchronization with gap-repair logic.

Structsยง

BroadcastConfig
Configuration for the broadcaster.
BroadcastMessage
A broadcast message containing head announcements.
BroadcastNetwork
Simulates a network of broadcasters for testing.
Broadcaster
Gossip-based broadcaster for head dissemination.
DAGSyncer
DAG synchronizer for gap-repair and reconciliation.
Hash
A 32-byte SHA-256 hash used as a Content Identifier (CID).
Hasher
Hasher utility for computing content hashes.
MemoryDAGStore
In-memory implementation of DAGStore.
MerkleNode
A node in the Merkle-DAG representing a causal event.
NodeBuilder
Builder for creating Merkle nodes.
SyncRequest
Request to fetch nodes from a peer.
SyncResponse
Response containing nodes from a peer.
SyncSimulator
Simulator for testing sync between multiple replicas.

Enumsยง

DAGError
Errors that can occur during DAG operations.
Payload
The payload carried by a Merkle node.
SyncError
Errors that can occur during synchronization.

Traitsยง

DAGStore
Trait for content-addressed DAG storage.