tiles

package
v0.20260729.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package tiles implements https://c2sp.org/tlog-tiles.

Entry tiles contain up to 256 MTCLogEntry objects and are stored as compressed entry bundles.

Hash tiles contain up to 256 32-byte SHA-256 hashes, concatenated. The tile represents up to 8 layers of the Merkle Tree, but only the bottom-most of those layers is actually stored. Higher layers are calculated from the tile contents as needed.

Invariants:

  • Tiles in storage are never empty.
  • Tiles in storage are immutable.
  • A hash is only appended to a tile when it will be permanent. Equivalently: only the hashes of complete subtrees are appended to a tile.
  • Any hash stored in a level L tile is equal to MTH(c), where c is a list of exactly 256 hashes stored in a child tile at level L-1 (for L > 0).

Index

Constants

This section is empty.

Variables

View Source
var ErrTileExists = errors.New("tile exists")

ErrTileExists is returned when trying to write a tile that already exists in storage.

Functions

This section is empty.

Types

type Frontier

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

Frontier contains all the tiles on the right edge of the tree, which may be partial or empty (but not full). It keeps track of which tiles have been modified and need to be written to storage.

When a tile becomes full, it gets moved into a holding list of tiles that are not on the right edge but need to be written and its MTH gets appended to the tile above it.

The zero value of Frontier represents an empty tree. Empty trees cannot be loaded or flushed.

Frontier is not safe for concurrent access.

func LoadFrontier

func LoadFrontier(ctx context.Context, s3c simpleS3, treeSize int64, prefix string) (*Frontier, error)

LoadFrontier loads the current frontier from storage, given the current tree size.

Succeeds only if all the frontier tiles for that tree size exist in storage.

func (*Frontier) AppendEntry

func (f *Frontier) AppendEntry(mtcle *entry.MTCLogEntry) error

AppendEntry appends a single MTCLogEntry to the entries tile and a corresponding hash to the level-0 hashes tile, updating any higher levels as needed.

On error, the Frontier is unchanged.

func (*Frontier) Clone added in v0.20260729.0

func (f *Frontier) Clone() *Frontier

Clone creates a copy of Frontier that doesn't share any memory with the original.

During sequencing in the MTCA we want to use a temporary copy of the frontier, so that if we error out the original in-memory Frontier stays untouched.

func (*Frontier) Publish added in v0.20260729.0

func (f *Frontier) Publish(ctx context.Context, s3c simpleS3, prefix string) error

Publish writes all dirty tiles to storage and clears their dirty status.

Errors if the tree is empty.

TODO(#8902): This should use CopyObject, and allow overwriting.

func (*Frontier) RootHash

func (f *Frontier) RootHash() tlog.Hash

RootHash calculates and returns the current root hash.

func (*Frontier) Stage added in v0.20260729.0

func (f *Frontier) Stage(ctx context.Context, s3c simpleS3, prefix string) error

Stage writes all dirty tiles to storage but does not clear their dirty status.

Tiles are written to a prefix determined by the tree size and root hash, so as not to conflict with live-published tiles.

Errors if the tree is empty.

func (*Frontier) TreeSize

func (f *Frontier) TreeSize() int64

TreeSize returns the current tree size.

Jump to

Keyboard shortcuts

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