protoarray

package
v1.2.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: GPL-3.0 Imports: 11 Imported by: 21

Documentation

Overview

Package protoarray implements proto array fork choice as outlined: https://github.com/protolambda/lmd-ghost#array-based-stateful-dag-proto_array This was motivated by the the original implementation by Sigma Prime here: https://github.com/sigp/lighthouse/pull/804

Index

Constants

View Source
const NonExistentNode = ^uint64(0)

NonExistentNode defines an unknown node which is used for the array based stateful DAG.

Variables

This section is empty.

Functions

This section is empty.

Types

type ForkChoice

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

ForkChoice defines the overall fork choice store which includes all block nodes, validator's latest votes and balances.

func New

func New(justifiedEpoch, finalizedEpoch uint64, finalizedRoot [32]byte) *ForkChoice

New initializes a new fork choice store.

func (*ForkChoice) AncestorRoot added in v1.0.0

func (f *ForkChoice) AncestorRoot(ctx context.Context, root [32]byte, slot uint64) ([]byte, error)

AncestorRoot returns the ancestor root of input block root at a given slot.

func (*ForkChoice) HasNode

func (f *ForkChoice) HasNode(root [32]byte) bool

HasNode returns true if the node exists in fork choice store, false else wise.

func (*ForkChoice) HasParent added in v1.0.0

func (f *ForkChoice) HasParent(root [32]byte) bool

HasParent returns true if the node parent exists in fork choice store, false else wise.

func (*ForkChoice) Head

func (f *ForkChoice) Head(ctx context.Context, justifiedEpoch uint64, justifiedRoot [32]byte, justifiedStateBalances []uint64, finalizedEpoch uint64) ([32]byte, error)

Head returns the head root from fork choice store. It firsts computes validator's balance changes then recalculates block tree from leaves to root.

func (*ForkChoice) IsCanonical added in v1.0.0

func (f *ForkChoice) IsCanonical(root [32]byte) bool

IsCanonical returns true if the given root is part of the canonical chain.

func (*ForkChoice) Node

func (f *ForkChoice) Node(root [32]byte) *Node

Node returns the copied node in the fork choice store.

func (*ForkChoice) Nodes

func (f *ForkChoice) Nodes() []*Node

Nodes returns the copied list of block nodes in the fork choice store.

func (*ForkChoice) ProcessAttestation

func (f *ForkChoice) ProcessAttestation(ctx context.Context, validatorIndices []uint64, blockRoot [32]byte, targetEpoch uint64)

ProcessAttestation processes attestation for vote accounting, it iterates around validator indices and update their votes accordingly.

func (*ForkChoice) ProcessBlock

func (f *ForkChoice) ProcessBlock(ctx context.Context, slot uint64, blockRoot, parentRoot, graffiti [32]byte, justifiedEpoch, finalizedEpoch uint64) error

ProcessBlock processes a new block by inserting it to the fork choice store.

func (*ForkChoice) Prune

func (f *ForkChoice) Prune(ctx context.Context, finalizedRoot [32]byte) error

Prune prunes the fork choice store with the new finalized root. The store is only pruned if the input root is different than the current store finalized root, and the number of the store has met prune threshold.

func (*ForkChoice) Store added in v1.0.0

func (f *ForkChoice) Store() *Store

Store returns the fork choice store object which contains all the information regarding proto array fork choice.

type Node

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

Node defines the individual block which includes its block parent, ancestor and how much weight accounted for it. This is used as an array based stateful DAG for efficient fork choice look up.

func (*Node) BestChild added in v1.0.0

func (n *Node) BestChild() uint64

BestChild of the fork choice node.

func (*Node) BestDescendant added in v1.0.0

func (n *Node) BestDescendant() uint64

BestDescendant of the fork choice node.

func (*Node) FinalizedEpoch added in v1.0.0

func (n *Node) FinalizedEpoch() uint64

FinalizedEpoch of the fork choice node.

func (*Node) Graffiti added in v1.0.0

func (n *Node) Graffiti() [32]byte

Graffiti of the fork choice node.

func (*Node) JustifiedEpoch added in v1.0.0

func (n *Node) JustifiedEpoch() uint64

JustifiedEpoch of the fork choice node.

func (*Node) Parent

func (n *Node) Parent() uint64

Parent of the fork choice node.

func (*Node) Root added in v1.0.0

func (n *Node) Root() [32]byte

Root of the fork choice node.

func (*Node) Slot

func (n *Node) Slot() uint64

Slot of the fork choice node.

func (*Node) Weight

func (n *Node) Weight() uint64

Weight of the fork choice node.

type Store

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

Store defines the fork choice store which includes block nodes and the last view of checkpoint information.

func (*Store) FinalizedEpoch added in v1.0.0

func (s *Store) FinalizedEpoch() uint64

FinalizedEpoch of fork choice store.

func (*Store) JustifiedEpoch added in v1.0.0

func (s *Store) JustifiedEpoch() uint64

JustifiedEpoch of fork choice store.

func (*Store) Nodes added in v1.0.0

func (s *Store) Nodes() []*Node

Nodes of fork choice store.

func (*Store) NodesIndices added in v1.0.0

func (s *Store) NodesIndices() map[[32]byte]uint64

NodesIndices of fork choice store.

func (*Store) PruneThreshold added in v1.0.0

func (s *Store) PruneThreshold() uint64

PruneThreshold of fork choice store.

type Vote

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

Vote defines an individual validator's vote.

Jump to

Keyboard shortcuts

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