github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/forkchoice/protoarray/types.go (about)

     1  package protoarray
     2  
     3  import (
     4  	"sync"
     5  
     6  	types "github.com/prysmaticlabs/eth2-types"
     7  )
     8  
     9  // ForkChoice defines the overall fork choice store which includes all block nodes, validator's latest votes and balances.
    10  type ForkChoice struct {
    11  	store     *Store
    12  	votes     []Vote // tracks individual validator's last vote.
    13  	votesLock sync.RWMutex
    14  	balances  []uint64 // tracks individual validator's last justified balances.
    15  }
    16  
    17  // Store defines the fork choice store which includes block nodes and the last view of checkpoint information.
    18  type Store struct {
    19  	pruneThreshold uint64              // do not prune tree unless threshold is reached.
    20  	justifiedEpoch types.Epoch         // latest justified epoch in store.
    21  	finalizedEpoch types.Epoch         // latest finalized epoch in store.
    22  	finalizedRoot  [32]byte            // latest finalized root in store.
    23  	nodes          []*Node             // list of block nodes, each node is a representation of one block.
    24  	nodesIndices   map[[32]byte]uint64 // the root of block node and the nodes index in the list.
    25  	canonicalNodes map[[32]byte]bool   // the canonical block nodes.
    26  	nodesLock      sync.RWMutex
    27  }
    28  
    29  // Node defines the individual block which includes its block parent, ancestor and how much weight accounted for it.
    30  // This is used as an array based stateful DAG for efficient fork choice look up.
    31  type Node struct {
    32  	slot           types.Slot  // slot of the block converted to the node.
    33  	root           [32]byte    // root of the block converted to the node.
    34  	parent         uint64      // parent index of this node.
    35  	justifiedEpoch types.Epoch // justifiedEpoch of this node.
    36  	finalizedEpoch types.Epoch // finalizedEpoch of this node.
    37  	weight         uint64      // weight of this node.
    38  	bestChild      uint64      // bestChild index of this node.
    39  	bestDescendant uint64      // bestDescendant of this node.
    40  	graffiti       [32]byte    // graffiti of the block node.
    41  }
    42  
    43  // Vote defines an individual validator's vote.
    44  type Vote struct {
    45  	currentRoot [32]byte    // current voting root.
    46  	nextRoot    [32]byte    // next voting root.
    47  	nextEpoch   types.Epoch // epoch of next voting period.
    48  }
    49  
    50  // NonExistentNode defines an unknown node which is used for the array based stateful DAG.
    51  const NonExistentNode = ^uint64(0)