beacon

package
v0.35.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: GPL-3.0 Imports: 26 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDepositCountsFromBeaconBlock

func GetDepositCountsFromBeaconBlock(block *spec.VersionedSignedBeaconBlock) int

GetDepositCountsFromBeaconBlock returns the number of deposits in a beacon block

func GetTransactionsCountFromBeaconBlock

func GetTransactionsCountFromBeaconBlock(block *spec.VersionedSignedBeaconBlock) int

GetTransactionsCountFromBeaconBlock returns the number of transactions in a beacon block

func GetVoluntaryExitsFromBeaconBlock

func GetVoluntaryExitsFromBeaconBlock(block *spec.VersionedSignedBeaconBlock) int

GetVoluntaryExitsFromBeaconBlock returns the number of voluntary exits in a beacon block

Types

type BeaconMetrics

type BeaconMetrics struct {
	Slot                prometheus.GaugeVec
	Transactions        prometheus.GaugeVec
	Slashings           prometheus.GaugeVec
	Attestations        prometheus.GaugeVec
	Deposits            prometheus.GaugeVec
	VoluntaryExits      prometheus.GaugeVec
	FinalityCheckpoints prometheus.GaugeVec
	ReOrgs              prometheus.Counter
	ReOrgDepth          prometheus.Counter
	EmptySlots          prometheus.Counter
	ProposerDelay       prometheus.Histogram
	Withdrawals         prometheus.GaugeVec
	WithdrawalsAmount   prometheus.GaugeVec
	WithdrawalsIndexMax prometheus.GaugeVec
	WithdrawalsIndexMin prometheus.GaugeVec
	BlobKZGCommitments  prometheus.GaugeVec
	// contains filtered or unexported fields
}

Beacon reports Beacon information about the beacon chain.

func NewBeaconMetrics

func NewBeaconMetrics(beac Node, log logrus.FieldLogger, namespace string, constLabels map[string]string) *BeaconMetrics

NewBeaconMetrics creates a new BeaconMetrics instance.

func (*BeaconMetrics) GetSignedBeaconBlock

func (b *BeaconMetrics) GetSignedBeaconBlock(ctx context.Context, blockID string) error

func (*BeaconMetrics) Name

func (b *BeaconMetrics) Name() string

Name returns the name of the job.

func (*BeaconMetrics) Start

func (b *BeaconMetrics) Start(ctx context.Context) error

Start starts the job.

func (*BeaconMetrics) Stop

func (b *BeaconMetrics) Stop() error

Stop stops the job.

type BeaconSubscriptionOptions

type BeaconSubscriptionOptions struct {
	Enabled bool
	Topics  EventTopics
}

BeaconSubscriptionOptions holds the options for beacon subscription.

func DefaultDisabledBeaconSubscriptionOptions

func DefaultDisabledBeaconSubscriptionOptions() BeaconSubscriptionOptions

DefaultDisabledBeaconSubscriptionOptions returns the default options for a disabled beacon subscription.

func DefaultEnabledBeaconSubscriptionOptions

func DefaultEnabledBeaconSubscriptionOptions() BeaconSubscriptionOptions

DefaultEnabledBeaconSubscriptionOptions returns the default options for an enabled beacon subscription.

func (*BeaconSubscriptionOptions) Disable

Disable disables the beacon subscription.

func (*BeaconSubscriptionOptions) Enable

Enable enables the beacon subscription.

type Config

type Config struct {
	// Name is the human-readable name of the node.
	Name string `yaml:"name"`
	// Address is the address of the node.
	Addr string `yaml:"addr"`
	// Headers are the headers to send with every request.
	Headers map[string]string `yaml:"headers"`
}

Config is the configuration for a beacon node.

type EmptySlotEvent

type EmptySlotEvent struct {
	Slot phase0.Slot
}

EmptySlotEvent is emitted when an empty slot is detected.

type EventMetrics

type EventMetrics struct {
	Count              prometheus.CounterVec
	TimeSinceLastEvent prometheus.Gauge

	LastEventTime time.Time
	// contains filtered or unexported fields
}

EventMetrics reports event counts.

func NewEventJob

func NewEventJob(bc Node, log logrus.FieldLogger, namespace string, constLabels map[string]string) *EventMetrics

NewEvent creates a new Event instance.

func (*EventMetrics) HandleEvent

func (e *EventMetrics) HandleEvent(ctx context.Context, event *v1.Event) error

HandleEvent handles all beacon events

func (*EventMetrics) Name

func (e *EventMetrics) Name() string

Name returns the name of the job.

func (*EventMetrics) Start

func (e *EventMetrics) Start(ctx context.Context) error

Start starts the job.

func (*EventMetrics) Stop

func (e *EventMetrics) Stop() error

Stop stops the job.

type EventTopics

type EventTopics []string

EventTopics is a list of topics that can be subscribed to

func (EventTopics) Exists

func (e EventTopics) Exists(topic string) bool

Exists returns true if the topic exists in the list

type FinalityCheckpointUpdated

type FinalityCheckpointUpdated struct {
	Finality *v1.Finality
}

FinalityCheckpointUpdated is emitted when the finality checkpoint is updated.

type ForkMetrics

type ForkMetrics struct {
	Epochs    prometheus.GaugeVec
	Activated prometheus.GaugeVec
	Current   prometheus.GaugeVec
	// contains filtered or unexported fields
}

ForkMetrics reports the state of any forks (previous, active or upcoming).

func NewForksJob

func NewForksJob(beac Node, log logrus.FieldLogger, namespace string, constLabels map[string]string) *ForkMetrics

NewForksJob returns a new Forks instance.

func (*ForkMetrics) Name

func (f *ForkMetrics) Name() string

Name returns the name of the job.

func (*ForkMetrics) Start

func (f *ForkMetrics) Start(ctx context.Context) error

Start starts the job.

func (*ForkMetrics) Stop

func (f *ForkMetrics) Stop() error

Stop stops the job.

type GeneralMetrics

type GeneralMetrics struct {
	NodeVersion prometheus.GaugeVec
	ClientName  prometheus.GaugeVec
	Peers       prometheus.GaugeVec
	// contains filtered or unexported fields
}

GeneralMetrics reports general information about the node.

func NewGeneralJob

func NewGeneralJob(beac Node, log logrus.FieldLogger, namespace string, constLabels map[string]string) *GeneralMetrics

NewGeneral creates a new General instance.

func (*GeneralMetrics) Name

func (g *GeneralMetrics) Name() string

Name returns the name of the job.

func (*GeneralMetrics) Start

func (g *GeneralMetrics) Start(ctx context.Context) error

Start starts the job.

func (*GeneralMetrics) Stop

func (g *GeneralMetrics) Stop() error

Stop stops the job.

type Health

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

Health tracks the health status of the beacon node.

func NewHealth

func NewHealth(successThreshold, failThreshold int) *Health

NewHealth creates a new health tracker.

func (Health) FailedTotal

func (n Health) FailedTotal() uint64

FailedTotal returns the total number of failures.

func (Health) Healthy

func (n Health) Healthy() bool

Healthy returns true if the node is healthy.

func (*Health) RecordFail

func (n *Health) RecordFail(err error)

RecordFail records a failure.

func (*Health) RecordSuccess

func (n *Health) RecordSuccess()

RecordSuccess records a success.

func (Health) SuccessTotal

func (n Health) SuccessTotal() uint64

SuccessTotal returns the total number of successes.

type HealthCheckFailedEvent

type HealthCheckFailedEvent struct {
	Duration time.Duration
}

HealthCheckFailedEvent is emitted when a health check fails.

type HealthCheckOptions

type HealthCheckOptions struct {
	// Interval is the interval at which the health check will be run.
	Interval human.Duration
	// SuccessThreshold is the number of consecutive successful health checks required before the node is considered healthy.
	SuccessfulResponses int
	// FailureThreshold is the number of consecutive failed health checks required before the node is considered unhealthy.
	FailedResponses int
}

HealthCheckOptions holds the options for the health check.

func DefaultHealthCheckOptions

func DefaultHealthCheckOptions() HealthCheckOptions

DefaultHealthCheckOptions returns the default health check options.

type HealthCheckSucceededEvent

type HealthCheckSucceededEvent struct {
	Duration time.Duration
}

HealthCheckSucceededEvent is emitted when a health check succeeds.

type HealthMetrics

type HealthMetrics struct {
	CheckResultsTotal *prometheus.CounterVec
	Up                prometheus.Gauge
	// contains filtered or unexported fields
}

HealthMetrics reports metrics on the health status of the node.

func NewHealthMetrics

func NewHealthMetrics(beac Node, log logrus.FieldLogger, namespace string, constLabels map[string]string) *HealthMetrics

NewHealthMetrics returns a new HealthMetrics instance.

func (*HealthMetrics) Name

func (h *HealthMetrics) Name() string

Name returns the name of the job.

func (*HealthMetrics) Start

func (h *HealthMetrics) Start(ctx context.Context) error

Start starts the job.

func (*HealthMetrics) Stop

func (h *HealthMetrics) Stop() error

Stop stops the job.

type Metrics

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

Metrics contains all the metrics jobs.

func NewMetrics

func NewMetrics(log logrus.FieldLogger, namespace, nodeName string, beacon Node) *Metrics

NewMetrics returns a new Metrics instance.

func (*Metrics) Beacon

func (m *Metrics) Beacon() *BeaconMetrics

Beacon returns the beacon metrics job.

func (*Metrics) Events

func (m *Metrics) Events() *EventMetrics

Events returns the events metrics job.

func (*Metrics) Forks

func (m *Metrics) Forks() *ForkMetrics

Forks returns the forks metrics job.

func (*Metrics) General

func (m *Metrics) General() *GeneralMetrics

General returns the general metrics job.

func (*Metrics) Health

func (m *Metrics) Health() *HealthMetrics

Health returns the health metrics job.

func (*Metrics) Spec

func (m *Metrics) Spec() *SpecMetrics

Spec returns the spec metrics job.

func (*Metrics) Start

func (m *Metrics) Start(ctx context.Context) error

Start starts all the jobs.

func (*Metrics) Stop

func (m *Metrics) Stop() error

Stop stops all the metrics jobs.

func (*Metrics) Sync

func (m *Metrics) Sync() *SyncMetrics

Sync returns the sync metrics job.

type MetricsJob

type MetricsJob interface {
	Start(ctx context.Context) error
	Stop() error
	Name() string
}

MetricsJob is a job that reports metrics.

type Node

type Node interface {
	// Lifecycle
	// Start starts the node.
	Start(ctx context.Context) error
	// StartAsync starts the node asynchronously.
	StartAsync(ctx context.Context)
	// Stop stops the node.
	Stop(ctx context.Context) error

	// Getters
	// Options returns the options for the node.
	Options() *Options

	// Wallclock returns the EthWallclock instance
	Wallclock() *ethwallclock.EthereumBeaconChain

	// Eth getters. These are all cached.
	// Spec returns the spec for the node.
	Spec() (*state.Spec, error)
	// SyncState returns the sync state for the node.
	SyncState() (*v1.SyncState, error)
	// Genesis returns the genesis for the node.
	Genesis() (*v1.Genesis, error)
	// NodeVersion returns the node version.
	NodeVersion() (string, error)
	// Status returns the status of the ndoe.
	Status() *Status
	// Finality returns the finality checkpoint for the node.
	Finality() (*v1.Finality, error)
	// Healthy returns true if the node is healthy.
	Healthy() bool

	// Fetchers - these are not cached and will always fetch from the node.
	// FetchBlock fetches the block for the given state id.
	FetchBlock(ctx context.Context, stateID string) (*spec.VersionedSignedBeaconBlock, error)
	// FetchRawBlock fetches the raw, unparsed block for the given state id.
	FetchRawBlock(ctx context.Context, stateID string, contentType string) ([]byte, error)
	// FetchBeaconState fetches the beacon state for the given state id.
	FetchBeaconState(ctx context.Context, stateID string) (*spec.VersionedBeaconState, error)
	// FetchBeaconStateRoot fetches the state root for the given state id.
	FetchBeaconStateRoot(ctx context.Context, stateID string) (phase0.Root, error)
	// FetchRawBeaconState fetches the raw, unparsed beacon state for the given state id.
	FetchRawBeaconState(ctx context.Context, stateID string, contentType string) ([]byte, error)
	// FetchFinality fetches the finality checkpoint for the state id.
	FetchFinality(ctx context.Context, stateID string) (*v1.Finality, error)
	// FetchGenesis fetches the genesis configuration.
	FetchGenesis(ctx context.Context) (*v1.Genesis, error)
	// FetchPeers fetches the peers from the beacon node.
	FetchPeers(ctx context.Context) (*types.Peers, error)
	// FetchSyncStatus fetches the sync status from the beacon node.
	FetchSyncStatus(ctx context.Context) (*v1.SyncState, error)
	// FetchNodeVersion fetches the node version from the beacon node.
	FetchNodeVersion(ctx context.Context) (string, error)
	// FetchSpec fetches the spec from the beacon node.
	FetchSpec(ctx context.Context) (*state.Spec, error)
	// FetchProposerDuties fetches the proposer duties from the beacon node.
	FetchProposerDuties(ctx context.Context, epoch phase0.Epoch) ([]*v1.ProposerDuty, error)
	// FetchForkChoice fetches the fork choice context.
	FetchForkChoice(ctx context.Context) (*v1.ForkChoice, error)
	// FetchDepositSnapshot fetches the deposit snapshot.
	FetchDepositSnapshot(ctx context.Context) (*types.DepositSnapshot, error)
	// FetchBeaconCommittees fetches the committees for the given epoch at the given state.
	FetchBeaconCommittees(ctx context.Context, state string, epoch phase0.Epoch) ([]*v1.BeaconCommittee, error)
	// FetchAttestationData fetches the attestation data for the given slot and committee index.
	FetchAttestationData(ctx context.Context, slot phase0.Slot, committeeIndex phase0.CommitteeIndex) (*phase0.AttestationData, error)
	// FetchBeaconBlockBlobs fetches blob sidecars for the given block id.
	FetchBeaconBlockBlobs(ctx context.Context, blockID string) ([]*deneb.BlobSidecar, error)

	// Subscriptions
	// - Proxied Beacon events
	// OnEvent is called when a beacon event is received.
	OnEvent(ctx context.Context, handler func(ctx context.Context, ev *v1.Event) error)
	// OnBlock is called when a block is received.
	OnBlock(ctx context.Context, handler func(ctx context.Context, ev *v1.BlockEvent) error)
	// OnAttestation is called when an attestation is received.
	OnAttestation(ctx context.Context, handler func(ctx context.Context, ev *phase0.Attestation) error)
	// OnFinalizedCheckpoint is called when a finalized checkpoint is received.
	OnFinalizedCheckpoint(ctx context.Context, handler func(ctx context.Context, ev *v1.FinalizedCheckpointEvent) error)
	// OnHead is called when the head is received.
	OnHead(ctx context.Context, handler func(ctx context.Context, ev *v1.HeadEvent) error)
	// OnChainReOrg is called when a chain reorg is received.
	OnChainReOrg(ctx context.Context, handler func(ctx context.Context, ev *v1.ChainReorgEvent) error)
	// OnVoluntaryExit is called when a voluntary exit is received.
	OnVoluntaryExit(ctx context.Context, handler func(ctx context.Context, ev *phase0.SignedVoluntaryExit) error)
	// OnContributionAndProof is called when a contribution and proof is received.
	OnContributionAndProof(ctx context.Context, handler func(ctx context.Context, ev *altair.SignedContributionAndProof) error)
	// OnBlobSidecar is called when a blob sidecar is received.
	OnBlobSidecar(ctx context.Context, handler func(ctx context.Context, ev *v1.BlobSidecarEvent) error)

	// - Custom events
	// OnReady is called when the node is ready.
	OnReady(ctx context.Context, handler func(ctx context.Context, event *ReadyEvent) error)
	// OnSyncStatus is called when the sync status changes.
	OnSyncStatus(ctx context.Context, handler func(ctx context.Context, event *SyncStatusEvent) error)
	// OnNodeVersionUpdated is called when the node version is updated.
	OnNodeVersionUpdated(ctx context.Context, handler func(ctx context.Context, event *NodeVersionUpdatedEvent) error)
	// OnPeersUpdated is called when the peers are updated.
	OnPeersUpdated(ctx context.Context, handler func(ctx context.Context, event *PeersUpdatedEvent) error)
	// OnSpecUpdated is called when the spec is updated.
	OnSpecUpdated(ctx context.Context, handler func(ctx context.Context, event *SpecUpdatedEvent) error)
	// OnEmptySlot is called when an empty slot is detected.
	OnEmptySlot(ctx context.Context, handler func(ctx context.Context, event *EmptySlotEvent) error)
	// OnHealthCheckFailed is called when a health check fails.
	OnHealthCheckFailed(ctx context.Context, handler func(ctx context.Context, event *HealthCheckFailedEvent) error)
	// OnHealthCheckSucceeded is called when a health check succeeds.
	OnHealthCheckSucceeded(ctx context.Context, handler func(ctx context.Context, event *HealthCheckSucceededEvent) error)
	// OnFinalityCheckpointUpdated is called when a the head finality checkpoint is updated.
	OnFinalityCheckpointUpdated(ctx context.Context, handler func(ctx context.Context, event *FinalityCheckpointUpdated) error)
}

func NewNode

func NewNode(log logrus.FieldLogger, config *Config, namespace string, options Options) Node

NewNode creates a new beacon node.

type NodeVersionUpdatedEvent

type NodeVersionUpdatedEvent struct {
	Version string
}

NodeVersionUpdatedEvent is emitted when the node version is updated.

type Options

type Options struct {
	BeaconSubscription BeaconSubscriptionOptions
	HealthCheck        HealthCheckOptions
	PrometheusMetrics  bool
	DetectEmptySlots   bool
}

Options holds the options for a beacon node.

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default options.

func (*Options) DisableEmptySlotDetection

func (o *Options) DisableEmptySlotDetection() *Options

DisableEmptySlotDetection disables empty slot detection.

func (*Options) DisablePrometheusMetrics

func (o *Options) DisablePrometheusMetrics() *Options

DisablePrometheusMetrics disables Prometheus metrics.

func (*Options) EnableDefaultBeaconSubscription

func (o *Options) EnableDefaultBeaconSubscription() *Options

EnableDefaultBeaconSubscription enables the default beacon subscription.

func (*Options) EnableEmptySlotDetection

func (o *Options) EnableEmptySlotDetection() *Options

EnableEmptySlotDetection enables empty slot detection.

func (*Options) EnablePrometheusMetrics

func (o *Options) EnablePrometheusMetrics() *Options

EnablePrometheusMetrics enables Prometheus metrics.

type PeersUpdatedEvent

type PeersUpdatedEvent struct {
	Peers types.Peers
}

PeersUpdatedEvent is emitted when the peer list is updated.

type ReadyEvent

type ReadyEvent struct {
}

type SpecMetrics

type SpecMetrics struct {
	SafeSlotsToUpdateJustified       prometheus.Gauge
	DepositChainID                   prometheus.Gauge
	ConfigName                       prometheus.GaugeVec
	MaxValidatorsPerCommittee        prometheus.Gauge
	SecondsPerEth1Block              prometheus.Gauge
	BaseRewardFactor                 prometheus.Gauge
	EpochsPerSyncCommitteePeriod     prometheus.Gauge
	EffectiveBalanceIncrement        prometheus.Gauge
	MaxAttestations                  prometheus.Gauge
	MinSyncCommitteeParticipants     prometheus.Gauge
	GenesisDelay                     prometheus.Gauge
	SecondsPerSlot                   prometheus.Gauge
	MaxEffectiveBalance              prometheus.Gauge
	TerminalTotalDifficulty          prometheus.Gauge
	TerminalTotalDifficultyTrillions prometheus.Gauge
	MaxDeposits                      prometheus.Gauge
	MinGenesisActiveValidatorCount   prometheus.Gauge
	TargetCommitteeSize              prometheus.Gauge
	SyncCommitteeSize                prometheus.Gauge
	Eth1FollowDistance               prometheus.Gauge
	TerminalBlockHashActivationEpoch prometheus.Gauge
	MinDepositAmount                 prometheus.Gauge
	SlotsPerEpoch                    prometheus.Gauge
	PresetBase                       prometheus.GaugeVec
	// contains filtered or unexported fields
}

SpecMetrics reports metrics about the configured consensus spec.

func NewSpecJob

func NewSpecJob(bc Node, log logrus.FieldLogger, namespace string, constLabels map[string]string) *SpecMetrics

NewSpecJob returns a new Spec instance.

func (*SpecMetrics) Name

func (s *SpecMetrics) Name() string

Name returns the name of the job.

func (*SpecMetrics) Start

func (s *SpecMetrics) Start(ctx context.Context) error

Start starts the job.

func (*SpecMetrics) Stop

func (s *SpecMetrics) Stop() error

Stop stops the job.

type SpecUpdatedEvent

type SpecUpdatedEvent struct {
	Spec *state.Spec
}

SpecUpdatedEvent is emitted when the spec is updated.

type Status

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

Status is a beacon node status.

func NewStatus

func NewStatus(successThreshold, failThreshold int) *Status

NewStatus creates a new status.

func (*Status) Health

func (s *Status) Health() *Health

Health returns the health status.

func (*Status) Healthy

func (s *Status) Healthy() bool

Healthy returns true if the beacon node is healthy.

func (*Status) NetworkID

func (s *Status) NetworkID() uint64

NetworkID returns the network ID.

func (*Status) SyncState

func (s *Status) SyncState() *v1.SyncState

SyncState returns the sync state.

func (*Status) Syncing

func (s *Status) Syncing() bool

Syncing returns true if the beacon node is syncing.

func (*Status) UpdateNetworkID

func (s *Status) UpdateNetworkID(networkID uint64)

UpdateNetworkID updates the network ID.

func (*Status) UpdateSyncState

func (s *Status) UpdateSyncState(state *v1.SyncState)

UpdateSyncState updates the sync state.

type SyncMetrics

type SyncMetrics struct {
	Percentage           prometheus.Gauge
	EstimatedHighestSlot prometheus.Gauge
	HeadSlot             prometheus.Gauge
	Distance             prometheus.Gauge
	IsSyncing            prometheus.Gauge
	// contains filtered or unexported fields
}

SyncMetrics reports metrics on the sync status of the node.

func NewSyncMetrics

func NewSyncMetrics(beac Node, log logrus.FieldLogger, namespace string, constLabels map[string]string) *SyncMetrics

NewSyncMetrics returns a new Sync metrics instance.

func (*SyncMetrics) Name

func (s *SyncMetrics) Name() string

Name returns the name of the job.

func (*SyncMetrics) Start

func (s *SyncMetrics) Start(ctx context.Context) error

Start starts the job.

func (*SyncMetrics) Stop

func (s *SyncMetrics) Stop() error

Stop stops the job.

type SyncStatusEvent

type SyncStatusEvent struct {
	State *v1.SyncState
}

SyncStatusEvent is emitted when the sync status is refreshed.

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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