Skip to content

Commit

Permalink
Part 2 of proto array fork choice - proto array types (#4616)
Browse files Browse the repository at this point in the history
* Docs

* Interface definitions

* Fmt and gazelle

* Rename interface to interfaces

* Define all the type for protoarray

* Gaz
  • Loading branch information
terencechain authored and 0xKiwi committed Jan 22, 2020
1 parent 8d889f1 commit c041403
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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)

0 comments on commit c041403

Please sign in to comment.