Documentation
¶
Index ¶
- Constants
- Variables
- type BlockRef
- type BlockSink
- type BlockSinkFn
- type Checkpoint
- type Epoch
- type ForkChoice
- func (fc *ForkChoice) BlocksAroundSlot(anchor Root, slot Slot) (before BlockRef, at BlockRef, after BlockRef, err error)
- func (fc *ForkChoice) Finalized() Checkpoint
- func (fc *ForkChoice) FindHead() (BlockRef, error)
- func (fc *ForkChoice) GetBlock(root Root) (block BlockRef, ok bool)
- func (fc *ForkChoice) Justified() Checkpoint
- func (fc *ForkChoice) ProcessAttestation(index ValidatorIndex, blockRoot Root, targetEpoch Epoch)
- func (fc *ForkChoice) ProcessBlock(block BlockRef, parentRoot Root, justifiedEpoch Epoch, finalizedEpoch Epoch)
- func (fc *ForkChoice) UpdateJustified(justified Checkpoint, finalized Checkpoint, justifiedStateBalances []Gwei) error
- type Gwei
- type ProtoArray
- func (pr *ProtoArray) ApplyScoreChanges(deltas []SignedGwei, justifiedEpoch Epoch, finalizedEpoch Epoch) error
- func (pr *ProtoArray) BlocksAroundSlot(anchor Root, slot Slot) (before BlockRef, at BlockRef, after BlockRef, err error)
- func (pr *ProtoArray) CanonicalChain(anchorRoot Root) ([]BlockRef, error)
- func (pr *ProtoArray) ContainsBlock(blockRoot Root) bool
- func (pr *ProtoArray) FindHead(anchorRoot Root) (BlockRef, error)
- func (pr *ProtoArray) GetBlock(blockRoot Root) (BlockRef, bool)
- func (pr *ProtoArray) OnBlock(block BlockRef, parent Root, justifiedEpoch Epoch, finalizedEpoch Epoch)
- func (pr *ProtoArray) OnPrune(anchorRoot Root) error
- type ProtoNode
- type ProtoNodeIndex
- type Root
- type SignedGwei
- type Slot
- type ValidatorIndex
- type VoteTracker
Constants ¶
const NONE = ^ProtoNodeIndex(0)
Variables ¶
var HeadUnknownErr = errors.New("array has invalid state, head has no index")
var NoViableHeadErr = errors.New("not a viable head anymore, invalid forkchoice state")
var UnknownAnchorErr = errors.New("anchor unknown")
Functions ¶
This section is empty.
Types ¶
type BlockSinkFn ¶
func (BlockSinkFn) OnPrunedBlock ¶
func (fn BlockSinkFn) OnPrunedBlock(node *ProtoNode, canonical bool) error
type Checkpoint ¶
type Checkpoint = beacon.Checkpoint
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 (*ForkChoice) Finalized ¶
func (fc *ForkChoice) Finalized() Checkpoint
func (*ForkChoice) FindHead ¶
func (fc *ForkChoice) FindHead() (BlockRef, error)
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 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 (*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) 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 SignedGwei ¶
type SignedGwei = int64
type ValidatorIndex ¶
type ValidatorIndex = beacon.ValidatorIndex