headtracker

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const HeadsBufferSize = 10

HeadsBufferSize - The buffer is used when heads sampling is disabled, to ensure the callback is run for every head

Variables

This section is empty.

Functions

func NewHeadBroadcaster

func NewHeadBroadcaster(logger logger.Logger) httypes.HeadBroadcaster

NewHeadBroadcaster creates a new HeadBroadcaster

Types

type Config

type Config interface {
	BlockEmissionIdleWarningThreshold() time.Duration
	EvmFinalityDepth() uint32
	EvmHeadTrackerHistoryDepth() uint32
	EvmHeadTrackerMaxBufferSize() uint32
	EvmHeadTrackerSamplingInterval() time.Duration
}

type HeadListener

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

func NewHeadListener

func NewHeadListener(l logger.Logger,
	ethClient eth.Client,
	config Config,
	chStop chan struct{},
	sleepers ...utils.Sleeper,
) *HeadListener

func (*HeadListener) Connected

func (hl *HeadListener) Connected() bool

Connected returns whether or not this HeadTracker is connected.

func (*HeadListener) ListenForNewHeads

func (hl *HeadListener) ListenForNewHeads(handleNewHead func(ctx context.Context, header *eth.Head) error, done func())

type HeadSaver

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

func NewHeadSaver

func NewHeadSaver(lggr logger.Logger, orm *ORM, config Config) *HeadSaver

func (*HeadSaver) Chain

func (ht *HeadSaver) Chain(hash common.Hash) *eth.Head

func (*HeadSaver) LatestChain added in v1.1.0

func (ht *HeadSaver) LatestChain() *eth.Head

LatestChain returns the block header with the highest number that has been seen, or nil

func (*HeadSaver) LoadFromDB added in v1.1.0

func (ht *HeadSaver) LoadFromDB(ctx context.Context) (chain *eth.Head, err error)

func (*HeadSaver) Save

func (ht *HeadSaver) Save(ctx context.Context, h *eth.Head) error

Save updates the latest block number, if indeed the latest, and persists this number in case of reboot. Thread safe.

type HeadTracker

type HeadTracker struct {
	utils.StartStopOnce
	// contains filtered or unexported fields
}

HeadTracker holds and stores the latest block number experienced by this particular node in a thread safe manner. Reconstitutes the last block number from the data store on reboot.

func NewHeadTracker

func NewHeadTracker(
	l logger.Logger,
	ethClient eth.Client,
	config Config,
	orm *ORM,
	headBroadcaster httypes.HeadBroadcaster,
	sleepers ...utils.Sleeper,
) *HeadTracker

NewHeadTracker instantiates a new HeadTracker using the orm to persist new block numbers. Can be passed in an optional sleeper object that will dictate how often it tries to reconnect.

func (*HeadTracker) Backfill

func (ht *HeadTracker) Backfill(ctx context.Context, headWithChain *eth.Head, depth uint) (err error)

Backfill given a head will fill in any missing heads up to the given depth

func (*HeadTracker) Connected

func (ht *HeadTracker) Connected() bool

Connected returns whether or not this HeadTracker is connected.

func (*HeadTracker) Healthy added in v0.10.11

func (ht *HeadTracker) Healthy() error

func (*HeadTracker) HighestSeenHeadFromDB

func (ht *HeadTracker) HighestSeenHeadFromDB(ctx context.Context) (*eth.Head, error)

func (*HeadTracker) LatestChain added in v1.1.0

func (ht *HeadTracker) LatestChain() *eth.Head

func (*HeadTracker) Save

func (ht *HeadTracker) Save(ctx context.Context, h *eth.Head) error

func (*HeadTracker) SetLogLevel added in v1.1.0

func (ht *HeadTracker) SetLogLevel(lvl zapcore.Level)

func (*HeadTracker) Start

func (ht *HeadTracker) Start() error

Start retrieves the last persisted block number from the HeadTracker, subscribes to new heads, and if successful fires Connect on the HeadTrackable argument.

func (*HeadTracker) Stop

func (ht *HeadTracker) Stop() error

Stop unsubscribes all connections and fires Disconnect.

type NullBroadcaster

type NullBroadcaster struct{}

func (*NullBroadcaster) Close

func (*NullBroadcaster) Close() error

func (*NullBroadcaster) Healthy

func (n *NullBroadcaster) Healthy() error

func (*NullBroadcaster) OnNewLongestChain

func (*NullBroadcaster) OnNewLongestChain(ctx context.Context, head *eth.Head)

func (*NullBroadcaster) Ready

func (n *NullBroadcaster) Ready() error

func (*NullBroadcaster) Start

func (*NullBroadcaster) Start() error

func (*NullBroadcaster) Subscribe

func (*NullBroadcaster) Subscribe(callback httypes.HeadTrackable) (currentLongestChain *eth.Head, unsubscribe func())

type NullTracker

type NullTracker struct{}

func (*NullTracker) Healthy added in v0.10.11

func (*NullTracker) Healthy() error

func (*NullTracker) HighestSeenHeadFromDB

func (n *NullTracker) HighestSeenHeadFromDB(context.Context) (*eth.Head, error)

func (*NullTracker) Ready added in v0.10.11

func (*NullTracker) Ready() error

func (*NullTracker) SetLogLevel added in v1.1.0

func (*NullTracker) SetLogLevel(zapcore.Level)

func (*NullTracker) Start

func (*NullTracker) Start() error

func (*NullTracker) Stop

func (*NullTracker) Stop() error

type ORM added in v0.10.10

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

func NewORM added in v0.10.10

func NewORM(db *sqlx.DB, lggr logger.Logger, cfg pg.LogConfig, chainID big.Int) *ORM

func (*ORM) HeadByHash added in v0.10.10

func (orm *ORM) HeadByHash(ctx context.Context, hash common.Hash) (head *eth.Head, err error)

HeadByHash fetches the head with the given hash from the db, returns nil if none exists

func (*ORM) IdempotentInsertHead added in v0.10.10

func (orm *ORM) IdempotentInsertHead(ctx context.Context, h *eth.Head) error

IdempotentInsertHead inserts a head only if the hash is new. Will do nothing if hash exists already. No advisory lock required because this is thread safe.

func (*ORM) LatestHead added in v1.1.0

func (orm *ORM) LatestHead(ctx context.Context) (head *eth.Head, err error)

LatestHead returns the highest seen head

func (*ORM) LatestHeads added in v1.1.0

func (orm *ORM) LatestHeads(ctx context.Context, limit int) (heads []*eth.Head, err error)

LatestHeads returns the latest heads up to given limit

func (*ORM) TrimOldHeads added in v0.10.10

func (orm *ORM) TrimOldHeads(ctx context.Context, n uint) (err error)

TrimOldHeads deletes heads such that only the top N block numbers remain

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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