Documentation
¶
Overview ¶
Package archive is a storage adapter for one overlay host: it follows the host's ls_log answers for one producer's stream, checks every answer as a reader does, and writes the batches, the canonical anchor tokens and the proof of each interval to local files, so that the stream outlives the host and an interval can be proved from the files alone.
On-disk layout, under Dir/<stream>/<producer>/ (docs/usage.md, Archive):
archive.json the cursor: the next seq to walk to and
the last interval proven
batches/<seq>-<carrier>.beef each verified carrier, as the host
answered it: its BEEF carries the
funding tree it spends, with the tree's
proof
batches/<seq>-<carrier>.json what was read from it
content/<seq>-<carrier>.log its decoded lines, when the content was
read (full-bytes, or found for a
digest-only batch)
anchors/<interval>-<token>.beef each canonical anchor token, with its
proof
intervals/<interval>.json the interval's proof: the token, its
height, the root, and every seq's
commitment with its RFC 6962 inclusion
path
retracted/<seq>-<carrier>.json the receipt of a stored batch found
retracted: what was read from it, its
commitment, and the sweep that spent
its funding output
retracted/<seq>-<carrier>.sweep.beef
that sweep, with its proof
trees/<txid>.beef each funding tree an anchor token
spends (its fee tree), with its proof,
kept when the anchor is first proven:
a node that prunes spent transactions
stops serving a tree once every output
is spent
The archive is itself a source for an auditor (Answer): it answers the three ls_log question classes from these files, and the auditor checks each answer as it checks a host's.
Each pass first asks the host again for every seq it has stored. A stored carrier the host no longer serves is checked for a retraction: a mined transaction other than the carrier spending its funding output, named by the transaction source and checked against the headers. When one is found the archive writes the receipt and the sweep, then drops the batch's bytes (its BEEF, record file and content). The receipt keeps the seq a numbered position: it completes an interval's root (docs/spec.md section 8.4), and its prev lets a proof continue past it.
<seq> and <interval> are 16 decimal digits, zero padded, so a directory listing is in order; <carrier> and <token> are txids. Every file is written atomically and never rewritten, so a pass that stops part way is continued by the next, and two archives of the same stream hold the same bytes. An interval file records what the archive held when it was proven; a later retraction adds a receipt and does not rewrite it.
Index ¶
Constants ¶
const Version = 1
Version is the cursor's format version.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Archive ¶
type Archive struct {
// Dir is the archive's root; one stream's files are under
// Dir/<stream>/<producer>.
Dir string
Host string
Stream string
Producer []byte
// Client asks Host and checks answers against its Headers; its Asset
// answers the funding trees an anchor's fee inputs spend.
Client *reader.Client
// Fetch finds a digest-only batch's content.
Fetch reader.Fetch
// Note receives one line per thing done.
Note func(format string, args ...any)
// Recheck is how many stored seqs a pass asks the host about again,
// oldest checked first; zero asks about none. RecheckAll asks about
// every stored seq, whatever Recheck says.
Recheck int
RecheckAll bool
}
Archive follows one host into one directory.
func (*Archive) Answer ¶
Answer answers an ls_log question from the files, so that an auditor can use the archive as it uses a host (reader.Source): the stored carriers at a seq, the canonical anchor token of a proven interval, or a kept funding tree. Nothing is checked here; the auditor checks every answer. A question about another stream or producer answers nothing.
func (*Archive) Interval ¶
func (a *Archive) Interval(k uint64) (*IntervalFile, error)
Interval reads intervals/<k>.json.
func (*Archive) LoadCursor ¶
LoadCursor reads the cursor, or starts one.
type BatchFile ¶
type BatchFile struct {
Seq uint64 `json:"seq"`
Carrier string `json:"carrier"`
Prev string `json:"prev"`
Timestamp uint64 `json:"timestamp"`
Count uint64 `json:"count"`
Encoding uint64 `json:"encoding"`
Profile uint64 `json:"profile"`
Size uint64 `json:"size"`
// Funding is the outpoint the carrier spends, txid:vout.
Funding string `json:"funding"`
Host string `json:"host"`
// Content is ok (content/ holds the lines), pending, unsupported or
// invalid.
Content string `json:"content"`
}
BatchFile is batches/<seq>-<carrier>.json.
type Cursor ¶
type Cursor struct {
Version int `json:"version"`
Stream string `json:"stream"`
Producer string `json:"producer"`
// Next is the first seq the walk has not found held.
Next uint64 `json:"next"`
// Intervals is the last interval proven; 1 to Intervals are.
Intervals uint64 `json:"intervals"`
// Hosts are the hosts this archive has followed, in first-use order.
Hosts []string `json:"hosts"`
// Rechecked is the last stored seq a pass asked the host about again;
// the next pass continues after it, wrapping to the first, so the
// seqs asked about longest ago are asked first.
Rechecked uint64 `json:"rechecked,omitempty"`
// Trees is the last interval whose anchor's funding trees are kept
// under trees/; 1 to Trees are. It trails Intervals in an archive
// begun before trees were kept, until a pass catches up.
Trees uint64 `json:"trees,omitempty"`
}
Cursor is archive.json.
type IntervalFile ¶
type IntervalFile struct {
Interval uint64 `json:"interval"`
First uint64 `json:"first"`
Count uint64 `json:"count"`
Root string `json:"root"`
Token string `json:"token"`
Vout int `json:"vout"`
Height uint32 `json:"height"`
Position uint64 `json:"position"`
PrevToken string `json:"prevToken,omitempty"`
// Status is proven (every seq held as a batch or a retraction receipt)
// or proven-with-holes (Holes are seqs whose commitment was recovered
// from the next batch's prev, whose bytes this archive does not hold
// and never held: retracted, or never delivered).
Status string `json:"status"`
Holes []uint64 `json:"holes,omitempty"`
// Retracted are seqs held as a retraction receipt.
Retracted []uint64 `json:"retracted,omitempty"`
Leaves []Leaf `json:"leaves"`
}
IntervalFile is intervals/<interval>.json.
func (*IntervalFile) Anchor ¶
func (f *IntervalFile) Anchor() (*logrec.Anchor, error)
Anchor rebuilds the anchor record an interval file describes, enough to check its paths: the root and the covered range.
func (*IntervalFile) Verify ¶
func (f *IntervalFile) Verify() error
Verify checks every leaf's path against the file's root at its seq, so an interval file can be checked on its own, with no host and no network.
type Leaf ¶
type Leaf struct {
Seq uint64 `json:"seq"`
Commitment string `json:"commitment"`
Held bool `json:"held"`
// Retracted is a seq held as a retraction receipt: its bytes dropped.
Retracted bool `json:"retracted,omitempty"`
// Path is the RFC 6962 inclusion path, leaf to root: each step the
// sibling's hash in hex, prefixed L: when it sits to the left.
Path []string `json:"path"`
}
Leaf is one position of an interval.
type Receipt ¶
type Receipt struct {
BatchFile
// Commitment is C, the carrier's txid, which the anchor commits.
Commitment string `json:"commitment"`
// Sweep is the mined transaction that spent the funding output, and
// SweepHeight the block it is in.
Sweep string `json:"sweep"`
SweepHeight uint32 `json:"sweepHeight"`
}
Receipt is retracted/<seq>-<carrier>.json: a stored batch found retracted, whose bytes were dropped.
type Summary ¶
type Summary struct {
Stored int
Next uint64
Intervals uint64
// Proven are the intervals proven in this pass.
Proven []*IntervalFile
// Stopped says why the interval walk stopped, when it did short of
// what the host holds.
Stopped string
// Refused counts answers refused; Refusals are they, each with what
// answered it.
Refused int
Refusals []reader.Refusal
// Retracted are the seqs whose stored batch this pass found retracted.
Retracted []uint64
// Rechecked is how many stored seqs this pass asked about again, of
// StoredSeqs, the seqs stored when it began.
Rechecked, StoredSeqs int
// Trees is how many funding trees this pass stored; TreesMissing says
// why an earlier interval's trees are still not kept, when they are
// not.
Trees int
TreesMissing string
}
Summary is what one pass did.