merkle

package
v1.0.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package merkle provides deterministic state digests for anti-entropy.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidState = errors.New("merkle: invalid canonical state frame")

Functions

func Diff

func Diff(left, right *Tree) (leftOnly, rightOnly, different []string)

Diff returns keys whose digest differs between two trees.

Types

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree stores key-to-value digests. Insert values should be canonical CRDT state bytes. Tree is safe for concurrent use, but is not a transport protocol or an authority on state validity.

func NewTree

func NewTree() *Tree

func (*Tree) Delete

func (t *Tree) Delete(key string)

Delete removes key from t. It is safe to call for a missing key.

func (*Tree) Insert

func (t *Tree) Insert(key string, value []byte)

func (*Tree) InsertState

func (t *Tree) InsertState(key string, state []byte) error

InsertState validates state as a complete CRDT frame envelope before hashing it. Prefer this method when roots are exchanged for anti-entropy; callers must have decoded any type-specific payload before accepting it.

func (*Tree) Root

func (t *Tree) Root() [sha256.Size]byte

Root returns a deterministic binary Merkle root over sorted key/value digests. It caches the result for the current immutable tree generation, so repeated anti-entropy checks do not re-copy, sort, and hash unchanged state. Leaf and inner-node domain separators prevent structural ambiguity; an odd node is paired with a zero digest at that level.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL