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
- type ForkChoice
- func (f *ForkChoice) AncestorRoot(ctx context.Context, root [32]byte, slot uint64) ([]byte, error)
- func (f *ForkChoice) HasNode(root [32]byte) bool
- func (f *ForkChoice) HasParent(root [32]byte) bool
- func (f *ForkChoice) Head(ctx context.Context, justifiedEpoch uint64, justifiedRoot [32]byte, ...) ([32]byte, error)
- func (f *ForkChoice) Node(root [32]byte) *Node
- func (f *ForkChoice) Nodes() []*Node
- func (f *ForkChoice) ProcessAttestation(ctx context.Context, validatorIndices []uint64, blockRoot [32]byte, ...)
- func (f *ForkChoice) ProcessBlock(ctx context.Context, slot uint64, blockRoot [32]byte, parentRoot [32]byte, ...) error
- func (f *ForkChoice) Prune(ctx context.Context, finalizedRoot [32]byte) error
- func (f *ForkChoice) Store() *Store
- type Node
- func (n *Node) BestChild() uint64
- func (n *Node) BestDescendant() uint64
- func (n *Node) FinalizedEpoch() uint64
- func (n *Node) Graffiti() [32]byte
- func (n *Node) JustifiedEpoch() uint64
- func (n *Node) Parent() uint64
- func (n *Node) Root() [32]byte
- func (n *Node) Slot() uint64
- func (n *Node) Weight() uint64
- type Store
- type Vote
Constants ¶
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 uint64, finalizedEpoch uint64, finalizedRoot [32]byte) *ForkChoice
New initializes a new fork choice store.
func (*ForkChoice) AncestorRoot ¶ added in v1.0.0
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) 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 [32]byte, parentRoot [32]byte, graffiti [32]byte, justifiedEpoch uint64, 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) BestDescendant ¶ added in v1.0.0
BestDescendant of the fork choice node.
func (*Node) FinalizedEpoch ¶ added in v1.0.0
FinalizedEpoch of the fork choice node.
func (*Node) JustifiedEpoch ¶ added in v1.0.0
JustifiedEpoch 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
FinalizedEpoch of fork choice store.
func (*Store) JustifiedEpoch ¶ added in v1.0.0
JustifiedEpoch of fork choice store.
func (*Store) NodesIndices ¶ added in v1.0.0
NodesIndices of fork choice store.
func (*Store) PruneThreshold ¶ added in v1.0.0
PruneThreshold of fork choice store.