Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part 2 of proto array fork choice - proto array types (#4616)
* Docs * Interface definitions * Fmt and gazelle * Rename interface to interfaces * Define all the type for protoarray * Gaz
- Loading branch information
1 parent
8d889f1
commit c041403
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |