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 ¶
- Variables
- func NewIdentifier(name string) (string, error)
- func RecordSizer(base storerec.Bucket) func([]storerec.Change, [][32]byte) (int, error)
- func SizingBase(bucket string, owner []byte, id, prev [32]byte, writers [][]byte) storerec.Bucket
- type Chain
- type Options
- type PendingToken
- type Plan
- type Report
- type Step
- type Store
- type Tool
Constants ¶
This section is empty.
Variables ¶
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 ¶
NewIdentifier is a bucket identifier for name with a fresh random suffix of 10 lowercase letters (spec section 3.1).
func RecordSizer ¶
RecordSizer measures a token record of a chain whose other fields are base's: the exact encoded length.
func SizingBase ¶
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
// Hold names writers whose entries this run does not apply: they stay
// unanchored, and the writer stays named by the token. An owner's
// service that applies a delegate's entries only under a permission it
// checked (bweb's delegation through borg) holds every writer it was
// not allowed for. The owner is never held.
Hold []string
// Only, when OnlySet, names the writers whose entries this run may
// apply: every writer the token names that Only does not is held, so a
// service that checks a permission holds a writer it never checked
// (one added outside it) as well as one it was refused. An empty Only
// with OnlySet holds every writer. The owner is never held.
Only []string
OnlySet bool
// DryRun plans and reports, and mints nothing.
DryRun bool
// NoWait returns once the settlement leg has taken a token, without
// waiting for it to mine: the token stays recorded as pending, and the
// next run publishes it to the hosts once it is mined (hosts admit a
// token only with its proof). A batch that needs more than one token
// gets its first; the next run mints the rest. A run that meets a
// token still unmined sends the same bytes again and stops there:
// AddWriters and RemoveWriters are then refused, not applied.
NoWait 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
Sent string // with NoWait: the token sent and not yet mined
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
Held []string // writers whose entries this run held back (Options.Hold)
Plan *Plan
}
Report is what an anchoring run did.
type Step ¶
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.
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 ¶
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.