reader

package
v0.2.1 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: 23 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 reader asks overlay hosts the three ls_log questions and checks every answer itself (docs/spec.md sections 7.2 and 13): a batch carrier's rules, its funding parent's proof against the reader's own headers, an anchor token's rules and its proof, a funding tree's txid and proof, the chain of anchors and an interval's root. A host is trusted for nothing: an answer is either verified here or reported as refused, and an empty answer means only that the host holds nothing that answers.

Index

Constants

This section is empty.

Variables

View Source
var ErrOtherBytes = errors.New("other bytes")

ErrOtherBytes is a source that answered a txid with another transaction: a source that lies, which is an error rather than missing evidence.

View Source
var ErrPending = errors.New("content pending: no configured source holds it")

ErrPending is content no configured source had: the batch is valid, its bytes are elsewhere.

View Source
var ErrUnsupported = errors.New("content unsupported by this version")

ErrUnsupported is a batch whose profile, encoding or locator this version does not read.

Functions

func Content

func Content(ctx context.Context, b *logrec.Batch, f Fetch) ([]byte, error)

Content returns a batch's decoded content: the carried bytes, or the fetched ones for a digest-only batch, decoded and held to size and count. An unsupported profile, encoding or locator is reported as such, never as a refusal: the batch is still a valid link.

func Linked

func Linked(prev, cand *Candidate) bool

Linked reports whether cand's prev is prev's commitment.

func SourceName

func SourceName(name string) string

SourceName names what answered: "host URL", or a local source's own name.

Types

type Answer

type Answer struct {
	Host   string
	Beef   []byte
	Output uint32
}

Answer is one output a host answered, and which host.

type Backfill

type Backfill struct {
	// From are the siblings, asked in order.
	From     []string
	To       string
	Stream   string
	Producer []byte
	// Intervals, when above zero, backfills the anchor chain 1 to
	// Intervals, in order, since a host admits an anchor only once it
	// holds its predecessor.
	Intervals uint64
	Seqs      []uint64
	// Sweeps carries sweeps to To: for each seq To holds, every candidate
	// it serves is checked for a retraction (Client.Retraction: a mined
	// spend of its funding output by another transaction, named by Txs,
	// which must answer spends), and a sweep found is submitted to To. No
	// lookup class names the sweep of a batch, so this is the only way a
	// backfill can carry one; it costs one spend read per held carrier.
	Sweeps bool
	// Note receives one line per position.
	Note func(format string, args ...any)
}

Backfill fills holes in one host (To) from its siblings (From): the anchor tokens of intervals 1 to Intervals and the batches at Seqs, each asked of To first and, only when To holds nothing, fetched from the first sibling whose answer verifies (a sibling that answers what does not verify is named, and the next is asked), and submitted to To's submit route (docs/spec.md section 12, Archive). It is also how a host that missed a unicast producer's submissions is repaired from the hosts that took them.

type Candidate

type Candidate struct {
	Carrier *logrec.Carrier
	Tx      *transaction.Transaction
	Beef    []byte
	Host    string
}

Candidate is a verified batch carrier.

func Link(cands []*Candidate, next *Candidate) (*Candidate, bool)

Link chooses, among the candidates at a seq, the one the next batch's prev names. With no next batch, or none named, a single candidate is chosen; several are a fork the caller reports.

type ChainSource added in v0.2.0

type ChainSource struct {
	Chain nodeapi.Chain
	// Label names the view in messages, such as its specification.
	Label string
}

ChainSource is a chain view (nodeapi.ParseChain): a node, WhatsOnChain, or both. Its transactions are held to the txid and its proofs to the header source the view was built with (nodeapi.Checked).

func (ChainSource) Name added in v0.2.0

func (s ChainSource) Name() string

Name names the view.

func (ChainSource) Spender added in v0.2.0

func (s ChainSource) Spender(ctx context.Context, txid string, vout uint32) (string, error)

Spender is the view's answer (nodeapi.SpendSource): the spender of output vout of txid, or "" with a nil error only on the view's evidence that the output is unspent. Every other answer is an error wrapping nodeapi.ErrSpendUnknown.

func (ChainSource) Tx added in v0.2.0

func (s ChainSource) Tx(ctx context.Context, txid string, proof bool) (*transaction.Transaction, error)

Tx reads the raw transaction and, with proof, its merkle path.

type Client

type Client struct {
	// Hosts are the overlay hosts' base URLs, asked in order.
	Hosts []string
	// Local are sources asked before the hosts (an archive's files); their
	// answers are checked as a host's are.
	Local []Source
	// Headers is the reader's own header source. Nil skips the proof
	// checks, which only backfill allows: the host it submits to checks
	// proofs itself.
	Headers chaintracker.ChainTracker
	// HeaderSource names Headers in messages (its URL).
	HeaderSource string
	// Txs, when set, is a copy of the chain answering transactions by
	// txid: a funding tree no host asked serves by the tree class, and the
	// spender of a funding output.
	Txs TxSource
	// ProveTrees asks Txs for a funding tree's proof too and checks it, so
	// that the tree can be kept or passed on with it (an archive).
	ProveTrees bool
	// Timeout bounds each request; HTTP, when set, is the client used (tests).
	Timeout time.Duration
	HTTP    *http.Client
}

Client asks hosts and checks their answers.

func (*Client) Ask

func (c *Client) Ask(ctx context.Context, base string, q Query) ([]Answer, error)

Ask asks one host one question.

func (*Client) AskAny

func (c *Client) AskAny(ctx context.Context, q Query, all bool) ([]Answer, error)

AskAny asks the local sources and then the hosts, in order, and returns the first non-empty answer. all asks every one and returns every answer each gave, so that one that does not verify is named whatever else answered beside it. Sources and hosts that fail are skipped; when every one failed, the first failure is returned.

func (*Client) Batch

func (c *Client) Batch(ctx context.Context, stream string, producer []byte, seq uint64, all bool) ([]*Candidate, []Refusal, error)

Batch asks for the batch at seq and checks every answer. all asks every host, so that a fork is seen and a host that answers what does not verify is named whatever another answered; otherwise the first host that answers is used. Each transaction is one candidate however many hosts answered it; each answer refused is returned with what answered it.

func (*Client) CheckCarrier

func (c *Client) CheckCarrier(ctx context.Context, a Answer, stream string, producer []byte, seq uint64) (*Candidate, Verdict)

CheckCarrier holds one answered output to what the batch at seq of producer on stream must be: the carrier rules of section 8.1 (the producer set being just this producer), the asked seq, output 0, and SPV through its funding parent against the reader's headers.

func (*Client) CheckTree

func (c *Client) CheckTree(ctx context.Context, a Answer, txid string) (tx *transaction.Transaction, why string, err error)

CheckTree holds one answer of the tree class to the question: the BEEF's subject is the transaction asked for (its double SHA-256 is txid), the answered output exists, and the proof the BEEF carries for it verifies against the reader's headers. A conforming host holds only mined trees, so an answer with no proof is refused. With no header source (which only backfill allows) the proof must be present and is left to the host the tree is submitted to.

why names a refusal; an error means the headers could not be asked.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, txid string, proof bool) (*transaction.Transaction, error)

Fetch asks the source for txid and holds the answer to it: the bytes must hash to the txid asked for, and with proof a merkle path must come too. The path itself is the caller's to check against its headers.

func (*Client) FundingTree

func (c *Client) FundingTree(ctx context.Context, stream, txid string) (tx *transaction.Transaction, from, missing string, refused []Refusal, err error)

FundingTree finds the transaction txid whose output an anchor's input spends: by the tree class from the local sources and the hosts, then from Txs (a copy of the chain). A tree from the tree class always comes with a proof checked against the headers; one from Txs is held to the txid, and comes with a checked proof when ProveTrees is set. from names what answered it; missing says where it was looked for when nothing did; refused are the tree class's answers that did not verify, each named.

func (*Client) Next

func (c *Client) Next(ctx context.Context, stream string, producer []byte, k uint64, prev *Token, evidence map[string]*transaction.Transaction) (*Token, *Report, error)

Next is one step of the walk VerifyInterval makes, for a verifier that keeps the chain between runs: it finds interval k's canonical token among the hosts' answers, given the canonical token of interval k - 1 (nil for k = 1), and holds it to the join and the anchor rules. The outputs its inputs spend are read from prev, from evidence (transactions by txid, to which a funding tree found is added), from the tree class, or from Txs. An error is no verdict.

func (*Client) Retraction

func (c *Client) Retraction(ctx context.Context, cand *Candidate) (sweep *transaction.Transaction, why string, err error)

Retraction looks for the evidence that a stored carrier was retracted (docs/spec.md section 8.4): a transaction other than the carrier that spends its funding outpoint and is mined in the reader's headers. Txs must also be a SpendSource to name the spender, whose answer is only a lead: the spender is fetched with its proof by txid and checked here. With no such transaction, why says what was found; an error is a source that answered other bytes for a txid, or no header source. Only the source's evidence notes the output unspent: a source that cannot say (nodeapi.ErrSpendUnknown, or any other error) notes that, and nothing is concluded.

func (*Client) Run

func (c *Client) Run(ctx context.Context, b Backfill) (Result, error)

Run runs the backfill. An error is a transport failure; positions the sibling held nothing for, or that To did not admit, are counted.

func (*Client) Token

func (c *Client) Token(ctx context.Context, a Answer, stream string, producer []byte, k uint64) (t *Token, why string, err error)

Token reads one answered anchor token for interval k of producer's stream: its record, its producer and stream, and a proof the headers hold. why names a refusal; an error means the headers could not be asked.

func (*Client) Tree

func (c *Client) Tree(ctx context.Context, stream, txid string) (tx *transaction.Transaction, from string, tried []string, refused []Refusal, err error)

Tree asks for the mined funding tree txid of stream by the tree class (docs/spec.md section 7.2): the local sources first, then the hosts in order, each answer held to CheckTree. Every source is asked, so that one that answers what does not verify is named whatever another answered; the first answer that passes is returned with the name of what answered it, and every answer refused in refused. With none, tried says what each source did: held nothing, answered something refused, or could not be asked (a host that predates the tree class refuses the question).

func (*Client) VerifyInterval

func (c *Client) VerifyInterval(ctx context.Context, stream string, producer []byte, n uint64) (*Report, error)

VerifyInterval is the auditor's check of docs/spec.md section 13 for interval n of producer's stream: it walks the interval class from 1 to n, keeping each interval's canonical token (interval 1: the one mined first; each later one: the one that spends its predecessor), holds every token to the anchor rules and its proof to the reader's headers, then asks the batch class for every seq interval n covers and requires the root over their commitments to equal the token's. A seq no host serves takes its commitment from the next batch's prev, as an archive's does, and is reported in Unserved; one whose commitment nothing names leaves the interval Incomplete. The outputs a token's inputs spend are read from the predecessor token's transaction, from the funding trees the interval's carriers carry, from the tree class (the local sources and the hosts, each tree's proof checked against the headers), or from Txs.

An error is no verdict: a host or the header source could not be asked.

type Fetch

type Fetch struct {
	Dirs  []string
	Allow []string
	// HTTP is the client for hints; nil is a client with no proxy that
	// follows no redirect off the origin. Its CheckRedirect is replaced
	// either way.
	HTTP    *http.Client
	Timeout time.Duration
}

Fetch is how a reader obtains a digest-only batch's content (docs/spec.md section 9.2): from local directories holding files named by the digest in hex, or over HTTPS from a locator's hint whose host is on Allow. A hint whose host is not on the list is never fetched.

func (Fetch) Get

func (f Fetch) Get(ctx context.Context, l *logrec.Locator) ([]byte, error)

Get returns the bytes a locator names, checked against its length and digest. Bytes that fail are discarded.

type Outcome

type Outcome int

Outcome is an audit's verdict.

const (
	// Verified: the interval is complete and proven.
	Verified Outcome = iota
	// Refused: the evidence contradicts the claim.
	Refused
	// Incomplete: some evidence was not found; nothing is proven either
	// way, since an empty answer proves nothing.
	Incomplete
)

type Query

type Query struct {
	Stream   string `json:"stream"`
	Producer string `json:"producer,omitempty"`
	Seq      uint64 `json:"seq,omitempty"`
	Interval uint64 `json:"interval,omitempty"`
	Tree     string `json:"tree,omitempty"`
}

Query is one ls_log question: Producer with exactly one of Seq and Interval (the batch and interval classes), or Tree alone, a txid (the tree class).

type Refusal

type Refusal struct {
	What   string
	Host   string
	Reason string
}

Refusal is one answer that did not verify: what was asked, what answered it (a host's URL, or a local source's name), and why. What it answered is not used.

func (Refusal) String

func (r Refusal) String() string

type Report

type Report struct {
	Outcome Outcome
	Reason  string
	// Chain is the canonical token of each interval walked, 1 to n.
	Chain []*Token
	// Batches are the interval's batches in seq order, as chosen by the
	// root.
	Batches []*Candidate
	// Missing are seqs of the interval no host answered whose commitment
	// could not be recovered.
	Missing []uint64
	// Unserved are seqs of a verified interval that no host serves, each
	// commitment taken from the next batch's prev, as an archive proves an
	// interval across a retraction (docs/spec.md section 8.4). A host
	// serves nothing for a retracted batch or for one it never received,
	// and a lookup cannot tell the two apart, so the auditor names the
	// position, not the cause. Batches holds none for them.
	Unserved []uint64
	// Unverified are seqs of a verified interval that hosts answered only
	// with what does not verify: each answer is in Refusals and none is
	// used, and each commitment is taken from the next batch's prev, as
	// for an unserved seq. Batches holds none for them.
	Unverified []uint64
	// Refusals are the answers refused along the way, each with what
	// answered it: a host that answers what does not verify is named, and
	// the audit is incomplete for it whatever else verified.
	Refusals []Refusal
	// Trees are the funding trees the anchors' inputs spend that were
	// fetched for this audit, and what answered each.
	Trees []TreeUse
}

Report is what verify-interval found.

type Result

type Result struct {
	Held, Filled, Missing, Refused, Unserved, Sweeps int
}

Result counts what a backfill did. Unserved are seqs no host serves whose commitment the next seq filled or held names (its prev), as an archive and verify-interval prove an interval across a retraction (docs/spec.md section 8.4): retracted, or never delivered to any host asked, which a lookup cannot tell apart. A missing seq nothing names stays Missing. Sweeps counts sweeps carried to the host (Backfill.Sweeps).

type Source

type Source interface {
	Answer(q Query) ([]Answer, error)
	// Name names the source in messages.
	Name() string
}

Source answers ls_log questions from somewhere other than a host: an archive's files. Its answers are checked exactly as a host's are.

type SpendSource

type SpendSource = nodeapi.SpendSource

SpendSource answers which transaction spent an output, for an archive checking whether a batch it stored was retracted (nodeapi.SpendSource). Its answer is never trusted: Client.Retraction fetches the spender with its proof and checks that it spends the output and is mined in the reader's headers.

type Token

type Token struct {
	Anchor *logrec.Anchor
	Tx     *transaction.Transaction
	Txid   string
	Vout   int
	Height uint32
	Index  uint64 // position in its block
}

Token is one canonical anchor token of the chain walked.

type TreeUse

type TreeUse struct {
	Interval uint64
	Txid     string
	// From names the source: a host, an archive, or the copy of the chain.
	From string
}

TreeUse is one funding tree an audit fetched.

type TxSource

type TxSource interface {
	// Tx returns the transaction; with proof, carrying its merkle path.
	Tx(ctx context.Context, txid string, proof bool) (*transaction.Transaction, error)
	// Name names the source in messages.
	Name() string
}

TxSource is a copy of the chain answering a mined transaction by its txid: a funding tree an anchor's input spends that no host asked serves by the tree class, a sweep, a payment. Its answer is never trusted. The caller holds the bytes to the txid it asked for, and a proof, when it needs one, to its own header source.

type Verdict

type Verdict struct {
	Code   verify.Code
	Reason string
}

Verdict is the outcome of checking one answer.

func (Verdict) OK

func (v Verdict) OK() bool

OK reports a verified answer.

Jump to

Keyboard shortcuts

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