catchup

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 30 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 catchup is the host's GASP catch-up (BRC-88's sync, in the shape the shipped engines speak: since-score lists of unspent outputs, then one node per transaction): it serves the two peer routes a peer pulls from (Server), and pulls from its configured peers what this host is missing (Syncer), on every carried topic but the replay-only ones (ReplayOnly).

What it recovers: an object the bridge shed after delivery (its engine queue was full) and one lost in the store's WAL window on a power loss (ruling R-j). The other hosts hold them, so a pull of each peer's outputs newer than the last one seen from that peer finds them, within one interval.

What it replays: each missing output's transaction as the subject of one submission, with the ancestry SPV needs (the transactions this host already holds, the rest fetched from the peer), through the pipeline: the same parse, overlay-bridge pkg/spv verification, topic lock, topic managers, BEEF blob, index rows and lookup notifications as an object off the lane. Never an ancestor as a subject of its own: the plane delivered each object as one subject, and a manager such as anytx admits every output of whatever it is handed.

What it cannot recover: an output the peer no longer lists, because it is spent there. GASP carries unspent outputs; history a module keeps of spent ones (an anchor's predecessor, a retained coin) comes back only with a later object that needs it, or by the application's own replay.

Index

Constants

View Source
const (
	MaxQuestion = 64 << 10
	MaxPage     = 10_000
)

MaxQuestion bounds a peer route's request body; MaxPage is the most outputs one /requestSyncResponse answers (the TypeScript client's page).

View Source
const (
	DefaultPageLimit = engine.DefaultGASPSyncLimit // outputs per list request
	DefaultMaxNodes  = 1000                        // transactions fetched for one object
	// DefaultReplayRoundQuestions bounds the questions one topic's replay
	// asks one peer in a round (OVERLAY_REPLAY_ROUND_QUESTIONS).
	DefaultReplayRoundQuestions = 1024
)

Defaults of Options.

View Source
const MaxAnswer = 64 << 20

MaxAnswer bounds a peer's answer: a page of outputs, or one node, whose transaction is at most the plane's object ceiling.

Variables

View Source
var (
	ErrWrongNode     = errors.New("catchup: the peer's node is not the transaction asked for")
	ErrGraphTooLarge = errors.New("catchup: the object's unproven ancestry exceeds the node bound")
)

Graph assembly refusals: the peer's answer is not what was asked for.

View Source
var ErrAnswerTooLarge = errors.New("catchup: peer answer exceeds the bound")

ErrAnswerTooLarge is a peer answer past MaxAnswer.

Functions

func Allowed

func Allowed(allow []netip.Prefix, remote string) bool

Allowed reports whether a remote address ("ip:port") may call the routes.

func NewClient

func NewClient(timeout time.Duration) util.HTTPClient

NewClient is the HTTP client the syncer asks its peers with: a deadline per request, an answer bound, and up to three waits on a 429 for the Retry-After it names (at most 10 s each).

func ParseLookupAnswer added in v0.9.0

func ParseLookupAnswer(raw []byte) (*lookup.LookupAnswer, error)

ParseLookupAnswer reads a BRC-24 lookup answer as a host's route writes it: an output-list's outputs with their BEEF and index, and their contexts in Result as []module.HydratedOutput when any has one; a freeform answer's result as raw JSON.

func ReplayOnly

func ReplayOnly(topic string) (rule string, ok bool)

ReplayOnly reports whether a topic is caught up by its application's own replay and never by GASP, and the rule that says so.

func ShedCount

func ShedCount(body []byte) (float64, bool)

ShedCount reads overlay_bridge_feed_total{outcome="shed"} from a Prometheus text exposition.

func Topics

func Topics(carried []string) (gasp []string, replay map[string]string)

Topics splits the carried topics into those GASP carries, in their order, and those it never touches, with the rule for each.

Types

type Engine

type Engine interface {
	ProvideForeignSyncResponse(ctx context.Context, req *gasp.InitialRequest, topic string) (*gasp.InitialResponse, error)
	ProvideForeignGASPNode(ctx context.Context, graphID, outpoint *transaction.Outpoint, topic string) (*gasp.Node, error)
}

Engine is what the peer routes ask of the engine: the fork's two GASP providers, unmodified.

type Finder

type Finder interface {
	FindOutput(ctx context.Context, outpoint *transaction.Outpoint, topic *string, spent *bool, includeBEEF bool) (*engine.Output, error)
}

Finder finds the topic that holds an output: a TypeScript peer names no topic on a node request.

type Options

type Options struct {
	Peers       []string // origins (config.GASPPeers)
	Topics      []string // the topics GASP carries (Topics)
	Interval    time.Duration
	Concurrency int // objects fetched and replayed at once per pull
	Store       Store
	// Held returns a transaction this host already holds, with its ancestry
	// (pkg/store Store.Transaction), or nil.
	Held    func(ctx context.Context, txid chainhash.Hash) (*transaction.Transaction, error)
	Submit  Submitter
	Client  util.HTTPClient
	Ready   func() bool // the first round waits for it, one interval at most
	Metrics *metrics.Metrics
	Log     *slog.Logger
	// PageLimit and MaxNodes default to DefaultPageLimit and DefaultMaxNodes.
	PageLimit uint32
	MaxNodes  int
	// Replay are the replay-only topics a module repairs by ordered replay
	// (replay.go), each with the module's replayer; ReplayQuestions and
	// ReplayObjects bound one call (the bcommon defaults when zero), and
	// ReplayRoundQuestions one topic from one peer in a round
	// (DefaultReplayRoundQuestions when zero).
	Replay               map[string]bmodule.Replayer
	ReplayQuestions      int
	ReplayObjects        int
	ReplayRoundQuestions int
	// Horizon, when set, is the oldest score worth pulling on a topic
	// (microseconds; 0 for no bound): a listed output older than it would
	// be removed again by the topic's retention (the anytx retention), so
	// it is passed as expired, never fetched. A score below 1e14 (a
	// TypeScript peer's milliseconds) is never bounded.
	Horizon func(topic string) float64
}

Options configure a Syncer.

type Server

type Server struct {
	Engine  Engine
	Store   Finder
	Carried []string // OVERLAY_TOPICS
	Topics  []string // the topics GASP carries
	Allow   []netip.Prefix
	Budget  *termsroute.HandshakeBudget
	Metrics *metrics.Metrics
	Log     *slog.Logger
}

Server answers the two GASP peer routes at the root, in the TypeScript host's paths and shapes (overlay-blueprints src/http.ts), so a Go and a TypeScript peer pull from each other:

POST /requestSyncResponse     header x-bsv-topic, body {version, since, limit}
                              -> {UTXOList: [{txid, outputIndex, score}], since}
POST /requestForeignGASPNode  body {graphID: "txid.vout", txid, outputIndex, metadata}
                              (x-bsv-topic optional: the TypeScript client sends none)
                              -> {graphID, rawTx (hex), outputIndex, proof? (hex)}

A refusal is {error} with 400, as the TypeScript host answers it; beyond that host, a caller outside Allow gets 403, one past its request budget 429 with Retry-After, and a storage failure 500. A replay-only topic (ReplayOnly) is never served.

func (*Server) Register

func (s *Server) Register(mux *http.ServeMux)

Register mounts the two routes.

type ShedWatch

type ShedWatch struct {
	URL    string
	Every  time.Duration
	Client *http.Client
	Log    *slog.Logger
}

ShedWatch reads the bridge's shed counter, overlay_bridge_feed_total {outcome="shed"} on its /metrics (a delivery refused because the engine queue was full: the object this host then misses), and calls trigger once a burst has ended: the counter rose, then held for one read. A round run then finds what the burst shed in seconds rather than at the next interval. The first read, and a counter that fell (the bridge restarted), set the baseline.

func (*ShedWatch) Run

func (w *ShedWatch) Run(ctx context.Context, trigger func())

Run polls until ctx ends.

type Store

type Store interface {
	GetLastInteraction(ctx context.Context, host, topic string) (float64, error)
	UpdateLastInteraction(ctx context.Context, host, topic string, since float64) error
	FindOutputs(ctx context.Context, outpoints []*transaction.Outpoint, topic string, spent *bool, includeBEEF bool) ([]*engine.Output, error)
	DoesAppliedTransactionExist(ctx context.Context, tx *overlay.AppliedTransaction) (bool, error)
}

Store is what the syncer reads and writes of the host's storage.

type Submitter

type Submitter interface {
	Submit(ctx context.Context, raw []byte, topics []string) (overlay.Steak, error)
}

Submitter is the pipeline: the admission path every object takes.

type Syncer

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

Syncer pulls from every peer, for every topic GASP carries, what this host is missing. Build it with NewSyncer; it is a prometheus.Collector of overlay_go_gasp_sync_lag_seconds.

func NewSyncer

func NewSyncer(o Options) *Syncer

NewSyncer builds a syncer.

func (*Syncer) Collect

func (s *Syncer) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector: one lag per topic and peer, of the GASP pulls and of the replay walks.

func (*Syncer) Describe

func (s *Syncer) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

func (*Syncer) Pull

func (s *Syncer) Pull(ctx context.Context, topic, peer string) Tally

Pull is one GASP pull of topic from peer: every output the peer lists with a score at or past this host's cursor for the pair, page by page; each one this host lacks is replayed; the cursor moves to the last output before the first object that got no verdict.

func (*Syncer) Replay added in v0.9.0

func (s *Syncer) Replay(ctx context.Context, topic, peer string) Tally

Replay is one topic's ordered replay from one peer in a round: the module's replayer called until its walk is done or the round's question budget (ReplayRoundQuestions) is spent, each answer's objects submitted in order.

func (*Syncer) ReplayRound added in v0.9.0

func (s *Syncer) ReplayRound(ctx context.Context) Tally

ReplayRound replays every topic a module repairs by replay from every peer, one walk at a time, and answers the tally.

func (*Syncer) Round

func (s *Syncer) Round(ctx context.Context) Tally

Round pulls every topic GASP carries from every peer, one pull at a time, then replays every topic a module repairs by replay from every peer (replay.go). It answers the GASP pulls' tally.

func (*Syncer) Run

func (s *Syncer) Run(ctx context.Context)

Run pulls once the host is ready (after one interval at the latest), then every interval and after each Trigger, until ctx ends. With no peer or no topic it returns at once.

func (*Syncer) Trigger

func (s *Syncer) Trigger()

Trigger asks for a round now, after the one running if any. Asked twice before it starts, it runs once.

type Tally

type Tally struct {
	Pulls, Missing int
	Results        map[string]int // per pull result
	Objects        map[string]int // per object result
	Nodes          int
}

Tally is what one pull, or one round, did.

Jump to

Keyboard shortcuts

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