Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part 2 of proto array fork choice - proto array types #4616

Merged
merged 7 commits into from Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion beacon-chain/forkchoice/protoarray/BUILD.bazel
Expand Up @@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["doc.go"],
srcs = [
"doc.go",
"types.go",
],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray",
visibility = ["//beacon-chain:__subpackages__"],
)
44 changes: 44 additions & 0 deletions beacon-chain/forkchoice/protoarray/types.go
@@ -0,0 +1,44 @@
package protoarray

import "sync"

// ForkChoice defines the overall fork choice store which includes all block nodes, validator's latest votes and balances.
type ForkChoice struct {
store *Store
votes []Vote // tracks individual validator's last vote.
balances []uint64 // tracks individual validator's last justified balances.
}

// Store defines the fork choice store which includes block nodes and the last view of checkpoint information.
type Store struct {
pruneThreshold uint64 // do not prune tree unless threshold is reached.
justifiedEpoch uint64 // latest justified epoch in store.
finalizedEpoch uint64 // latest finalized epoch in store.
finalizedRoot [32]byte // latest finalized root in store.
nodes []*Node // list of block nodes, each node is a representation of one block.
nodeIndices map[[32]byte]uint64 // the root of block node and the nodes index in the list.
nodeIndicesLock sync.RWMutex
}

// 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.
type Node struct {
slot uint64 // slot of the block converted to the node.
root [32]byte // root of the block converted to the node.
parent uint64 // the parent index of this node.
justifiedEpoch uint64 // justified epoch of this node.
finalizedEpoch uint64 // finalized epoch of this node.
weight uint64 // weight of this node.
bestChild uint64 // best child index of this node.
bestDescendant uint64 // head index of this node.
}

// Vote defines an individual validator's vote.
type Vote struct {
currentRoot [32]byte // current voting root.
nextRoot [32]byte // next voting root.
nextEpoch uint64 // epoch of next voting period.
}

// This defines an unknown node which is used for the array based stateful DAG.
const nonExistentNode = ^uint64(0)