anchor

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package anchor is the bucket owner's tooling (spec sections 3.4 to 3.6 and 4.4): it creates a bucket chain, and anchors the entries of the owner and its writers into the chain's next tokens, exactly as frozen.

The set of commitments the chain has named is rebuilt from the chain itself, every run, from the rooted tokens the tooling verifies against its own headers (bucket, then bucket-seq back to seq 0), never from a local cache; the fold of those tokens must be consistent. Each writer's unnamed entries are walked with unanchored at every host, every page from the start; every entry an answer returns must verify (carrier rules and the funding tree's proof) and carry the writer, bucket and id asked for, and its funding outpoint must be unspent by positive evidence from the spend source. The batch is folded against the current map before anything is minted: one key's entries ordered by created then commitment, the last deciding and the rest consumed; a delete of a key the map does not hold, and a put of the value a key already names, go to consumed; nothing a token of the chain named is applied again. The changes are split over several tokens when they do not fit one record of 65,536 bytes (or 1024 changes, or 1024 consumed).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBroken is a chain whose fold is not consistent: only the owner
	// could have made it so, and the way on is a new chain (exit 1).
	ErrBroken = errors.New("anchor: the chain's fold is not consistent")
	// ErrIncomplete is a run that did what it could and left something:
	// a host whose answer did not verify, an entry whose funding outpoint
	// the spend source could not vouch for, a token not yet mined. It
	// proves nothing either way (exit 3).
	ErrIncomplete = errors.New("anchor: incomplete")
	// ErrRefused is a mined token a host refused: a refusal is final for
	// those bytes, so it is not sent to that host again (exit 1).
	ErrRefused = errors.New("anchor: refused")
)

Errors a caller maps to exit codes.

Functions

func NewIdentifier

func NewIdentifier(name string) (string, error)

NewIdentifier is a bucket identifier for name with a fresh random suffix of 10 lowercase letters (spec section 3.1).

func RecordSizer

func RecordSizer(base storerec.Bucket) func([]storerec.Change, [][32]byte) (int, error)

RecordSizer measures a token record of a chain whose other fields are base's: the exact encoded length.

func SizingBase

func SizingBase(bucket string, owner []byte, id, prev [32]byte, writers [][]byte) storerec.Bucket

SizingBase is the record a batch's tokens are measured against: every token at the widest seq, count and time it could carry, so a later token of a split, whose seq is wider, still fits.

Types

type Chain

type Chain struct {
	Bucket  string   `json:"bucket"`
	ID      string   `json:"id,omitempty"` // hex, once the first token is signed
	Writers []string `json:"writers"`      // hex, ascending
	// Tree is the chain tree the first token spends (raw hex and proof).
	Tree     string          `json:"tree,omitempty"`
	TreeBump string          `json:"treeBump,omitempty"`
	TreeFee  *bwallet.Output `json:"treeFee,omitempty"`
	// Pending is a token signed and recorded, not yet seen mined and
	// published.
	Pending *PendingToken `json:"pending,omitempty"`
	// Seq is the last token this tooling minted.
	Seq     uint64 `json:"seq"`
	Created int64  `json:"created"`
}

Chain is a bucket chain this identity owns, as its tooling records it: enough to mint the next token on, never the set of what the chain named.

type Options

type Options struct {
	AddWriters    []string
	RemoveWriters []string
	// DryRun plans and reports, and mints nothing.
	DryRun bool
}

Options are what an anchoring run may change besides the map.

type PendingToken

type PendingToken struct {
	Seq      uint64         `json:"seq"`
	Txid     string         `json:"txid"`
	Raw      string         `json:"raw"`
	Parent   string         `json:"parent"` // raw hex of the transaction it spends
	ParentMP string         `json:"parentBump"`
	Vout     uint32         `json:"vout"` // the parent output it spends
	Fee      bwallet.Output `json:"fee"`
	Changes  int            `json:"changes"`
	Consumed int            `json:"consumed"`
}

PendingToken is a token recorded before it is sent.

type Plan

type Plan struct {
	Steps []Step
	// Deferred are the keys left for a later run because the map is at its
	// bound of 1,048,576 keys.
	Deferred []string
}

Plan is a folded batch, split into the tokens that carry it.

func PlanBatch

func PlanBatch(current storerec.Map, named map[[32]byte]bool, batch []storerec.Applicable, size func([]storerec.Change, [][32]byte) (int, error)) (*Plan, error)

PlanBatch folds batch against the current map and the chain's named set, as spec section 3.4 has it, and splits the result over tokens whose records, as size measures them, fit the bounds. Each key's change is carried by exactly one token; a key whose consumed entries do not fit one token spills them into tokens of consumed alone before it.

type Report

type Report struct {
	FromSeq   uint64
	Tokens    []string // txids minted
	Applied   int      // changes written
	Consumed  int
	Entries   int // entries considered (each once)
	Named     int // entries skipped because a token already named them
	Swept     []string
	Unvouched []string // entries whose funding outpoint the spend source could not vouch for
	Strangers int      // entries an answer returned for another writer, bucket or id
	Hosts     []string // hosts named, and why
	Deferred  []string
	Plan      *Plan
}

Report is what an anchoring run did.

type Step

type Step struct {
	Changes  []storerec.Change
	Consumed [][32]byte
	Map      storerec.Map
}

Step is one token's worth of a batch: its changes, ascending by key, its consumed commitments, ascending, and the map after it.

type Store

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

Store is the owner's chains, one file in the identity's directory.

func OpenStore

func OpenStore(dir string) *Store

OpenStore opens dir's chains file.

func (*Store) Find

func (s *Store) Find(bucket, id string) (*Chain, error)

Find is the chain of a bucket identifier this identity owns; with id empty, the only one, else an error naming the choice.

func (*Store) Load

func (s *Store) Load() ([]*Chain, error)

Load reads every chain.

func (*Store) Save

func (s *Store) Save(c *Chain) error

Save writes one chain, in place of the record of the same bucket and id.

type Tool

type Tool struct {
	Pub    *publish.Publisher
	Reader *reader.Reader
	Store  *Store
	Logf   func(format string, args ...any)
	// contains filtered or unexported fields
}

Tool is the owner's tooling over an identity's publisher (its wallet, node, settlement leg and delivery) and a reader of the hosts.

func (*Tool) Anchor

func (t *Tool) Anchor(ctx context.Context, c *Chain, o Options) (*Report, error)

Anchor runs the owner's tooling once over a chain: it rebuilds the chain from the hosts, walks every writer's unanchored entries, checks each, folds the batch and mints the tokens that carry it.

func (*Tool) New

func (t *Tool) New(ctx context.Context, bucket string, writers []string) (*Chain, error)

New creates a bucket chain: a chain tree of one output under derive(owner, "chain"), mined, then the first token spending it, each recorded before it is sent. A run that stopped part way is finished by calling New again with the same identifier.

Jump to

Keyboard shortcuts

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