forkchoice

package
v5.0.4-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

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

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

type RLocker interface {
	RLock()
	RUnlock()
}

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

type ROForkChoice

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

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

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

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

func (*ROForkChoice) FinalizedPayloadBlockHash

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

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

func (*ROForkChoice) HasNode

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

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

func (*ROForkChoice) HighestReceivedBlockDelay

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

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

func (*ROForkChoice) HighestReceivedBlockSlot

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

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

func (*ROForkChoice) IsCanonical

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

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

func (*ROForkChoice) IsOptimistic

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

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

func (*ROForkChoice) IsViableForCheckpoint

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

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

func (*ROForkChoice) JustifiedCheckpoint

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

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

func (*ROForkChoice) JustifiedPayloadBlockHash

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

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

func (*ROForkChoice) LastRoot

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

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

func (*ROForkChoice) NodeCount

func (ro *ROForkChoice) NodeCount() int

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

func (*ROForkChoice) PreviousJustifiedCheckpoint

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

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

func (*ROForkChoice) ProposerBoost

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

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

func (*ROForkChoice) ReceivedBlocksLastEpoch

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

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

func (*ROForkChoice) ShouldOverrideFCU

func (ro *ROForkChoice) ShouldOverrideFCU() bool

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

func (*ROForkChoice) Slot

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

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

func (*ROForkChoice) TargetRootForEpoch

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

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

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

func (*ROForkChoice) Weight

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

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

type ROWrappable

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