forkchoice

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 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 ForkChoicer

type ForkChoicer interface {
	Lock()
	Unlock()
	RLock()
	RUnlock()
	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 {
	HasNode([32]byte) bool
	ProposerBoost() [fieldparams.RootLength]byte
	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)
	IsCanonical(root [32]byte) bool
	FinalizedCheckpoint() *forkchoicetypes.Checkpoint
	IsViableForCheckpoint(*forkchoicetypes.Checkpoint) (bool, error)
	FinalizedPayloadBlockHash() [32]byte
	JustifiedCheckpoint() *forkchoicetypes.Checkpoint
	PreviousJustifiedCheckpoint() *forkchoicetypes.Checkpoint
	JustifiedPayloadBlockHash() [32]byte
	UnrealizedJustifiedPayloadBlockHash() [32]byte
	NodeCount() int
	HighestReceivedBlockSlot() primitives.Slot
	ReceivedBlocksLastEpoch() (uint64, error)
	ForkChoiceDump(context.Context) (*v1.ForkChoiceDump, error)
	Weight(root [32]byte) (uint64, error)
	Tips() ([][32]byte, []primitives.Slot)
	IsOptimistic(root [32]byte) (bool, error)
	ShouldOverrideFCU() bool
	Slot([32]byte) (primitives.Slot, error)
	LastRoot(primitives.Epoch) [32]byte
}

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