tiles

package
v0.20260928.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MPL-2.0 Imports: 18 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).
  • Entry bundles in the entries layer have the exact same number of elements as the pubkey bundles in the pubkeys layer.

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

func EntriesForPackage added in v0.20260825.0

func EntriesForPackage(ctx context.Context, s3c simpleS3Reader, start, end, treeSize int64, prefix string) ([]byte, error)

EntriesForPackage reads the entries in [start, end) from their stored entry bundle, returning them unparsed in the wire form a tlog-mirror entry package requires, each entry with a big-endian uint16 length prefix.

https://c2sp.org/tlog-mirror

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 simpleS3Reader, 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, mtcpk *pubkey.MTCPublicKey) 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.

type TileReader added in v0.20260825.0

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

TileReader reads stored hash tiles as a tlog.TileReader, for use with tlog.TileHashReader.

func NewTileReader added in v0.20260825.0

func NewTileReader(ctx context.Context, s3c simpleS3Reader, prefix string) *TileReader

NewTileReader returns a TileReader over the tiles stored under prefix.

func (*TileReader) Height added in v0.20260825.0

func (r *TileReader) Height() int

Height returns 8, the height of tiles holding 256 hashes.

func (*TileReader) ReadTiles added in v0.20260825.0

func (r *TileReader) ReadTiles(tiles []tlog.Tile) ([][]byte, error)

ReadTiles fetches the data for each requested tile from storage.

func (*TileReader) SaveTiles added in v0.20260825.0

func (r *TileReader) SaveTiles([]tlog.Tile, [][]byte)

SaveTiles is a no-op.

Jump to

Keyboard shortcuts

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