chain

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package chain provides epoch-level state management and builder information caching.

Index

Constants

View Source
const BuilderIndexFlag uint64 = 1 << 40
View Source
const (

	// EtherGweiFactor is the number of Gwei in 1 ETH.
	EtherGweiFactor = phase0.Gwei(1_000_000_000)
)
View Source
const FarFutureEpoch = uint64(0xFFFFFFFFFFFFFFFF)

FarFutureEpoch is the sentinel value indicating a builder/validator has not exited.

Variables

This section is empty.

Functions

func BeaconVersion

func BeaconVersion(v enginev.DataVersion) (version.DataVersion, error)

BeaconVersion maps an Engine API (execution) data version back to the canonical beacon (consensus) fork that introduced it.

func EngineVersion

func EngineVersion(v version.DataVersion) (enginev.DataVersion, error)

EngineVersion maps a beacon (consensus) fork to the Engine API (execution) data version whose payload structures it carries. It errors for pre-merge forks (phase0/altair), which have no execution payload.

func IsBuilderActive

func IsBuilderActive(info *BuilderInfo, finalizedEpoch uint64) bool

IsBuilderActive returns true when a builder's deposit has been finalized and the builder has not exited. Pass the result of GetBuilderByPubkey and GetFinalizedEpoch.

Types

type ActiveIndiceIndex

type ActiveIndiceIndex uint32

ActiveIndiceIndex is a uint32 index into the active validators array.

type BlobScheduleEntry

type BlobScheduleEntry struct {
	Epoch            uint64
	MaxBlobsPerBlock uint64
}

BlobScheduleEntry represents a single entry in the BLOB_SCHEDULE.

type BuilderInfo

type BuilderInfo struct {
	Index             uint64
	Pubkey            phase0.BLSPubKey
	Balance           uint64
	Active            bool
	DepositEpoch      uint64
	WithdrawableEpoch uint64
	PendingPayments   uint64 // Sum of pending payments from BuilderPendingPayments in state
}

BuilderInfo represents information about a builder from the beacon state.

type ChainSpec

type ChainSpec struct {
	SecondsPerSlot time.Duration
	SlotsPerEpoch  uint64

	// Duty calculation parameters
	ShuffleRoundCount          uint64
	TargetCommitteeSize        uint64
	MaxCommitteesPerSlot       uint64
	MaxEffectiveBalance        uint64
	MaxEffectiveBalanceElectra uint64
	EpochsPerHistoricalVector  uint64
	MinSeedLookahead           uint64

	// Pending-deposit processing parameters (Electra). Used to estimate how many
	// pending deposits drain per epoch when timing the pre-Gloas early onboarding
	// deposit (see pkg/lifecycle pending-deposit simulation).
	MinPerEpochChurnLimit               uint64
	ChurnLimitQuotient                  uint64
	MaxPerEpochActivationExitChurnLimit uint64
	MaxPendingDepositsPerEpoch          uint64
	MinActivationBalance                uint64
	EffectiveBalanceIncrement           uint64

	// Domain types
	DomainBeaconProposer      phase0.DomainType
	DomainBeaconAttester      phase0.DomainType
	DomainPtcAttester         phase0.DomainType
	DomainProposerPreferences phase0.DomainType

	// Fork epochs and versions (nil if not configured)
	ForkSchedule []ForkSchedule

	// Blob schedule (BPO - Blob Parameters Only)
	BlobSchedule []BlobScheduleEntry

	// ePBS parameters
	PtcSize uint64

	// Deposit contract
	DepositContractAddress *common.Address
}

ChainSpec holds chain specification parameters.

func ParseChainSpec

func ParseChainSpec(specData map[string]string, rawData map[string]json.RawMessage) (*ChainSpec, error)

ParseChainSpec parses the chain specification from the spec data.

func (*ChainSpec) GetForkEpoch

func (s *ChainSpec) GetForkEpoch(fork version.DataVersion) phase0.Epoch

GetForkEpoch returns the epoch of a given fork.

func (*ChainSpec) GetForkVersion

func (s *ChainSpec) GetForkVersion(fork version.DataVersion) (phase0.Version, error)

GetForkVersion returns the fork version for a given fork.

func (*ChainSpec) IsForkActive

func (s *ChainSpec) IsForkActive(fork version.DataVersion, epoch phase0.Epoch) bool

IsForkActive checks if a fork is active for a given epoch.

func (*ChainSpec) IsForkScheduled

func (s *ChainSpec) IsForkScheduled(fork version.DataVersion) bool

IsForkScheduled checks if a fork is scheduled.

type DutyState

type DutyState struct {
	RandaoMix           *phase0.Hash32
	NextRandaoMix       *phase0.Hash32
	GetRandaoMixes      func() []phase0.Root
	GetActiveCount      func() uint64
	GetEffectiveBalance func(index ActiveIndiceIndex) phase0.Gwei
}

DutyState holds the state data needed for duty calculations.

type EpochStats

type EpochStats struct {
	Version        version.DataVersion
	Epoch          phase0.Epoch
	FinalizedEpoch phase0.Epoch
	StateSlot      phase0.Slot

	// Validator data
	ActiveValidators  uint64
	ValidatorCount    uint64
	ActiveIndices     []phase0.ValidatorIndex
	EffectiveBalances []uint32 // Effective balance in full ETH units

	// Builder data (for lifecycle management, Gloas only).
	// Populated (possibly empty) for any Gloas+ state; nil for pre-Gloas epochs.
	Builders []*BuilderInfo

	// Total active effective balance (gwei). Used to estimate the activation-exit
	// churn limit for pending-deposit processing (early-onboarding timing).
	TotalActiveBalance uint64

	// Pending-deposit queue data (Electra+). Used to time the pre-Gloas early
	// onboarding deposit so it is still queued at the fork boundary.
	PendingDeposits           []PendingDepositInfo
	DepositBalanceToConsume   uint64 // gwei
	Eth1DepositIndex          uint64
	DepositRequestsStartIndex uint64

	// Pre-computed duties
	RandaoMix      phase0.Hash32
	NextRandaoMix  phase0.Hash32
	ProposerDuties []phase0.ValidatorIndex // [slot_index] -> validator index
	AttesterDuties [][][]ActiveIndiceIndex // [slot_index][committee_index][member] -> active indice index
	PtcDuties      [][]ActiveIndiceIndex   // [slot_index][ptc_member] -> active indice index (Gloas only)
}

EpochStats holds cached statistics for an epoch computed from beacon state.

type ForkSchedule

type ForkSchedule struct {
	Fork    version.DataVersion
	Version phase0.Version
	Epoch   phase0.Epoch
}

type HeadVoteTracker

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

HeadVoteTracker tracks head vote participation per slot by processing attestation events against known attester duties.

func NewHeadVoteTracker

func NewHeadVoteTracker(
	chainSvc Service,
	clClient *beacon.Client,
	log logrus.FieldLogger,
) *HeadVoteTracker

NewHeadVoteTracker creates a new head vote tracker.

func (*HeadVoteTracker) Start

func (t *HeadVoteTracker) Start(ctx context.Context)

Start starts the head vote tracker.

func (*HeadVoteTracker) Stop

func (t *HeadVoteTracker) Stop()

Stop stops the head vote tracker.

func (*HeadVoteTracker) SubscribeUpdates

func (t *HeadVoteTracker) SubscribeUpdates() *utils.Subscription[*HeadVoteUpdate]

SubscribeUpdates returns a subscription for head vote updates.

type HeadVoteUpdate

type HeadVoteUpdate struct {
	Slot             phase0.Slot
	ParticipationPct float64
	ParticipationETH uint64
	TotalSlotETH     uint64
	Timestamp        int64
}

HeadVoteUpdate is dispatched when head vote participation changes.

type PendingDepositInfo

type PendingDepositInfo struct {
	Pubkey phase0.BLSPubKey
	Amount uint64 // gwei
	Slot   phase0.Slot
}

PendingDepositInfo is a single entry of the beacon state's pending_deposits queue, reduced to the fields needed to model Electra deposit-queue draining and to identify our own (early-onboarding) deposit after a restart.

type Service

type Service interface {
	Start(ctx context.Context) error
	Stop() error

	// Chain state accessors
	GetChainSpec() *ChainSpec
	GetGenesis() *beacon.Genesis
	SlotToTime(slot phase0.Slot) time.Time
	TimeToSlot(t time.Time) phase0.Slot
	GetCurrentEpoch() phase0.Epoch
	GetCurrentSlot() phase0.Slot
	GetCurrentFork() version.DataVersion
	ActiveForkAtEpoch(epoch phase0.Epoch) version.DataVersion
	GetForkVersion() (phase0.Version, error)
	GetEpochOfSlot(slot phase0.Slot) phase0.Epoch

	// Epoch stats access
	GetCurrentEpochStats() *EpochStats
	GetEpochStats(epoch phase0.Epoch) *EpochStats

	// Subscriptions
	SubscribeEpochStats() *utils.Subscription[*EpochStats]

	// Head vote tracking
	GetHeadVoteTracker() *HeadVoteTracker

	// Finality
	GetFinalizedEpoch() phase0.Epoch

	// Builder access
	GetBuilderByIndex(index uint64) *BuilderInfo
	GetBuilderByPubkey(pubkey phase0.BLSPubKey) *BuilderInfo
	GetBuilders() []*BuilderInfo

	// Validator access
	GetValidatorPubkeyByIndex(index phase0.ValidatorIndex) *phase0.BLSPubKey

	// RefreshBuilders re-fetches the beacon state to pick up new builder registrations.
	RefreshBuilders(ctx context.Context) error

	// SetProposerPreferencesCache registers the proposer preferences cache so
	// it can be pruned on each epoch transition. Pass nil to disable pruning.
	SetProposerPreferencesCache(cache *proposerpreferences.Cache)
}

Service interface defines the chain service operations.

func NewService

func NewService(
	clClient *beacon.Client,
	chainSpec *ChainSpec,
	genesis *beacon.Genesis,
	log logrus.FieldLogger,
) Service

NewService creates a new chain service.

Jump to

Keyboard shortcuts

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