headnotify

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

Documentation

Overview

Package headnotify implements Lantern's chain-head change distributor.

It's the bridge between a Store's OnHeadChange callback (which fires on every new head) and the per-WebSocket subscriber channels that Filecoin.ChainNotify hands out.

Semantics match Lotus:

  • When a subscriber connects, the first message is always {Type:"current", Val: <current head>}.
  • For every subsequent canonical head, fan out {Type:"apply", Val: <new tipset>}. On reorg, fan out a sequence of {Type:"revert"} events for the orphaned tipsets followed by {Type:"apply"} events for the new chain.
  • Per-subscriber buffer is bounded (default 64 events). When a subscriber's channel is full we drop the oldest events (matching Lotus' slow-subscriber behaviour) and emit a log warning.

Written for Lantern. Not a direct lift of Lotus' notifee plumbing, but the head-change event shape (HeadChange{Type,Val}) is the same wire format Curio expects.

Index

Constants

View Source
const DefaultBufferSize = 64

DefaultBufferSize is the per-subscriber bounded buffer depth.

Lotus' default is similar; we pick 64 to absorb ~30s of mainnet epochs without dropping under normal load.

Variables

This section is empty.

Functions

This section is empty.

Types

type Distributor

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

Distributor fans out head-change events from a header store to many subscribers (one per active WebSocket ChainNotify session).

func New

func New(store *hstore.Store, bufferSize int) *Distributor

New returns a Distributor backed by the given header store. The distributor does NOT start listening on the store until Start() is called.

func (*Distributor) CurrentHead

func (d *Distributor) CurrentHead() *ltypes.TipSet

CurrentHead returns the most recent head the distributor has observed, or nil if no head has been published yet.

func (*Distributor) PublishCustom

func (d *Distributor) PublishCustom(events []api.HeadChange)

PublishCustom lets the daemon push an arbitrary head-change sequence (e.g. a synthetic "current" reset). Used during startup if the daemon wants to advertise the trusted-root head before the header store has caught up.

func (*Distributor) Start

func (d *Distributor) Start()

Start hooks the distributor into the header store. Idempotent.

func (*Distributor) Subscribe

func (d *Distributor) Subscribe(ctx context.Context) <-chan []api.HeadChange

Subscribe returns a new channel that receives head-change events. The first event is always {Type:"current"} with the current head (or empty if no head is available yet). Cancelling ctx unsubscribes.

The returned channel is closed by the distributor when ctx is done.

func (*Distributor) SubscriberCount

func (d *Distributor) SubscriberCount() int

SubscriberCount returns the number of active subscribers.

Jump to

Keyboard shortcuts

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