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
- Variables
- func Allowed(allow []netip.Prefix, remote string) bool
- func NewClient(timeout time.Duration) util.HTTPClient
- func ParseLookupAnswer(raw []byte) (*lookup.LookupAnswer, error)
- func ReplayOnly(topic string) (rule string, ok bool)
- func ShedCount(body []byte) (float64, bool)
- func Topics(carried []string) (gasp []string, replay map[string]string)
- type BridgeLoad
- type Engine
- type Finder
- type Gate
- type GateOptions
- type Options
- type Server
- type ShedWatch
- type Store
- type Submitter
- type Syncer
- func (s *Syncer) Collect(ch chan<- prometheus.Metric)
- func (s *Syncer) Describe(ch chan<- *prometheus.Desc)
- func (s *Syncer) Pull(ctx context.Context, topic, peer string) Tally
- func (s *Syncer) Replay(ctx context.Context, topic, peer string) Tally
- func (s *Syncer) ReplayRound(ctx context.Context) Tally
- func (s *Syncer) Round(ctx context.Context) Tally
- func (s *Syncer) Run(ctx context.Context)
- func (s *Syncer) Trigger()
- type Tally
Constants ¶
const ( DefaultHoldFill = 0.5 DefaultHoldMax = 5 * time.Minute DefaultHoldPoll = time.Second )
Defaults of GateOptions.
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).
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.
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 ¶
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.
var ErrAnswerTooLarge = errors.New("catchup: peer answer exceeds the bound")
ErrAnswerTooLarge is a peer answer past MaxAnswer.
Functions ¶
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 ¶
ReplayOnly reports whether a topic is caught up by its application's own replay and never by GASP, and the rule that says so.
Types ¶
type BridgeLoad ¶ added in v0.16.0
type BridgeLoad struct {
Shed float64 // overlay_bridge_feed_total{outcome="shed"}
Depth, Capacity float64 // overlay_bridge_engine_queue_depth, _capacity
Bytes, BytesCap float64 // overlay_bridge_engine_queue_bytes, _bytes_capacity
HasShed, HasQueue bool
}
BridgeLoad is what one read of the bridge's /metrics says.
func ParseBridgeLoad ¶ added in v0.16.0
func ParseBridgeLoad(body []byte) BridgeLoad
ParseBridgeLoad reads the shed counter and the engine queue gauges from a Prometheus text exposition of overlay-bridge.
func (BridgeLoad) Fill ¶ added in v0.16.0
func (l BridgeLoad) Fill() float64
Fill is the queue's fill: the larger of depth over capacity and bytes over the byte bound (when the bridge has one).
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 Gate ¶ added in v0.16.0
type Gate struct {
// contains filtered or unexported fields
}
Gate holds catch-up's admissions (GASP pulls and ordered replay) while this host's bridge is under pressure: it shed a delivery since the last read, or its engine queue is at least Fill full. Catch-up and the lane take the same per-topic lock, so a catch-up admission during a shed burst slows the live admissions and sheds more (the overload collapse lane L15 measured). The gate fails open: an unreadable bridge holds nothing.
func NewGate ¶ added in v0.16.0
func NewGate(o GateOptions) *Gate
NewGate builds a gate; Run (or Poll) feeds it.
func (*Gate) Observe ¶ added in v0.16.0
func (g *Gate) Observe(l *BridgeLoad)
Observe moves the gate on one read; nil is a failed read, which opens it.
type GateOptions ¶ added in v0.16.0
type GateOptions struct {
// URL is the bridge's /metrics on this host (OVERLAY_GASP_SHED_URL).
URL string
// Fill is the engine queue's fill (depth over capacity, or bytes over
// the byte bound when the bridge has one) at which catch-up holds; it
// resumes once the fill is below half of it and no shed was seen for
// holdReleaseReads reads in a row.
Fill float64
// MaxHold bounds one hold: past it the gate opens until the pressure
// ends, so catch-up never waits for ever.
MaxHold time.Duration
// Poll is how often the bridge is read.
Poll time.Duration
Client *http.Client
Metrics *metrics.Metrics
Log *slog.Logger
}
GateOptions configure a Gate.
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
// Gate, when set, holds each admission while this host's bridge is
// under pressure (gate.go); nil never holds.
Gate *Gate
}
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.
type ShedWatch ¶
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.
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 (*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 ¶
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
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
ReplayRound replays every topic a module repairs by replay from every peer, one walk at a time, and answers the tally.
func (*Syncer) Round ¶
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.