proto

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const NONE = ^NodeIndex(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

func NewProtoForkChoice

func NewProtoForkChoice(spec *common.Spec, finalized Checkpoint, justified Checkpoint,
	anchorRoot Root, anchorSlot Slot, anchorParent Root,
	initialBalances []Gwei, sink NodeSink) (Forkchoice, error)

func NewProtoVoteStore

func NewProtoVoteStore(spec *common.Spec) VoteStore

Types

type NodeSink

type NodeSink interface {
	OnPrunedNode(ctx context.Context, ref NodeRef, canonical bool) error
}

type NodeSinkFn

type NodeSinkFn func(ctx context.Context, ref NodeRef, canonical bool) error

func (NodeSinkFn) OnPrunedNode

func (fn NodeSinkFn) OnPrunedNode(ctx context.Context, ref NodeRef, canonical bool) error

type ProtoArray

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

Tracks slots and blocks as nodes. Every block has two nodes: with and without the block. The node with the block is the child of that without it. Gap slots just have a single node. There may be multiple nodes with the same parent but different blocks (i.e. double proposals, but slashable).

func NewProtoArray

func NewProtoArray(parent Root, blockRoot Root, blockSlot Slot, justifiedEpoch Epoch, finalizedEpoch Epoch, sink NodeSink) *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) CanonAtSlot

func (pr *ProtoArray) CanonAtSlot(anchor Root, slot Slot, withBlock bool) (at NodeRef, err error)

Returns the canonical node at the given slot. If withBlock is false, a slot node is retrieved. If true, a block node is retrieved, or nil if the slot is empty. If there is a double proposal, the canonical block (w.r.t. votes) is used. If the fork-choice starts at a filled slot node, this node cannot be requested with withBlock == false, as the data is already pruned.

func (*ProtoArray) CanonicalChain

func (pr *ProtoArray) CanonicalChain(anchorRoot Root, anchorSlot Slot) ([]ExtendedNodeRef, error)

From head back to anchor root (including the anchor itself, if present) and anchor slot. Includes nodes with empty block, then followed up by a node with the block if there is any.

func (*ProtoArray) ClosestToSlot

func (pr *ProtoArray) ClosestToSlot(anchor Root, slot Slot) (closest NodeRef, err error)

Returns the closest empty-slot node to the given slot. Nodes with blocks after the anchor are ignored.

func (*ProtoArray) FindHead

func (pr *ProtoArray) FindHead(anchorRoot Root, anchorSlot Slot) (NodeRef, error)

Finds the head, starting from the anchor_root *forkchoice* 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) GetSlot

func (pr *ProtoArray) GetSlot(blockRoot Root) (Slot, bool)

func (*ProtoArray) InSubtree

func (pr *ProtoArray) InSubtree(anchor Root, root Root) (unknown bool, inSubtree bool)

InSubtree checks if root is in the subtree of the anchor. If the roots are the same, it still counts as in the subtree.

func (*ProtoArray) Indices

func (pr *ProtoArray) Indices() map[NodeRef]NodeIndex

func (*ProtoArray) OnPrune

func (pr *ProtoArray) OnPrune(ctx context.Context, anchorRoot Root, anchorSlot Slot) error

Update the tree with new finalization information (or alternatively another trusted root and slot) The slot may point to a gap slot, in which case the node with the anchor block of the anchor block-root is pruned, and the next nodes, up to (and excl.) the anchorSlot.

func (*ProtoArray) ProcessBlock

func (pr *ProtoArray) ProcessBlock(parent Root, blockRoot Root, blockSlot Slot, justifiedEpoch Epoch, finalizedEpoch Epoch) (ok bool)

Register a block with the fork choice. Calls OnSlot to add any missing slot nodes. If justified or finalized in-between, make sure to call OnSlot with accurate details first.

The parent root of the genesis block should be zeroed.

func (*ProtoArray) ProcessSlot

func (pr *ProtoArray) ProcessSlot(parent Root, slot Slot, justifiedEpoch Epoch, finalizedEpoch Epoch)

Called to add an empty slot to the graph. Any gaps between the existing graph nodes and the given slot are filled with nodes. If the justifiedEpoch or finalizedEpoch changed in-between the existing graph and the new slot, the call should be split with increasing slot numbers, to reflect the changes of justification and finalization.

func (*ProtoArray) Search

func (pr *ProtoArray) Search(anchor NodeRef, parentRoot *Root, slot *Slot) (nonCanon []NodeRef, canon []NodeRef, err error)

Searches the available nodes for blocks with a matching parent root and/or matching slot. If no options are specified, the

type ProtoNode

type ProtoNode struct {
	Ref NodeRef
	// The transition parent of a block node is the node of the same slot, without the block.
	// The transition parent of a slot node is the slot or block before it.
	TransitionParent NodeIndex
	// The forkchoice parent of a node is strictly one slot lower, it cannot be the same slot.
	ForkchoiceParent NodeIndex
	// Duplicated to avoid pruning of this useful info.
	ParentRoot     Root
	JustifiedEpoch Epoch
	FinalizedEpoch Epoch
	Weight         SignedGwei
	// Relative to ForkchoiceParent relations
	BestChild NodeIndex
	// Relative to ForkchoiceParent relations
	BestDescendant NodeIndex
}

type ProtoVoteStore

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

func (*ProtoVoteStore) ComputeDeltas

func (st *ProtoVoteStore) ComputeDeltas(indices map[NodeRef]NodeIndex, oldBalances []Gwei, newBalances []Gwei) []SignedGwei

Returns a list of `deltas`, where there is one delta for each of the ProtoArray nodes. The deltas are calculated between `oldBalances` and `newBalances`, and/or a change of vote. The votestore is updated, the next deltas will be 0 if ProcessAttestation is not changing any vote.

func (*ProtoVoteStore) HasChanges

func (st *ProtoVoteStore) HasChanges() bool

func (*ProtoVoteStore) ProcessAttestation

func (st *ProtoVoteStore) ProcessAttestation(index ValidatorIndex, blockRoot Root, headSlot Slot) (ok bool)

Process an attestation. (Note that the head slot may be for a gap slot after the block root)

type VoteTracker

type VoteTracker struct {
	Current            NodeRef
	Next               NodeRef
	CurrentTargetEpoch Epoch
	NextTargetEpoch    Epoch
}

Jump to

Keyboard shortcuts

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