forkchoice

package
v4.2.1 Latest Latest
Warning

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

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

Documentation

Overview

Package forkchoice implements the service to support fork choice for the Ethereum beacon chain. This contains the necessary components to track latest validators votes, and balances. Then a store object to be used to calculate head. High level fork choice summary: https://notes.ethereum.org/@vbuterin/rkhCgQteN?type=view#LMD-GHOST-fork-choice-rule

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownCommonAncestor = errors.New("unknown common ancestor")

Functions

This section is empty.

Types

type AttestationProcessor

type AttestationProcessor interface {
	ProcessAttestation(context.Context, []uint64, [32]byte, primitives.Epoch)
}

AttestationProcessor processes the attestation that's used for accounting fork choice.

type BalancesByRooter

type BalancesByRooter func(context.Context, [32]byte) ([]uint64, error)

BalancesByRooter is a handler to obtain the effective balances of the state with the given block root

type BlockProcessor

type BlockProcessor interface {
	InsertNode(context.Context, state.BeaconState, [32]byte) error
	InsertChain(context.Context, []*forkchoicetypes.BlockAndCheckpoints) error
}

BlockProcessor processes the block that's used for accounting fork choice.

type FastGetter added in v4.2.0

type FastGetter interface {
	FinalizedCheckpoint() *forkchoicetypes.Checkpoint
	FinalizedPayloadBlockHash() [32]byte
	HasNode([32]byte) bool
	HighestReceivedBlockSlot() primitives.Slot
	HighestReceivedBlockDelay() primitives.Slot
	IsCanonical(root [32]byte) bool
	IsOptimistic(root [32]byte) (bool, error)
	IsViableForCheckpoint(*forkchoicetypes.Checkpoint) (bool, error)
	JustifiedCheckpoint() *forkchoicetypes.Checkpoint
	JustifiedPayloadBlockHash() [32]byte
	LastRoot(primitives.Epoch) [32]byte
	NodeCount() int
	PreviousJustifiedCheckpoint() *forkchoicetypes.Checkpoint
	ProposerBoost() [fieldparams.RootLength]byte
	ReceivedBlocksLastEpoch() (uint64, error)
	ShouldOverrideFCU() bool
	Slot([32]byte) (primitives.Slot, error)
	TargetRootForEpoch([32]byte, primitives.Epoch) ([32]byte, error)
	UnrealizedJustifiedPayloadBlockHash() [32]byte
	Weight(root [32]byte) (uint64, error)
}

type ForkChoicer

type ForkChoicer interface {
	RLocker // separate interface isolates  read locking for ROForkChoice.
	Lock()
	Unlock()
	HeadRetriever        // to compute head.
	BlockProcessor       // to track new block for fork choice.
	AttestationProcessor // to track new attestation for fork choice.
	Getter               // to retrieve fork choice information.
	Setter               // to set fork choice information.
}

ForkChoicer represents the full fork choice interface composed of all the sub-interfaces.

type Getter

type Getter interface {
	FastGetter
	AncestorRoot(ctx context.Context, root [32]byte, slot primitives.Slot) ([32]byte, error)
	CommonAncestor(ctx context.Context, root1 [32]byte, root2 [32]byte) ([32]byte, primitives.Slot, error)
	ForkChoiceDump(context.Context) (*forkchoice2.Dump, error)
	Tips() ([][32]byte, []primitives.Slot)
}

Getter returns fork choice related information.

type HeadRetriever

type HeadRetriever interface {
	Head(context.Context) ([32]byte, error)
	GetProposerHead() [32]byte
	CachedHeadRoot() [32]byte
}

HeadRetriever retrieves head root and optimistic info of the current chain.

type RLocker added in v4.2.0

type RLocker interface {
	RLock()
	RUnlock()
}

RLocker represents forkchoice's internal RWMutex read-only lock/unlock methods.

type ROForkChoice added in v4.2.0

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

ROForkChoice is an implementation of forkchoice.Getter which calls `Rlock`/`RUnlock` around a delegated method call to the underlying Getter implementation.

func NewROForkChoice added in v4.2.0

func NewROForkChoice(w ROWrappable) *ROForkChoice

NewROForkChoice returns an ROForkChoice that delegates forkchoice.Getter calls to the given value after first using its Locker methods to make sure it is correctly locked.

func (*ROForkChoice) FinalizedCheckpoint added in v4.2.0

func (ro *ROForkChoice) FinalizedCheckpoint() *forkchoicetypes.Checkpoint

FinalizedCheckpoint delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) FinalizedPayloadBlockHash added in v4.2.0

func (ro *ROForkChoice) FinalizedPayloadBlockHash() [32]byte

FinalizedPayloadBlockHash delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) HasNode added in v4.2.0

func (ro *ROForkChoice) HasNode(root [32]byte) bool

HasNode delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) HighestReceivedBlockDelay added in v4.2.1

func (ro *ROForkChoice) HighestReceivedBlockDelay() primitives.Slot

HighestReceivedBlockDelay delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) HighestReceivedBlockSlot added in v4.2.0

func (ro *ROForkChoice) HighestReceivedBlockSlot() primitives.Slot

HighestReceivedBlockSlot delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) IsCanonical added in v4.2.0

func (ro *ROForkChoice) IsCanonical(root [32]byte) bool

IsCanonical delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) IsOptimistic added in v4.2.0

func (ro *ROForkChoice) IsOptimistic(root [32]byte) (bool, error)

IsOptimistic delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) IsViableForCheckpoint added in v4.2.0

func (ro *ROForkChoice) IsViableForCheckpoint(cp *forkchoicetypes.Checkpoint) (bool, error)

IsViableForCheckpoint delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) JustifiedCheckpoint added in v4.2.0

func (ro *ROForkChoice) JustifiedCheckpoint() *forkchoicetypes.Checkpoint

JustifiedCheckpoint delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) JustifiedPayloadBlockHash added in v4.2.0

func (ro *ROForkChoice) JustifiedPayloadBlockHash() [32]byte

JustifiedPayloadBlockHash delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) LastRoot added in v4.2.0

func (ro *ROForkChoice) LastRoot(e primitives.Epoch) [32]byte

LastRoot delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) NodeCount added in v4.2.0

func (ro *ROForkChoice) NodeCount() int

NodeCount delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) PreviousJustifiedCheckpoint added in v4.2.0

func (ro *ROForkChoice) PreviousJustifiedCheckpoint() *forkchoicetypes.Checkpoint

PreviousJustifiedCheckpoint delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) ProposerBoost added in v4.2.0

func (ro *ROForkChoice) ProposerBoost() [fieldparams.RootLength]byte

ProposerBoost delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) ReceivedBlocksLastEpoch added in v4.2.0

func (ro *ROForkChoice) ReceivedBlocksLastEpoch() (uint64, error)

ReceivedBlocksLastEpoch delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) ShouldOverrideFCU added in v4.2.0

func (ro *ROForkChoice) ShouldOverrideFCU() bool

ShouldOverrideFCU delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) Slot added in v4.2.0

func (ro *ROForkChoice) Slot(root [32]byte) (primitives.Slot, error)

Slot delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) TargetRootForEpoch added in v4.2.0

func (ro *ROForkChoice) TargetRootForEpoch(root [32]byte, epoch primitives.Epoch) ([32]byte, error)

TargetRootForEpoch delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) UnrealizedJustifiedPayloadBlockHash added in v4.2.0

func (ro *ROForkChoice) UnrealizedJustifiedPayloadBlockHash() [32]byte

UnrealizedJustifiedPayloadBlockHash delegates to the underlying forkchoice call, under a lock.

func (*ROForkChoice) Weight added in v4.2.0

func (ro *ROForkChoice) Weight(root [32]byte) (uint64, error)

Weight delegates to the underlying forkchoice call, under a lock.

type ROWrappable added in v4.2.0

type ROWrappable interface {
	RLocker
	FastGetter
}

ROWrappable represents the subset of ForkChoicer a type needs to support in order for ROForkChoice to wrap it. This simplifies the creation of a mock type that can be used to assert that all of the wrapped methods are correctly called between mutex acquire/release.

type Setter

type Setter interface {
	SetOptimisticToValid(context.Context, [fieldparams.RootLength]byte) error
	SetOptimisticToInvalid(context.Context, [fieldparams.RootLength]byte, [fieldparams.RootLength]byte, [fieldparams.RootLength]byte) ([][32]byte, error)
	UpdateJustifiedCheckpoint(context.Context, *forkchoicetypes.Checkpoint) error
	UpdateFinalizedCheckpoint(*forkchoicetypes.Checkpoint) error
	SetGenesisTime(uint64)
	SetOriginRoot([32]byte)
	NewSlot(context.Context, primitives.Slot) error
	SetBalancesByRooter(BalancesByRooter)
	InsertSlashedIndex(context.Context, primitives.ValidatorIndex)
}

Setter allows to set forkchoice information

Directories

Path Synopsis
Package doublylinkedtree implements eth2 LMD GHOST fork choice using the doubly linked proto array node structure.
Package doublylinkedtree implements eth2 LMD GHOST fork choice using the doubly linked proto array node structure.

Jump to

Keyboard shortcuts

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