subscriber

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: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CertSource

type CertSource interface {
	GetCert(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error)
	GetLatest(ctx context.Context) (*certs.FinalityCertificate, error)
}

CertSource pulls F3 certs over the wire.

type JSONRPCSource

type JSONRPCSource struct {
	URL    string
	Client *http.Client
}

JSONRPCSource implements CertSource via a Lotus-compatible JSON-RPC endpoint (Filecoin.F3GetCertificate / Filecoin.F3GetLatestCertificate).

func NewJSONRPCSource

func NewJSONRPCSource(url string) *JSONRPCSource

NewJSONRPCSource returns a JSONRPCSource with a 20s default timeout.

func (*JSONRPCSource) GetCert

func (s *JSONRPCSource) GetCert(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error)

GetCert calls Filecoin.F3GetCertificate(instance).

func (*JSONRPCSource) GetLatest

GetLatest calls Filecoin.F3GetLatestCertificate.

type Options

type Options struct {
	// Anchor is the embedded F3 trust anchor (Instance, committee).
	Anchor *anchor.Anchor
	// Manifest is the F3 network manifest (NetworkName).
	Manifest *manifest.Manifest
	// Source is the cert source (Forest/Lotus RPC).
	Source CertSource
	// DB is an optional BadgerDB for persistence of (instance, powerTable).
	DB *badger.DB
}

Options configures a Subscriber.

type PeerProvider

type PeerProvider interface {
	// Peers returns the currently known-good Lantern beacon set. May
	// return an empty slice during cold start; callers handle that by
	// falling back to the JSON-RPC fallback.
	Peers() []peer.AddrInfo
}

PeerProvider is the minimal callback shape the SwarmCertSource needs to discover Lantern beacons it can query. The beacon's startup wires this to the DHT rendezvous discovery loop; tests pass a static slice via StaticPeerProvider.

type State

type State struct {
	NetworkName gpbft.NetworkName
	Instance    uint64                     // next instance to verify
	PowerTable  gpbft.PowerEntries         // committee at Instance
	Latest      *certs.FinalityCertificate // most recently verified cert
	LatestChain *gpbft.ECChain             // its EC chain (head = finalized)
}

State is the in-memory follower state.

type StaticPeerProvider

type StaticPeerProvider []peer.AddrInfo

StaticPeerProvider returns a fixed peer list. Used by tests and by operators who want to pin a specific beacon set instead of relying on DHT discovery.

func (StaticPeerProvider) Peers

func (s StaticPeerProvider) Peers() []peer.AddrInfo

Peers returns the fixed peer list.

type Stats

type Stats struct {
	CertsVerified uint64
	LastInstance  uint64
	LatestFinalEp int64
	LastError     string
}

Stats tracks subscriber activity.

type Subscriber

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

Subscriber walks F3 certs from anchor forward.

func New

func New(opts Options) (*Subscriber, error)

New builds a Subscriber. Caller must call Bootstrap before Walk.

func (*Subscriber) State

func (s *Subscriber) State() State

State returns a snapshot of the current follower state.

func (*Subscriber) Stats

func (s *Subscriber) Stats() Stats

Stats returns activity counters.

func (*Subscriber) Walk

func (s *Subscriber) Walk(ctx context.Context, maxCerts int) (int, error)

Walk pulls certs from the source starting at s.state.Instance, validates each, and advances state. It walks up to maxCerts or until the latest cert is reached, whichever is first. Returns the number of certs walked.

type SwarmCertSource

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

SwarmCertSource implements CertSource over a pool of libp2p Lantern beacons, with a JSON-RPC fallback. Goroutine-safe.

func NewSwarmCertSource

func NewSwarmCertSource(cfg SwarmConfig) (*SwarmCertSource, error)

NewSwarmCertSource constructs a SwarmCertSource. Host and Fallback are required; everything else has defaults.

func (*SwarmCertSource) GetCert

func (s *SwarmCertSource) GetCert(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error)

GetCert tries the swarm first, then falls back. Unlike GetLatest there's no staleness to evaluate; we just want the specific instance.

func (*SwarmCertSource) GetLatest

GetLatest tries the swarm first, then falls back.

func (*SwarmCertSource) Stats

func (s *SwarmCertSource) Stats() SwarmStats

Stats returns a snapshot of activity counters.

type SwarmConfig

type SwarmConfig struct {
	// Host is the libp2p host used to dial Lantern beacons.
	Host host.Host
	// NetworkName is the F3 network name baked into the protocol id.
	// Defaults to "filecoin" (mainnet).
	NetworkName string
	// Provider returns the current pool of Lantern beacons.
	Provider PeerProvider
	// Fallback is the CertSource used when no swarm peer answers in time
	// or when all answers are stale. Typically a JSONRPCSource pointing
	// at Glif or a sibling Forest/Lotus.
	Fallback CertSource
	// PerPeerTimeout caps each libp2p call. Default 4s.
	PerPeerTimeout time.Duration
	// StaleAfter declares a swarm answer stale and triggers a fallback
	// when the cert's timestamp is older than this. Default 5 minutes.
	StaleAfter time.Duration
}

SwarmConfig configures a SwarmCertSource.

type SwarmStats

type SwarmStats struct {
	LastUpstream string // human-readable, e.g. "libp2p:12D3Koo..." or "fallback"
	TotalCalls   uint64
	SwarmHits    uint64
	SwarmMisses  uint64
	FallbackHits uint64
}

SwarmStats reports observable activity for the dashboard / lantern info.

Jump to

Keyboard shortcuts

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