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 original implementation by Sigma Prime here: https://github.com/sigp/lighthouse/pull/804
Index ¶
- Constants
- Variables
- type ForkChoice
- func (f *ForkChoice) AllTipsAreInvalid() bool
- func (f *ForkChoice) AncestorRoot(ctx context.Context, root [32]byte, slot types.Slot) ([32]byte, error)
- func (f *ForkChoice) BestJustifiedCheckpoint() *forkchoicetypes.Checkpoint
- func (f *ForkChoice) CachedHeadRoot() [32]byte
- func (f *ForkChoice) CommonAncestor(ctx context.Context, r1 [32]byte, r2 [32]byte) ([32]byte, types.Slot, error)
- func (f *ForkChoice) FinalizedCheckpoint() *forkchoicetypes.Checkpoint
- func (f *ForkChoice) FinalizedPayloadBlockHash() [32]byte
- func (*ForkChoice) ForkChoiceDump(_ context.Context) (*v1.ForkChoiceResponse, error)
- func (f *ForkChoice) HasNode(root [32]byte) bool
- func (f *ForkChoice) HasParent(root [32]byte) bool
- func (f *ForkChoice) Head(ctx context.Context, justifiedStateBalances []uint64) ([32]byte, error)
- func (f *ForkChoice) HighestReceivedBlockSlot() types.Slot
- func (f *ForkChoice) InsertNode(ctx context.Context, state state.BeaconState, root [32]byte) error
- func (f *ForkChoice) InsertOptimisticChain(ctx context.Context, chain []*forkchoicetypes.BlockAndCheckpoints) error
- func (f *ForkChoice) InsertSlashedIndex(ctx context.Context, index types.ValidatorIndex)
- func (f *ForkChoice) IsCanonical(root [32]byte) bool
- func (f *ForkChoice) IsOptimistic(root [32]byte) (bool, error)
- func (f *ForkChoice) JustifiedCheckpoint() *forkchoicetypes.Checkpoint
- func (f *ForkChoice) JustifiedPayloadBlockHash() [32]byte
- func (f *ForkChoice) NewSlot(ctx context.Context, slot types.Slot) error
- func (f *ForkChoice) NodeCount() int
- func (f *ForkChoice) PreviousJustifiedCheckpoint() *forkchoicetypes.Checkpoint
- func (f *ForkChoice) ProcessAttestation(ctx context.Context, validatorIndices []uint64, blockRoot [32]byte, ...)
- func (f *ForkChoice) ProposerBoost() [fieldparams.RootLength]byte
- func (f *ForkChoice) ReceivedBlocksLastEpoch() (uint64, error)
- func (f *ForkChoice) ResetBoostedProposerRoot(_ context.Context) error
- func (f *ForkChoice) SetGenesisTime(genesisTime uint64)
- func (f *ForkChoice) SetOptimisticToInvalid(ctx context.Context, root, parentRoot, payloadHash [32]byte) ([][32]byte, error)
- func (f *ForkChoice) SetOptimisticToValid(ctx context.Context, root [32]byte) error
- func (f *ForkChoice) SetOriginRoot(root [32]byte)
- func (f *ForkChoice) Tips() ([][32]byte, []types.Slot)
- func (f *ForkChoice) UpdateFinalizedCheckpoint(fc *forkchoicetypes.Checkpoint) error
- func (f *ForkChoice) UpdateJustifiedCheckpoint(jc *forkchoicetypes.Checkpoint) error
- type Node
- type Store
- type Vote
Constants ¶
const NonExistentNode = ^uint64(0)
NonExistentNode defines an unknown node which is used for the array based stateful DAG.
Variables ¶
var ErrUnknownNodeRoot = errors.New("unknown block root")
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 (*ForkChoice) AllTipsAreInvalid ¶
func (f *ForkChoice) AllTipsAreInvalid() bool
AllTipsAreInvalid returns true if no forkchoice tip is viable for head
func (*ForkChoice) AncestorRoot ¶
func (f *ForkChoice) AncestorRoot(ctx context.Context, root [32]byte, slot types.Slot) ([32]byte, error)
AncestorRoot returns the ancestor root of input block root at a given slot.
func (*ForkChoice) BestJustifiedCheckpoint ¶
func (f *ForkChoice) BestJustifiedCheckpoint() *forkchoicetypes.Checkpoint
BestJustifiedCheckpoint of fork choice store.
func (*ForkChoice) CachedHeadRoot ¶
func (f *ForkChoice) CachedHeadRoot() [32]byte
CachedHeadRoot returns the last cached head root
func (*ForkChoice) CommonAncestor ¶ added in v3.1.0
func (f *ForkChoice) CommonAncestor(ctx context.Context, r1 [32]byte, r2 [32]byte) ([32]byte, types.Slot, error)
CommonAncestorRoot returns the common ancestor root between the two block roots r1 and r2.
func (*ForkChoice) FinalizedCheckpoint ¶
func (f *ForkChoice) FinalizedCheckpoint() *forkchoicetypes.Checkpoint
FinalizedCheckpoint of fork choice store.
func (*ForkChoice) FinalizedPayloadBlockHash ¶
func (f *ForkChoice) FinalizedPayloadBlockHash() [32]byte
FinalizedPayloadBlockHash returns the hash of the payload at the finalized checkpoint
func (*ForkChoice) ForkChoiceDump ¶ added in v3.1.0
func (*ForkChoice) ForkChoiceDump(_ context.Context) (*v1.ForkChoiceResponse, error)
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 ¶
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 ¶
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) HighestReceivedBlockSlot ¶
func (f *ForkChoice) HighestReceivedBlockSlot() types.Slot
HighestReceivedBlockSlot returns the highest slot received by the forkchoice
func (*ForkChoice) InsertNode ¶
func (f *ForkChoice) InsertNode(ctx context.Context, state state.BeaconState, root [32]byte) error
InsertNode processes a new block by inserting it to the fork choice store.
func (*ForkChoice) InsertOptimisticChain ¶
func (f *ForkChoice) InsertOptimisticChain(ctx context.Context, chain []*forkchoicetypes.BlockAndCheckpoints) error
InsertOptimisticChain inserts all nodes corresponding to blocks in the slice `blocks`. It includes all blocks **except** the first one.
func (*ForkChoice) InsertSlashedIndex ¶
func (f *ForkChoice) InsertSlashedIndex(ctx context.Context, index types.ValidatorIndex)
InsertSlashedIndex adds the given slashed validator index to the store-tracked list. Votes from these validators are not accounted for in forkchoice.
func (*ForkChoice) IsCanonical ¶
func (f *ForkChoice) IsCanonical(root [32]byte) bool
IsCanonical returns true if the given root is part of the canonical chain.
func (*ForkChoice) IsOptimistic ¶
func (f *ForkChoice) IsOptimistic(root [32]byte) (bool, error)
IsOptimistic returns true if this node is optimistically synced A optimistically synced block is synced as usual, but its execution payload is not validated, while the EL is still syncing. This function returns an error if the block is not found in the fork choice store
func (*ForkChoice) JustifiedCheckpoint ¶
func (f *ForkChoice) JustifiedCheckpoint() *forkchoicetypes.Checkpoint
JustifiedCheckpoint of fork choice store.
func (*ForkChoice) JustifiedPayloadBlockHash ¶
func (f *ForkChoice) JustifiedPayloadBlockHash() [32]byte
JustifiedPayloadBlockHash returns the hash of the payload at the justified checkpoint
func (*ForkChoice) NewSlot ¶
NewSlot mimics the implementation of `on_tick` in fork choice consensus spec. It resets the proposer boost root in fork choice, and it updates store's justified checkpoint if a better checkpoint on the store's finalized checkpoint chain. This should only be called at the start of every slot interval.
Spec pseudocode definition:
# Reset store.proposer_boost_root if this is a new slot if current_slot > previous_slot: store.proposer_boost_root = Root() # Not a new epoch, return if not (current_slot > previous_slot and compute_slots_since_epoch_start(current_slot) == 0): return # Update store.justified_checkpoint if a better checkpoint on the store.finalized_checkpoint chain if store.best_justified_checkpoint.epoch > store.justified_checkpoint.epoch: finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) ancestor_at_finalized_slot = get_ancestor(store, store.best_justified_checkpoint.root, finalized_slot) if ancestor_at_finalized_slot == store.finalized_checkpoint.root: store.justified_checkpoint = store.best_justified_checkpoint
func (*ForkChoice) NodeCount ¶
func (f *ForkChoice) NodeCount() int
NodeCount returns the current number of nodes in the Store
func (*ForkChoice) PreviousJustifiedCheckpoint ¶
func (f *ForkChoice) PreviousJustifiedCheckpoint() *forkchoicetypes.Checkpoint
PreviousJustifiedCheckpoint of fork choice store.
func (*ForkChoice) ProcessAttestation ¶
func (f *ForkChoice) ProcessAttestation(ctx context.Context, validatorIndices []uint64, blockRoot [32]byte, targetEpoch types.Epoch)
ProcessAttestation processes attestation for vote accounting, it iterates around validator indices and update their votes accordingly.
func (*ForkChoice) ProposerBoost ¶
func (f *ForkChoice) ProposerBoost() [fieldparams.RootLength]byte
ProposerBoost returns the proposerBoost of the store
func (*ForkChoice) ReceivedBlocksLastEpoch ¶
func (f *ForkChoice) ReceivedBlocksLastEpoch() (uint64, error)
ReceivedBlocksLastEpoch returns the number of blocks received in the last epoch
func (*ForkChoice) ResetBoostedProposerRoot ¶
func (f *ForkChoice) ResetBoostedProposerRoot(_ context.Context) error
ResetBoostedProposerRoot sets the value of the proposer boosted root to zeros.
func (*ForkChoice) SetGenesisTime ¶
func (f *ForkChoice) SetGenesisTime(genesisTime uint64)
SetGenesisTime sets the genesisTime tracked by forkchoice
func (*ForkChoice) SetOptimisticToInvalid ¶
func (f *ForkChoice) SetOptimisticToInvalid(ctx context.Context, root, parentRoot, payloadHash [32]byte) ([][32]byte, error)
SetOptimisticToInvalid updates the synced_tips map when the block with the given root becomes INVALID. It takes three parameters: the root of the INVALID block, its parent root and the payload Hash of the last valid block
func (*ForkChoice) SetOptimisticToValid ¶
func (f *ForkChoice) SetOptimisticToValid(ctx context.Context, root [32]byte) error
SetOptimisticToValid is called with the root of a block that was returned as VALID by the EL.
WARNING: This method returns an error if the root is not found in forkchoice
func (*ForkChoice) SetOriginRoot ¶
func (f *ForkChoice) SetOriginRoot(root [32]byte)
SetOriginRoot sets the genesis block root
func (*ForkChoice) Tips ¶
func (f *ForkChoice) Tips() ([][32]byte, []types.Slot)
Tips returns all possible chain heads (leaves of fork choice tree). Heads roots and heads slots are returned.
func (*ForkChoice) UpdateFinalizedCheckpoint ¶
func (f *ForkChoice) UpdateFinalizedCheckpoint(fc *forkchoicetypes.Checkpoint) error
UpdateFinalizedCheckpoint sets the finalized checkpoint to the given one
func (*ForkChoice) UpdateJustifiedCheckpoint ¶
func (f *ForkChoice) UpdateJustifiedCheckpoint(jc *forkchoicetypes.Checkpoint) error
UpdateJustifiedCheckpoint sets the justified checkpoint to the given one
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 ¶
BestDescendant of the fork choice node.
func (*Node) FinalizedEpoch ¶
FinalizedEpoch of the fork choice node.
func (*Node) JustifiedEpoch ¶
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) PruneThreshold ¶
PruneThreshold of fork choice store.