headtracker

package
v0.10.16-rc1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHeadBroadcaster

func NewHeadBroadcaster() httypes.HeadBroadcaster

NewHeadBroadcaster creates a new HeadBroadcaster

Types

type Config

type Config interface {
	ChainID() *big.Int
	EnableLegacyJobPipeline() bool
	EthHeadTrackerHistoryDepth() uint
	EthHeadTrackerMaxBufferSize() uint
	EthHeadTrackerSamplingInterval() time.Duration
	BlockEmissionIdleWarningThreshold() time.Duration
	EthereumURL() string
	EthFinalityDepth() uint
}

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{},
	wgDone *sync.WaitGroup,
	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 models.Head) error, connected func())

func (*HeadListener) SetLogger

func (hl *HeadListener) SetLogger(logger *logger.Logger)

SetLogger sets and reconfigures the log for the head tracker service

type HeadSaver

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

TODO: Needs to be optimised to allow for in-memory reads and not hit the DB every time See: https://app.clubhouse.io/chainlinklabs/story/13314/optimise-headsaver-to-not-hit-the-db-so-much

func NewHeadSaver

func NewHeadSaver(orm *ORM, config Config) *HeadSaver

func (*HeadSaver) Chain

func (ht *HeadSaver) Chain(ctx context.Context, hash common.Hash, depth uint) (models.Head, error)

func (*HeadSaver) HeadByHash added in v0.10.10

func (ht *HeadSaver) HeadByHash(ctx context.Context, hash common.Hash) (*models.Head, error)

func (*HeadSaver) HighestSeenHead

func (ht *HeadSaver) HighestSeenHead() *models.Head

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

func (*HeadSaver) HighestSeenHeadFromDB

func (ht *HeadSaver) HighestSeenHeadFromDB() (*models.Head, error)

func (*HeadSaver) IdempotentInsertHead

func (ht *HeadSaver) IdempotentInsertHead(ctx context.Context, head models.Head) error

func (*HeadSaver) Save

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

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

func (*HeadSaver) SetHighestSeenHeadFromDB

func (ht *HeadSaver) SetHighestSeenHeadFromDB() (*models.Head, error)

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 models.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) HighestSeenHead

func (ht *HeadTracker) HighestSeenHead() *models.Head

func (*HeadTracker) HighestSeenHeadFromDB

func (ht *HeadTracker) HighestSeenHeadFromDB() (*models.Head, error)

func (*HeadTracker) Save

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

func (*HeadTracker) SetLogger

func (ht *HeadTracker) SetLogger(logger *logger.Logger)

SetLogger sets and reconfigures the log for the head tracker service

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) Connect

func (*NullBroadcaster) Connect(head *models.Head) error

func (*NullBroadcaster) Healthy

func (n *NullBroadcaster) Healthy() error

func (*NullBroadcaster) OnNewLongestChain

func (*NullBroadcaster) OnNewLongestChain(ctx context.Context, head models.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 *models.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() (*models.Head, error)

func (*NullTracker) Ready added in v0.10.11

func (*NullTracker) Ready() error

func (*NullTracker) SetLogger

func (*NullTracker) SetLogger(*logger.Logger)

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 *gorm.DB) *ORM

func (*ORM) Chain added in v0.10.10

func (orm *ORM) Chain(ctx context.Context, hash common.Hash, lookback uint) (models.Head, error)

Chain return the chain of heads starting at hash and up to lookback parents Returns RecordNotFound if no head with the given hash exists

func (*ORM) HeadByHash added in v0.10.10

func (orm *ORM) HeadByHash(ctx context.Context, hash common.Hash) (*models.Head, 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 models.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) LastHead added in v0.10.10

func (orm *ORM) LastHead(ctx context.Context) (*models.Head, error)

LastHead returns the head with the highest number. In the case of ties (e.g. due to re-org) it returns the most recently seen head entry.

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
internal

Jump to

Keyboard shortcuts

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