forkchoice

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

View Source
const NONE = ^ProtoNodeIndex(0)

Variables

View Source
var HeadUnknownErr = errors.New("array has invalid state, head has no index")
View Source
var NoViableHeadErr = errors.New("not a viable head anymore, invalid forkchoice state")
View Source
var UnknownAnchorErr = errors.New("anchor unknown")

Functions

This section is empty.

Types

type BlockRef

type BlockRef struct {
	Slot Slot
	Root Root
}

type BlockSink

type BlockSink interface {
	OnPrunedBlock(node *ProtoNode, canonical bool) error
}

type BlockSinkFn

type BlockSinkFn func(node *ProtoNode, canonical bool) error

func (BlockSinkFn) OnPrunedBlock

func (fn BlockSinkFn) OnPrunedBlock(node *ProtoNode, canonical bool) error

type Checkpoint

type Checkpoint = beacon.Checkpoint

type Epoch

type Epoch = beacon.Epoch

type ForkChoice

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

func NewForkChoice

func NewForkChoice(finalized Checkpoint, justified Checkpoint, sink BlockSink) *ForkChoice

func (*ForkChoice) BlocksAroundSlot

func (fc *ForkChoice) BlocksAroundSlot(anchor Root, slot Slot) (before BlockRef, at BlockRef, after BlockRef, err error)

func (*ForkChoice) Finalized

func (fc *ForkChoice) Finalized() Checkpoint

func (*ForkChoice) FindHead

func (fc *ForkChoice) FindHead() (BlockRef, error)

func (*ForkChoice) GetBlock

func (fc *ForkChoice) GetBlock(root Root) (block BlockRef, ok bool)

func (*ForkChoice) Justified

func (fc *ForkChoice) Justified() Checkpoint

func (*ForkChoice) ProcessAttestation

func (fc *ForkChoice) ProcessAttestation(index ValidatorIndex, blockRoot Root, targetEpoch Epoch)

func (*ForkChoice) ProcessBlock

func (fc *ForkChoice) ProcessBlock(block BlockRef, parentRoot Root, justifiedEpoch Epoch, finalizedEpoch Epoch)

func (*ForkChoice) UpdateJustified

func (fc *ForkChoice) UpdateJustified(justified Checkpoint, finalized Checkpoint, justifiedStateBalances []Gwei) error

type Gwei

type Gwei = beacon.Gwei

type ProtoArray

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

func NewProtoArray

func NewProtoArray(justifiedEpoch Epoch, finalizedEpoch Epoch, sink BlockSink) *ProtoArray

func (*ProtoArray) ApplyScoreChanges

func (pr *ProtoArray) ApplyScoreChanges(deltas []SignedGwei, justifiedEpoch Epoch, finalizedEpoch Epoch) error

Iterate backwards through the array, touching all nodes and their parents and potentially the best-child of each parent.

The structure of the `self.nodes` array ensures that the child of each node is always touched before its parent.

For each node, the following is done:

- Update the node's weight with the corresponding delta (can be negative). - Back-propagate each node's delta to its parents delta. - Compare the current node with the parents best-child, updating it if the current node should become the best child. - If required, update the parents best-descendant with the current node or its best-descendant.

func (*ProtoArray) BlocksAroundSlot

func (pr *ProtoArray) BlocksAroundSlot(anchor Root, slot Slot) (before BlockRef, at BlockRef, after BlockRef, err error)

func (*ProtoArray) CanonicalChain

func (pr *ProtoArray) CanonicalChain(anchorRoot Root) ([]BlockRef, error)

From head back to anchor root (including the anchor itself, if present)

func (*ProtoArray) ContainsBlock

func (pr *ProtoArray) ContainsBlock(blockRoot Root) bool

func (*ProtoArray) FindHead

func (pr *ProtoArray) FindHead(anchorRoot Root) (BlockRef, error)

Finds the head, starting from the anchor_root subtree. (justified_root for regular fork-choice)

Follows the best-descendant links to find the best-block (i.e., head-block).

The result of this function is not guaranteed to be accurate if `OnBlock` has been called without a subsequent `applyScoreChanges` call. This is because `OnBlock` does not attempt to walk backwards through the tree and update the best-child/best-descendant links.

func (*ProtoArray) GetBlock

func (pr *ProtoArray) GetBlock(blockRoot Root) (BlockRef, bool)

func (*ProtoArray) OnBlock

func (pr *ProtoArray) OnBlock(block BlockRef, parent Root, justifiedEpoch Epoch, finalizedEpoch Epoch)

Register a block with the fork choice.

It is only sane to supply a `None` parent for the genesis block.

func (*ProtoArray) OnPrune

func (pr *ProtoArray) OnPrune(anchorRoot Root) error

Update the tree with new finalization information (or alternatively another trusted root)

type ProtoNode

type ProtoNode struct {
	Block          BlockRef
	Parent         ProtoNodeIndex
	JustifiedEpoch Epoch
	FinalizedEpoch Epoch
	Weight         SignedGwei
	BestChild      ProtoNodeIndex
	BestDescendant ProtoNodeIndex
}

type ProtoNodeIndex

type ProtoNodeIndex uint64

type Root

type Root = beacon.Root

type SignedGwei

type SignedGwei = int64

type Slot

type Slot = beacon.Slot

type ValidatorIndex

type ValidatorIndex = beacon.ValidatorIndex

type VoteTracker

type VoteTracker struct {
	CurrentRoot Root
	NextRoot    Root
	NextEpoch   Epoch
}

Jump to

Keyboard shortcuts

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