bootstrap

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package bootstrap implements Lantern's multi-source trust-bootstrap quorum, as specified in INSTALLER-SPEC.md §3.

The premise: no single source determines Lantern's trust anchor. We query N independent sources in parallel, ask each "what is the current F3-finalized tipset?", and only accept the answer when ≥quorum sources cryptographically agree on the same (instance, tipsetKey, stateRoot).

This is the trust foundation for V1.2 GA: the installer mathematically cannot be fooled by a single compromised gateway, RPC provider, or Lantern operator. The bootstrap quorum runs once at install time and produces the validated trust anchor that all subsequent verification builds on.

Source implementations live in subpackages so they don't drag every dependency into the bootstrap package itself; the Quorum() driver here only depends on the Source interface.

Index

Constants

This section is empty.

Variables

View Source
var ErrInsufficientSources = errors.New("bootstrap: fewer countable sources than quorum")

ErrInsufficientSources is returned when fewer countable sources are supplied than the quorum threshold.

View Source
var ErrQuorumNotReached = errors.New("bootstrap: quorum not reached")

ErrQuorumNotReached is returned when sources respond but no single finality reaches the quorum threshold.

Functions

func FormatReport

func FormatReport(r *QuorumResult) string

FormatReport renders a multi-line human-readable summary of a QuorumResult, suitable for printing under `lantern init`, `lantern doctor`, or error pages in the installer.

Types

type Bucket

type Bucket struct {
	Finality Finality
	Sources  []string
}

Bucket is one distinct (instance, tsk, stateroot) tuple seen during a probe, plus the names of sources that returned it.

type Finality

type Finality struct {
	// Instance is the GPBFT instance that finalized this tipset. Lantern
	// requires it to be > 0 (the bootstrap manifest's initial instance
	// is 0 and we never accept that as a live-chain head).
	Instance uint64
	// TipSetKey is the block CIDs of the finalized tipset, in canonical
	// order (matches gpbft.TipSet.MarshalCBOR / Lotus tipset key form).
	TipSetKey []cid.Cid
	// StateRoot is the state root computed by applying the messages in
	// the finalized tipset. Light clients use this as the trust anchor
	// for state queries at and after the finalized epoch.
	StateRoot cid.Cid
	// Epoch is the chain epoch of the finalized tipset, if known.
	// Optional; used for human-readable display only. Quorum equality
	// does NOT depend on Epoch (because not every source can answer it
	// without extra round-trips).
	Epoch int64
}

Finality is one source's answer to "what is the latest F3-finalized tipset?". Two finalities agree iff they have the same Instance, TipSetKey (as a set, order-insensitive), and StateRoot.

func (Finality) Key

func (f Finality) Key() string

Key returns the canonical equality key for this finality: the joined stringified instance + tipsetkey + stateroot. Used to bucket quorum-agreeing sources.

func (Finality) String

func (f Finality) String() string

String renders the finality for log output.

type Kind

type Kind string

Kind groups sources for quorum-policy decisions.

const (
	// KindLibp2p is a libp2p mainnet bootstrap peer queried directly
	// over the F3 cert-exchange protocol.
	KindLibp2p Kind = "libp2p"
	// KindForest is a public Forest/Lotus JSON-RPC endpoint (e.g.
	// forest-archive.chainsafe.dev).
	KindForest Kind = "forest"
	// KindLanternBeacon is a DHT-discovered Lantern beacon.
	KindLanternBeacon Kind = "lantern-beacon"
	// KindLanternGateway is the Lantern project's gateway. NOT counted
	// in the quorum by default.
	KindLanternGateway Kind = "lantern-gateway"
	// KindUser is a user-supplied --peer endpoint.
	KindUser Kind = "user"
)

type QuorumOptions

type QuorumOptions struct {
	// Quorum is the minimum number of agreeing, counted sources required.
	// Default: 5. Required is enforced before any source is queried;
	// Quorum() returns ErrInsufficientSources if len(sources_counted) <
	// Quorum.
	Quorum int
	// Timeout is the total wall-clock budget. Default: 60s.
	Timeout time.Duration
	// CountGateway: if true, KindLanternGateway sources count toward
	// quorum. Default false; the Lantern gateway is used for fast block
	// fetch but is not part of the trust quorum unless the operator opts
	// in.
	CountGateway bool
	// Progress, if non-nil, is called once per source result as it
	// completes. Useful for live spinners / per-source ✓/✗ in init UX.
	Progress func(SourceResult)
}

QuorumOptions configures a Quorum() run.

type QuorumResult

type QuorumResult struct {
	// Reached is true iff at least Quorum sources agreed on the same
	// finality.
	Reached bool
	// Required is the quorum threshold that was asked for.
	Required int
	// Winning is the finality that reached quorum (zero-value if none).
	Winning Finality
	// Agreeing is the names of sources that agreed on Winning.
	Agreeing []string
	// Results is per-source detail (all sources, in completion order).
	Results []SourceResult
	// Counted is the number of sources whose answers were actually
	// tallied (i.e. counted=true and OK).
	Counted int
	// Buckets summarises the distinct finalities seen, by count.
	Buckets []Bucket
	// Elapsed is the wall-clock time the probe took.
	Elapsed time.Duration
}

QuorumResult is the full output of a quorum probe.

func Quorum

func Quorum(ctx context.Context, sources []Source, opts QuorumOptions) (*QuorumResult, error)

Quorum runs all sources in parallel under a single deadline, tallies their answers, and returns a QuorumResult. If at least opts.Quorum counted sources agreed on the same finality, Reached is true and err is nil. Otherwise err is one of ErrInsufficientSources, ErrQuorumNotReached, or context.DeadlineExceeded.

Quorum never panics on a misbehaving source; per-source failures are recorded in Results and surface to opts.Progress as they happen.

type Source

type Source interface {
	// Name returns a short human-readable identifier for log/error output
	// (e.g. "libp2p-peer:12D3KooW...", "forest-archive", "user-peer:...").
	Name() string

	// Kind returns the source category for quorum policy decisions
	// (e.g. independent operators count, the project's own gateway does
	// not by default). See KindLibp2p / KindForest / KindLanternBeacon /
	// KindLanternGateway / KindUser.
	Kind() Kind

	// LatestFinality asks the source for its view of the most recent
	// F3-finalized result. Returns the GPBFT Instance, the tipset key
	// (block CIDs of the finalized tipset), and the state root after
	// applying that tipset.
	//
	// Implementations should respect ctx and return promptly on
	// cancellation. Network errors should be wrapped to be diagnosable.
	LatestFinality(ctx context.Context) (Finality, error)
}

Source is the narrow interface every bootstrap participant satisfies. Each source answers exactly one question: what is the latest F3 finality result you can attest to?

type SourceResult

type SourceResult struct {
	Name     string
	Kind     Kind
	Finality Finality
	Error    error
	Duration time.Duration
	// Counted is true if this source contributes to the quorum tally
	// (i.e. it's not a non-counted KindLanternGateway when CountGateway
	// is false).
	Counted bool
}

SourceResult records one source's response (or failure) during a quorum probe. Always populated even on error.

func (SourceResult) OK

func (r SourceResult) OK() bool

OK reports whether the source returned a finality without error.

Directories

Path Synopsis
Package sources provides Source implementations for the chain/bootstrap quorum:
Package sources provides Source implementations for the chain/bootstrap quorum:

Jump to

Keyboard shortcuts

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