Documentation
¶
Index ¶
Constants ¶
const HeadsBufferSize = 10
HeadsBufferSize - The buffer is used when heads sampling is disabled, to ensure the callback is run for every head
const TrackableCallbackTimeout = 2 * time.Second
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broadcaster ¶
type Broadcaster[H chains.Head[BLOCK_HASH], BLOCK_HASH chains.Hashable] interface { services.Service BroadcastNewLongestChain(H) Subscribe(callback Trackable[H, BLOCK_HASH]) (currentLongestChain H, unsubscribe func()) }
Broadcaster relays new Heads to all subscribers.
func NewBroadcaster ¶
func NewBroadcaster[ H chains.Head[BLOCK_HASH], BLOCK_HASH chains.Hashable, ]( lggr logger.Logger, ) Broadcaster[H, BLOCK_HASH]
NewBroadcaster creates a new Broadcaster
type ChainConfig ¶
type Client ¶
type Client[H chains.Head[BLOCK_HASH], S chains.Subscription, ID chains.ID, BLOCK_HASH chains.Hashable] interface { HeadByNumber(ctx context.Context, number *big.Int) (head H, err error) HeadByHash(ctx context.Context, hash BLOCK_HASH) (head H, err error) // ConfiguredChainID returns the chain ID that the node is configured to connect to ConfiguredChainID() (id ID) // SubscribeToHeads is the method in which the client receives new Head. // It can be implemented differently for each chain i.e websocket, polling, etc SubscribeToHeads(ctx context.Context) (<-chan H, S, error) // LatestSafeBlock - returns the latest block that was marked as safe LatestSafeBlock(ctx context.Context) (safe H, err error) // LatestFinalizedBlock - returns the latest block that was marked as finalized LatestFinalizedBlock(ctx context.Context) (head H, err error) }
type FinalizedMissingError ¶
func (FinalizedMissingError[BLOCK_HASH]) Error ¶
func (e FinalizedMissingError[BLOCK_HASH]) Error() string
type Handler ¶
type Handler[H chains.Head[BLOCK_HASH], BLOCK_HASH chains.Hashable] func(ctx context.Context, header H) error
Handler is a callback that handles incoming heads
type Listener ¶
type Listener[H chains.Head[BLOCK_HASH], BLOCK_HASH chains.Hashable] interface { services.Service // ListenForNewHeads runs the listen loop (not thread safe) ListenForNewHeads(ctx context.Context) // ReceivingHeads returns true if the listener is receiving heads (thread safe) ReceivingHeads() bool // Connected returns true if the listener is connected (thread safe) Connected() bool // HealthReport returns report of errors within Listener HealthReport() map[string]error }
Listener is a chain agnostic interface that manages connection of Client that receives heads from the blockchain node
func NewListener ¶
func NewListener[ HTH Head[BLOCK_HASH, ID], S chains.Subscription, ID chains.ID, BLOCK_HASH chains.Hashable, CLIENT Client[HTH, S, ID, BLOCK_HASH], ]( lggr logger.Logger, client CLIENT, config ListenerConfig, onSubscription func(context.Context), handleNewHead Handler[HTH, BLOCK_HASH], ) Listener[HTH, BLOCK_HASH]
type ListenerConfig ¶
type Saver ¶
type Saver[H chains.Head[BLOCK_HASH], BLOCK_HASH chains.Hashable] interface { // Save updates the latest block number, if indeed the latest, and persists // this number in case of reboot. Save(ctx context.Context, head H) error // Load loads latest heads up to latestFinalized - historyDepth, returns the latest chain. Load(ctx context.Context, latestFinalized int64) (H, error) // LatestChain returns the block header with the highest number that has been seen, or nil. LatestChain() H // Chain returns a head for the specified hash, or nil. Chain(hash BLOCK_HASH) H // MarkFinalized - marks matching block and all it's direct ancestors as finalized MarkFinalized(ctx context.Context, latestFinalized H) error }
Saver is a chain agnostic interface for saving and loading heads Different chains will instantiate generic Saver type with their native Head and BlockHash types.
type Trackable ¶
type Trackable[H chains.Head[BLOCK_HASH], BLOCK_HASH chains.Hashable] interface { // OnNewLongestChain sends a new head when it becomes available. Subscribers can recursively trace the parent // of the head to the finalized block back. OnNewLongestChain(ctx context.Context, head H) }
Trackable is implemented by the core txm to be able to receive head events from any chain. Chain implementations should notify head events to the core txm via this interface.
type Tracker ¶
type Tracker[H chains.Head[BLOCK_HASH], BLOCK_HASH chains.Hashable] interface { services.Service // Backfill given a head will fill in any missing heads up to latestFinalized Backfill(ctx context.Context, headWithChain H, prevHeadWithChain H) (err error) LatestChain() H // LatestSafeBlock returns the latest block that is considered safe to use. LatestSafeBlock(ctx context.Context) (safe H, err error) // LatestAndFinalizedBlock - returns latest and latest finalized blocks. // NOTE: Returns latest finalized block as is, ignoring the FinalityTagBypass feature flag. LatestAndFinalizedBlock(ctx context.Context) (latest, finalized H, err error) }
Tracker holds and stores the block experienced by a particular node in a thread safe manner.
func NewTracker ¶
func NewTracker[HTH Head[BHASH, ID], S chains.Subscription, ID chains.ID, BHASH chains.Hashable]( lggr logger.Logger, client Client[HTH, S, ID, BHASH], config ChainConfig, htConfig TrackerConfig, headBroadcaster Broadcaster[HTH, BHASH], headSaver Saver[HTH, BHASH], mailMon *mailbox.Monitor, getNilHead func() HTH, ) Tracker[HTH, BHASH]
NewTracker instantiates a new Tracker using Saver to persist new block numbers.