feed

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 23 Imported by: ? 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 feed turns delivered BRC-149 records into ordinary engine submits.

It is the lane handler for objfmt.ClassBEEFDelivery. Each record carries the identifier of the topic that matched, the payload's length, and the payload verbatim: the publisher's submission record (every topic name it wrote, then the BEEF object) or, from an older edge, the bare object. The feed splits on the explicit length, unwraps the payload, maps the identifier back to the name the host elected, and submits the object to the engine under that name and under every other elected name in the record, on the interface the engine already serves. What happens next is what happens for any client: the engine parses, verifies by SPV against its chain tracker, runs the topic manager, stores admitted outputs, notifies lookup services, and answers with admittance instructions.

The lane is open, so nothing here trusts it

The plane is open to any publisher: the bytes on this lane are whatever some publisher chose to send, and the network never parses past the leading marker, by design. Every length an object declares is therefore checked against the bytes actually present before anything of that size is allocated, and a parser failure is a rejected object rather than an incident. The codec does the length checking; this package adds the ceiling and the marker gate, and refuses anything that fails either.

Index

Constants

View Source
const (
	// AlsoOK: the target answered 200.
	AlsoOK = "ok"
	// AlsoRefused: the target answered a 4xx; it is not asked again.
	AlsoRefused = "refused"
	// AlsoError: the target failed or could not be reached on every try.
	AlsoError = "error"
	// AlsoShed: the queue was full, or its workers were not running.
	AlsoShed = "shed"
)

The results of one offer.

View Source
const (
	// StageVerify: the worker is running the bridge's own SPV verification
	// of the object (only with VerifyMode shadow or enforce).
	StageVerify = "verify"
	// StageSubmit: the worker is waiting on an engine submit for one of the
	// object's topics, retries and backoff included.
	StageSubmit = "submit"
)

The worker stages a busy-worker count is kept for.

View Source
const (
	// ShadowMatch: both engines admitted the same outputs and retained the
	// same coins (both answering nothing is a match: the duplicate answer).
	ShadowMatch = "match"
	// ShadowPrimaryOnly: the primary admitted or retained something and the
	// shadow nothing.
	ShadowPrimaryOnly = "primary_only"
	// ShadowShadowOnly: the shadow admitted or retained something and the
	// primary nothing.
	ShadowShadowOnly = "shadow_only"
	// ShadowDiffer: both answered something, and not the same thing.
	ShadowDiffer = "differ"
	// ShadowError: the shadow could not be reached, refused the object,
	// failed, or answered with no entry for the topic. Nothing to compare.
	ShadowError = "shadow_error"
	// ShadowDropped: the shadow's queue was full, or its workers were not
	// running, so the object was never offered to it.
	ShadowDropped = "shadow_dropped"
)

The comparison kinds, one per topic submit.

View Source
const (
	// OutcomeAdmitted: the engine admitted at least one output.
	OutcomeAdmitted = "admitted"
	// OutcomeEmpty: the engine answered for the topic with nothing admitted.
	// This is the host's duplicate answer and the expected steady state, not
	// an alarm: the delivery pool replays its last written object on every
	// reconnect, and edge listeners restart on every converge, so duplicates
	// are routine. It is also the only duplicate signal either engine offers,
	// since neither exposes a metrics registry.
	OutcomeEmpty = "empty"
	// OutcomeError: the engine answered 200 with no entry for the topic we
	// submitted. That is a contract violation by the host, not a duplicate.
	OutcomeError = "error"
	// OutcomeRefused: the engine answered 4xx, refusing the object on its
	// merits (an invalid or malformed BEEF). Used on the submit-duration
	// histogram only.
	OutcomeRefused = "refused"
	// OutcomeEngineError: the engine could not be reached, or answered 5xx,
	// through every retry. Used on the submit-duration histogram only.
	OutcomeEngineError = "engine_error"
)

Outcome values. These are the only three, and the distinction between them is what tells an operator whether the host is working.

View Source
const (
	// MismatchBridgeOKEngineRefused: the bridge passed an object the engine
	// refused (4xx). Under enforce, the engine would have been told to skip
	// scripts for it, so this is the kind that must stay at zero.
	MismatchBridgeOKEngineRefused = "bridge_ok_engine_refused"
	// MismatchBridgeRefusedEngineOK: the bridge refused an object the engine
	// accepted. Under enforce, the object would not have reached the engine.
	MismatchBridgeRefusedEngineOK = "bridge_refused_engine_ok"
)

Mismatch kinds: the two ways the bridge and the engine can disagree.

View Source
const DefaultRoute = "default"

DefaultRoute is the label of the unrouted engines in metrics.

View Source
const DefaultStopDrain = 30 * time.Second

DefaultStopDrain is the drain allowed at stop when StopDrain is 0.

View Source
const IdleConnsPerEngine = 256

IdleConnsPerEngine is how many idle connections the submit clients keep to one engine. Go's default transport keeps 2, so with more concurrent submits than that (the feed's workers, the shadows', the facade's) a connection closed after every answer above the second and the next submit dialled anew: a TCP setup and an engine-side connection per object at load. The pool only grows to the concurrency actually used.

Variables

AlsoResults lists every result, for presetting series at zero.

View Source
var ErrShed = errors.New("feed: engine queue full, delivery shed")

ErrShed reports a delivery refused because the engine queue was full.

MismatchKinds lists every kind, for presetting series at zero.

ShadowKinds lists every kind, for presetting series at zero.

View Source
var WorkerStages = []string{StageVerify, StageSubmit}

WorkerStages lists the stages, for presetting series at zero.

Functions

func Classify added in v0.5.0

func Classify(primary, shadow *overlay.AdmittanceInstructions) string

Classify compares the primary's answer for a topic with the shadow's. A nil answer is an engine that answered nothing for the topic.

func NewTopicMap

func NewTopicMap(names []string) map[[32]byte]string

NewTopicMap builds the identifier map from elected topic names.

func ParseRoute added in v0.6.0

func ParseRoute(s string) (pattern, primary, shadow string, err error)

ParseRoute parses one `-engine-route` value:

GLOB=PRIMARY[,shadow=SHADOW][,also=TARGET]...

PRIMARY, SHADOW and each TARGET are bare submit origins like -engine. It returns the parts; the caller builds the clients. ParseRouteSpec also returns the also targets.

func Refused added in v0.4.0

func Refused(err error) bool

Refused reports whether err is the engine refusing the object (a 4xx).

Types

type Also added in v0.10.0

type Also struct {
	// Submit is the target's client.
	Submit Submitter
	// Name labels the route (its glob) and Target the target's origin, in
	// logs and metrics.
	Name, Target string
	// Workers drain the queue; zero takes 2.
	Workers int
	// QueueDepth bounds the objects waiting; zero takes 1024.
	QueueDepth int
	// QueueBytes bounds the bytes waiting or in a worker's hands; zero
	// takes 256 MiB. An object larger than the bound on its own is shed.
	QueueBytes int64
	// Retries is how many times a failed submit is tried again; zero takes
	// 3, a negative value none.
	Retries int
	// Backoff is the wait before the first retry, growing linearly; zero
	// takes 500 ms.
	Backoff time.Duration
	Log     *slog.Logger
	// contains filtered or unexported fields
}

Also hands every object its route's primary is handed to one more local target: a second subscriber at the same site, fed from the same subscription. The case it exists for is a storage provider beside an overlay host: one consumer elects a bucket's records topic, the host's engine indexes the entries and the provider needs them too, to take the pieces it holds.

It is not a shadow. Nothing is compared. A target that refuses an object (a 4xx) is booked and not asked again, as the primary is not; one that fails (a 5xx, or unreachable) is asked again a bounded number of times. The offer never blocks its caller: it is a put on a queue bounded by count and by bytes, drained by the target's own workers, and an object that does not fit is shed and counted. A target that is slow or down costs the primary path nothing but the counter.

On the feed an Also is offered every object the plane delivered under the route's topics and the bridge's SPV let through; on the facade, every submission the primary accepted, which is how the site's other subscriber gets what own-traffic exclusion keeps the plane from delivering back.

func (*Also) Offer added in v0.10.0

func (a *Also) Offer(topic string, object []byte)

Offer queues one object for the target under one topic. It never blocks, and a nil Also accepts the call and does nothing, so callers need no guard. The object is held, not copied: callers hand over bytes they no longer write to.

func (*Also) Running added in v0.10.0

func (a *Also) Running() bool

Running reports whether the workers are draining the queue.

func (*Also) Start added in v0.10.0

func (a *Also) Start(ctx context.Context) error

Start runs the workers until ctx is cancelled. Offers made before it runs are shed and counted, never queued for a drain that is not coming.

func (*Also) Stats added in v0.10.0

func (a *Also) Stats() AlsoStats

Stats returns a snapshot.

type AlsoStats added in v0.10.0

type AlsoStats struct {
	Results       map[string]uint64
	Queued        int
	Capacity      int
	QueuedBytes   int64
	CapacityBytes int64
}

AlsoStats is a snapshot: Results by result, and the queue now.

type Answer

type Answer struct {
	Steak overlay.Steak
	// Wrapped reports whether the engine wrapped its answer as
	// {"STEAK": {...}} rather than answering the bare map. A facade relaying
	// this to a client must re-emit the same form: a client written against
	// one engine and pointed at the facade would otherwise stop being able to
	// read the reply, which defeats the point of serving the engine's own
	// interface.
	Wrapped bool
}

Answer is an engine's reply plus the one detail of its shape that a caller relaying the reply has to preserve.

type BusyKey added in v0.7.0

type BusyKey struct{ Route, Stage string }

BusyKey buckets busy workers by the route whose engine the work is for (DefaultRoute or a route's pattern) and by stage. Verification counts under the route of the topic the plane delivered the object under.

type Client

type Client struct {
	// Base is the engine's submit origin, mounted at ROOT: no /api/v1 prefix.
	// The TypeScript host mounts POST /submit on the Express app root and
	// offers no way to set a base path, so a prefix here is simply wrong for
	// the round-one target.
	Base string
	// HTTP is the client to use. Nil builds one with Timeout.
	HTTP *http.Client
	// Timeout is the per-submit ceiling when HTTP is nil. Default 30s.
	Timeout time.Duration
	Log     *slog.Logger
}

Client is the BRC-22 submit client.

It is hand-rolled on purpose. One client has to speak to two engines whose /submit responses differ, and the SDK's own HTTPS facilitator speaks to neither reliably: it decodes straight into a bare STEAK, which is right for the TypeScript engine and wrong for the Go one (which wraps the answer, so the facilitator returns no error and a one-entry map keyed literally "STEAK" with every instruction slice empty), and it sends the topic header as a JSON array, which the Go engine's generated binder splits on commas and then rejects. Both failures are silent in the shape that matters: a success that reads as an empty admittance.

The request form below is the single form BOTH engines accept, so the feed needs no per-host dialect.

func (*Client) Submit

func (c *Client) Submit(ctx context.Context, topic string, object []byte) (overlay.Steak, error)

Submit posts one object to one topic and returns the engine's admittance instructions.

Three details of the request are load-bearing rather than polite:

  • Content-Type must be application/octet-stream. The TypeScript host parses the body with a raw parser bound to exactly that type, so any other value leaves the body empty and the submit fails with a missing BEEF body; the Go engine's size limiter likewise only engages on it.
  • x-topics carries ONE topic name, with no spaces, sent ONCE. The Go server reads a JSON array as a single topic name and answers 500, and the TypeScript host refuses a repeated header; one plain name in one header is the form neither engine can misread. A delivery record carries exactly one topic identifier, so there is never cause to send more.

func (*Client) SubmitDetail

func (c *Client) SubmitDetail(ctx context.Context, topic string, object []byte) (Answer, error)

SubmitDetail is Submit, and also reports the answer's wrapper form.

func (*Client) SubmitMarked added in v0.4.0

func (c *Client) SubmitMarked(ctx context.Context, topic string, object []byte, marker string) (overlay.Steak, error)

SubmitMarked is Submit with the SPV trust marker attached, when marker is not empty. Only the feed sends one, and only for an object its own verifier passed; the facade never does.

type DetailSubmitter

type DetailSubmitter interface {
	Submitter
	SubmitDetail(ctx context.Context, topic string, object []byte) (Answer, error)
}

DetailSubmitter is a Submitter that also reports the answer's wrapper form.

type Feed

type Feed struct {
	// Topics maps TopicID to the elected topic name. SetTopics replaces it
	// while the feed runs.
	Topics map[[32]byte]string

	// Submit is the engine client.
	Submit Submitter
	// Guard is the loop guard. The feed marks an object Delivered before
	// submitting it, so a client that hands the same bytes back to the facade
	// is recognised as a loop rather than published again.
	Guard *guard.Guard
	// MaxObject bounds object bytes. Zero takes the codec default (64 MiB).
	//
	// Keep this at or below the engine's own body limit. Above it, a delivered
	// object becomes a rejection from the engine and an engine error here,
	// which reads as our fault when it is a configuration mismatch.
	MaxObject int
	// Workers is the number of concurrent engine submits. Zero means Handle
	// submits synchronously, in the lane's read loop, which is the right shape
	// for a test and the wrong one for a deployment: the engine's submit can
	// take up to its timeout, and a stall there holds the lane's socket past
	// the edge's write deadline, so the edge drops and redials, the delivery
	// pool replays its last object, and an engine outage becomes a connection
	// storm. With workers, Handle returns as soon as the object is queued.
	Workers int
	// SubmitRetries is how many times a failed engine submit is retried
	// before the object is given up on. Zero takes a small default; a
	// negative value disables retry entirely.
	//
	// It exists because dropping on the first error LOSES DATA, measured: 55
	// and 56 objects on the two lab hosts in one afternoon, every one of them
	// during a window when the engine was restarting for a deploy. The object
	// has already crossed the fabric, been reassembled and been written to
	// this process; the engine being briefly unreachable is the most ordinary
	// failure there is, and it is recoverable by waiting.
	//
	// Retrying here is safe BECAUSE this runs on a worker, off the lane read
	// loop. The constraint that must not be broken is the one in main.go: an
	// engine stall may never hold the delivery socket past the edge's write
	// deadline. A worker blocking costs throughput and, if the queue fills,
	// sheds, which is counted and visible. It never applies backpressure to
	// the socket.
	SubmitRetries int
	// SubmitBackoff is the base delay between submit attempts; each attempt
	// waits one more multiple of it. Zero takes a default.
	SubmitBackoff time.Duration
	// QueueDepth bounds the queued objects behind the workers. Zero takes a
	// small default. When it is full a delivery is SHED: counted, logged, and
	// refused back to the lane, which counts it too and keeps the connection.
	// The host misses that object until its own catch-up finds it, which is a
	// real loss and is preferred to stalling every later delivery behind it.
	QueueDepth int
	// QueueBytes, when set, also bounds the queue by the bytes of the
	// objects in it: a delivery that would take the queue past it is shed.
	// Memory, not the count, is what a queue costs (a lab object is about
	// 1 KB, a BEEF can run to megabytes), so with QueueBytes the count
	// (QueueDepth) can be set deep enough to ride out a burst of small
	// objects while the bytes keep the memory bounded.
	QueueBytes int64
	Log        *slog.Logger

	// Verify is the bridge's own SPV verifier, used as VerifyMode says. Nil,
	// or VerifyMode off, leaves verification to the engine alone.
	Verify     Verifier
	VerifyMode VerifyMode
	// MarkerKey is the key the enforce-mode trust marker is computed under
	// (pkg/spv). Without one, enforce still drops refused objects but sends
	// passing ones unmarked, so the engine verifies them too.
	MarkerKey []byte
	// OnVerified is told of every verdict; OnSubmitted of every submit's
	// outcome and its time from lane arrival to the engine's answer. Both run
	// on a worker and must not block.
	OnVerified  func(spv.Verdict)
	OnSubmitted func(outcome string, d time.Duration)
	// OnDequeued is told, when a worker takes an object off the queue, how
	// long it waited there since it arrived on the lane. It runs on the
	// worker and must not block.
	OnDequeued func(wait time.Duration)

	// Shadow, when set, is offered every topic submit once the primary has
	// answered, with the primary's answer to compare against. It never
	// delays or fails the primary submit.
	Shadow *Shadow
	// Routes send the topics each pattern names to a primary and a shadow of
	// their own (first match wins); every other topic uses Submit and
	// Shadow. See Route.
	Routes []*Route

	// StopDrain bounds how long the workers keep submitting what is already
	// queued once Start's context is cancelled (0 = DefaultStopDrain).
	// Without a drain a restart dropped every queued object: the lane had
	// delivered them, so nothing upstream sends them again.
	StopDrain time.Duration
	// contains filtered or unexported fields
}

Feed is the lane handler. It holds the only map from topic identifier to elected name, computed from the election rather than fetched: the identifier is the hash of the name, so the map is derivable and there is nothing to look up.

func (*Feed) Backlog added in v0.7.0

func (f *Feed) Backlog() (queued, capacity int)

Backlog reports the deliveries queued behind the workers and the queue's capacity (-engine-queue). A full queue sheds.

func (*Feed) BacklogBytes added in v0.9.0

func (f *Feed) BacklogBytes() (queued, capacity int64)

BacklogBytes reports the bytes of the objects queued behind the workers and the queue's byte bound (-engine-queue-bytes; 0 for none).

func (*Feed) Busy added in v0.7.0

func (f *Feed) Busy() map[BusyKey]int64

Busy reports how many workers are in each stage right now, by route. A key absent from the map has none.

func (*Feed) Handle

func (f *Feed) Handle(ctx context.Context, record []byte) error

Handle consumes one whole delivery record. It satisfies lanes.Handler.

Returning lanes.ErrReject means the record was well-framed but refused on policy: the sender's problem, counted separately, connection kept. Any other error is ours or the engine's. Neither drops the connection.

func (*Feed) RouteNames added in v0.7.0

func (f *Feed) RouteNames() []string

RouteNames lists every route's metrics label: DefaultRoute, then each route's pattern in order.

func (*Feed) SetTopics added in v0.18.0

func (f *Feed) SetTopics(m map[[32]byte]string)

SetTopics replaces the name map while the feed runs, for a bridge whose topics change without a restart. A delivery named after it returns is named from m; one already named finishes as it was. The feed keeps m: the caller must not change it afterwards.

func (*Feed) Start

func (f *Feed) Start(ctx context.Context) error

Start runs the workers until ctx is cancelled, then drains: every object already queued is still submitted, on a context that outlives ctx by at most StopDrain, before Start returns. It must be called when Workers is set; Handle refuses deliveries until it has.

func (*Feed) Stats

func (f *Feed) Stats() Stats

Stats returns a counter snapshot.

func (*Feed) TopicMap added in v0.18.0

func (f *Feed) TopicMap() map[[32]byte]string

TopicMap is the name map in use: the last one SetTopics stored, else Topics. It must not be changed.

type MarkedSubmitter added in v0.4.0

type MarkedSubmitter interface {
	SubmitMarked(ctx context.Context, topic string, object []byte, marker string) (overlay.Steak, error)
}

MarkedSubmitter is a Submitter that can attach the SPV trust marker. The marker is a header value (see pkg/spv); the empty string sends none.

type Route added in v0.6.0

type Route struct {
	// Pattern is a path.Match glob over the topic name (`tm_bsecret_*`).
	// A topic name holds no slash, so `*` matches the whole remainder.
	Pattern string
	// Submit is the route's primary. For the facade it should also be a
	// DetailSubmitter, so the answer keeps the engine's wrapper form.
	Submit Submitter
	// Shadow, when set, is offered every submit the route's primary is
	// handed, exactly as the default shadow is. Nil = no shadow for these
	// topics.
	Shadow *Shadow
	// Also are the site's other local targets for these topics: each is
	// handed every object the primary is (see Also).
	Also []*Also
}

Route sends the topics a glob names to an engine of their own, with a shadow of their own, while every other topic keeps the bridge's default primary and shadow.

It exists for a per-topic cutover: one application's topics move to a new engine while the others stay on the old one, and the old engine shadows the new one for those topics (parity read in reverse) until the port is trusted. The route is the unit of rollback: swap its primary and shadow and the topics are back, with nothing else touched.

func RouteFor added in v0.6.0

func RouteFor(routes []*Route, topic string) *Route

RouteFor picks the first route whose pattern matches the topic, or nil for the default engines.

func (*Route) Matches added in v0.6.0

func (r *Route) Matches(topic string) bool

Matches reports whether the route carries the topic.

func (*Route) Name added in v0.6.0

func (r *Route) Name() string

Name labels the route in metrics and logs: its pattern.

func (*Route) OfferAlso added in v0.10.0

func (r *Route) OfferAlso(topic string, object []byte)

OfferAlso hands an object to each of the route's Also targets. A nil route does nothing.

type RouteSpec added in v0.10.0

type RouteSpec struct {
	Pattern, Primary, Shadow string
	// Also are the origins of the route's other local targets, in order.
	Also []string
}

RouteSpec is one parsed `-engine-route` value.

func ParseRouteSpec added in v0.10.0

func ParseRouteSpec(s string) (RouteSpec, error)

ParseRouteSpec parses one `-engine-route` value. A glob that path.Match rejects, a missing primary, a prefixed origin, a shadow equal to the primary, or an also target equal to the primary, the shadow or another also target is an error.

type Shadow added in v0.5.0

type Shadow struct {
	// Submit is the shadow engine's client. A MarkedSubmitter is handed the
	// marker the primary was handed.
	Submit Submitter
	// Workers drain the queue; zero takes a default of 2.
	Workers int
	// QueueDepth bounds offers waiting for a worker; zero takes a default
	// of 1024. A full queue drops.
	QueueDepth int
	// LogMismatches is how many mismatches are logged with their txid and
	// topic before logging stops; zero takes a default of 20. Counting
	// never stops.
	LogMismatches int
	Log           *slog.Logger
	// OnSubmitted is told each shadow submit's result (ok or error) and
	// its duration. It runs on a worker and must not block.
	OnSubmitted func(result string, d time.Duration)
	// Name labels this shadow in logs: the route it belongs to, or
	// DefaultRoute. Metrics carry it as the route label.
	Name string
	// contains filtered or unexported fields
}

Shadow is a second engine fed every object the primary is fed, so that two engines can be compared on real traffic before one replaces the other.

Each topic submit the feed makes to the primary is offered to the shadow once the primary has answered: the same body, the same topic, the same SPV trust marker. The shadow's answer for that topic is compared with the primary's and the comparison counted by kind. Nothing the shadow does reaches the primary path: the offer is a non-blocking put on a bounded queue, drained by the shadow's own workers, and a full queue drops the offer and counts the drop. A shadow that is down, slow or wrong costs the primary nothing but the counter.

Lookups are not teed. Whether the two engines answer questions alike is the application's own demo to run.

func (*Shadow) Backlog added in v0.7.0

func (s *Shadow) Backlog() (queued, capacity int)

Backlog reports the topic submits queued for the shadow and the queue's capacity (-shadow-queue). A full queue drops.

func (*Shadow) Offer added in v0.6.0

func (s *Shadow) Offer(topic string, object []byte, marker string, primary *overlay.AdmittanceInstructions)

Offer queues one topic submit for the shadow: the object, the topic, the SPV marker the primary was handed (empty for none) and the primary's answer for the topic (nil when it gave none). It never blocks, and a nil Shadow accepts the call and does nothing, so callers need no guard.

func (*Shadow) Start added in v0.5.0

func (s *Shadow) Start(ctx context.Context) error

Start runs the workers until ctx is cancelled. Offers made before it runs are dropped and counted, never queued for a drain that is not coming.

func (*Shadow) Stats added in v0.5.0

func (s *Shadow) Stats() ShadowStats

Stats returns a counter snapshot.

type ShadowStats added in v0.5.0

type ShadowStats struct {
	Kinds     map[string]uint64
	Submitted uint64
}

ShadowStats is a snapshot of the shadow's counters: Kinds by comparison kind, and Submitted, the submits that reached the shadow engine.

type Stats

type Stats struct {
	Submitted   uint64
	EngineError uint64
	// Retried counts objects that FAILED an engine submit at least once and
	// then succeeded. It is the difference between a transient engine restart
	// and data loss, and without it a recovered submit is indistinguishable
	// from one that never had trouble.
	Retried      uint64
	ParseError   uint64
	UnknownTopic uint64
	Rejected     uint64
	// Sunk counts deliveries terminated with no engine configured (sink mode).
	Sunk uint64
	// Shed counts deliveries refused because the engine queue was full. Each
	// is an object the host did NOT receive from the plane. Non-zero means the
	// engine cannot keep up with delivery and the host is relying on its own
	// catch-up to close the gap.
	Shed uint64
	// ShedByRoute splits Shed by the route of the topic the plane delivered
	// each object under (DefaultRoute or a route's pattern).
	ShedByRoute map[string]uint64
	// EngineRefused counts submits the engine answered 4xx: refused on the
	// object's merits, never retried.
	EngineRefused uint64
	// SPVRefused counts objects the bridge's own verifier refused in
	// enforce mode. Each was NOT submitted.
	SPVRefused uint64
	// VerifyScripts counts input scripts the bridge's verifier ran.
	VerifyScripts uint64
	// Mismatch counts shadow-mode disagreements with the engine, by kind.
	Mismatch map[string]uint64
	Steak    map[SteakKey]uint64
}

Stats is a point-in-time snapshot of the feed's counters.

These count what came off the plane. They are NOT a count of what the host holds: an engine can acquire objects through its own catch-up protocol that never traverse this feed. Do not write an acceptance check that reads engine state from these numbers; the oracle for what a host holds is its own lookup service.

type StatusError added in v0.4.0

type StatusError struct {
	Code int
	Body string
}

StatusError is an engine that ANSWERED with a status other than 200. A 4xx is the engine refusing the object on its merits (a malformed or invalid BEEF); a 5xx is the engine failing.

func (*StatusError) Error added in v0.4.0

func (e *StatusError) Error() string

type SteakKey

type SteakKey struct{ Topic, Outcome string }

SteakKey buckets an engine answer by topic and outcome.

type Submitter

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

Submitter posts one BEEF object to one topic on a BRC-22 engine.

type Verifier added in v0.4.0

type Verifier interface {
	Verify(ctx context.Context, beef []byte) spv.Verdict
}

Verifier verifies one BEEF object. *spv.Verifier is one.

type VerifyMode added in v0.4.0

type VerifyMode string

VerifyMode is how the feed uses its own SPV verifier.

const (
	VerifyOff     VerifyMode = "off"
	VerifyShadow  VerifyMode = "shadow"
	VerifyEnforce VerifyMode = "enforce"
)

The modes.

  • off: no verification here; the engine verifies, as before.
  • shadow: every object is verified here AND submitted exactly as before, with no marker, so the engine verifies it too. When the engine answers, the two verdicts are compared and a disagreement is counted. Nothing is dropped and nothing is trusted: shadow can only add information.
  • enforce: an object this verifier REFUSES is not submitted (counted and logged with its txid). One that passes is submitted with the trust marker, which an engine configured for it honours by skipping its own script verification. One that could not be verified (ResultError) is submitted with NO marker, so the engine verifies it in full: a tracker outage never drops an object and never grants trust.

func ParseVerifyMode added in v0.4.0

func ParseVerifyMode(s string) (VerifyMode, error)

ParseVerifyMode reads a mode name; empty is off.

Jump to

Keyboard shortcuts

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