events

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 21 Imported by: 4 modules, 3 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

Index

Constants

View Source
const (
	// DefaultWatchdogTimeout is how long the service waits for a new block before it
	// treats the block subscription as dead, re-subscribes and fetches the missed
	// blocks itself.
	DefaultWatchdogTimeout = 8 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option added in v0.4.6

type Option func(*options) error

Option configures the events service. It follows the functional options pattern, so settings can be added without breaking NewEvents callers. An option that returns an error makes NewEvents fail with that error.

func WithLogger added in v0.4.6

func WithLogger(l log.Logger) Option

WithLogger sets the logger the service reports to, including every loss and re-establishment of the block subscription. It must not be nil. By default the service uses the logger carried by the context passed to NewEvents (see util/ctxlog), which discards everything when the context carries none.

func WithStartHeight added in v0.4.6

func WithStartHeight(h int64) Option

WithStartHeight makes the service publish events from block h+1 on, where h is the last block the caller has already accounted for, for example the height its bootstrap queries were pinned to. Without it the service starts from the node's latest height when NewEvents runs, and anything the caller has not seen at or below that height is neither queried nor published. h must not be negative. A height the node no longer retains parks the service until a node that retains it answers.

func WithWatchdogTimeout added in v0.4.6

func WithWatchdogTimeout(d time.Duration) Option

WithWatchdogTimeout sets how long the service waits for a new block before it treats the block subscription as dead, re-subscribes and fetches the missed blocks itself. It must be positive. The default is DefaultWatchdogTimeout.

type Service

type Service interface {
	// Shutdown gracefully stops the event monitoring service and waits for it to finish.
	Shutdown()
}

Service represents an event monitoring service that watches the chain and publishes the transaction events it recognises to a message bus.

func NewEvents

func NewEvents(pctx context.Context, node sdkclient.CometRPC, name string, bus pubsub.Bus, opts ...Option) (Service, error)

NewEvents creates and starts a blockchain event monitoring service.

It subscribes to block headers and processes each block in order, publishing the events it recognises exactly once: none is skipped and none is published twice. It tracks the last processed height, so a gap between headers (for example after a dropped and re-established subscription) is back-filled rather than lost.

A watchdog resets on every block and fires if none arrives within the timeout (WithWatchdogTimeout, DefaultWatchdogTimeout by default). The subscription channel is never closed when the connection under it dies, so the watchdog is what notices: it fetches the missed blocks to keep events flowing and re-subscribes. The re-subscribe matters because the CometBFT websocket client redials only after a websocket close or a failed write. After a reset or a keepalive timeout it goes silent for good until something writes to it again. Every loss of the subscription is logged at warn level and every attempt to re-establish it at info level (see WithLogger).

A height that cannot be fetched or decoded parks the cursor and is retried indefinitely, once per minRetryInterval on its own timer, so a transient failure (a pooled backend that does not have the height yet, a rate-limited request) costs one retry interval rather than waiting for the next header or watchdog tick. The cursor never moves past it, even once the node has pruned it, because a skipped height is a lost event: a missed EventLeaseClosed leaves a provider running a closed lease. A parked cursor holds back every later event until the height is served.

It starts from the node's latest height, so historical events are not replayed, unless WithStartHeight says where the caller left off.

Jump to

Keyboard shortcuts

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