Skip to main content

Module prolly

Module prolly 

Source
Expand description

Prolly Tree: content-defined chunked Merkle tree for efficient O(log N) diff.

Events are keyed by (item_id, wall_ts_us), sorted, then split into chunks using a rolling hash (Gear hash) for content-defined boundaries. A balanced Merkle tree is built over the chunks so that two replicas can diff in O(log N) time by comparing hashes top-down.

This is a library module intended for use by external sync tools (e.g. transport layers over TCP, HTTP, MCP, or file-based exchange). It is not exposed as a CLI command — bones does not own transport.

§Usage

use bones_core::sync::prolly::ProllyTree;

// Build trees from each replica's events.
let local_tree = ProllyTree::build(&events);
let remote_tree = ProllyTree::build(&events);

// Compare root hashes for fast equality check.
if local_tree.root.hash() == remote_tree.root.hash() {
    // Replicas are identical — no sync needed.
} else {
    // Diff in O(k log N) where k = number of differing chunks.
    let missing = local_tree.diff(&remote_tree);
    // `missing` contains event hashes present in remote but not local.
}

Structs§

Hash
32-byte BLAKE3 hash used as a node/chunk identity.
ProllyTree
Content-addressed Prolly Tree over a set of events.

Enums§

ProllyNode
A Prolly Tree node — either a leaf chunk of events or an interior node pointing to children.