github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/rpc/prysm/v1alpha1/debug/forkchoice.go (about) 1 package debug 2 3 import ( 4 "context" 5 "encoding/hex" 6 7 "github.com/golang/protobuf/ptypes/empty" 8 pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" 9 ) 10 11 // GetProtoArrayForkChoice returns proto array fork choice store. 12 func (ds *Server) GetProtoArrayForkChoice(_ context.Context, _ *empty.Empty) (*pbrpc.ProtoArrayForkChoiceResponse, error) { 13 store := ds.HeadFetcher.ProtoArrayStore() 14 15 nodes := store.Nodes() 16 returnedNodes := make([]*pbrpc.ProtoArrayNode, len(nodes)) 17 18 for i := 0; i < len(returnedNodes); i++ { 19 r := nodes[i].Root() 20 returnedNodes[i] = &pbrpc.ProtoArrayNode{ 21 Slot: nodes[i].Slot(), 22 Root: r[:], 23 Parent: nodes[i].Parent(), 24 JustifiedEpoch: nodes[i].JustifiedEpoch(), 25 FinalizedEpoch: nodes[i].FinalizedEpoch(), 26 Weight: nodes[i].Weight(), 27 BestChild: nodes[i].BestChild(), 28 BestDescendant: nodes[i].BestDescendant(), 29 } 30 } 31 32 indices := make(map[string]uint64, len(store.NodesIndices())) 33 for k, v := range store.NodesIndices() { 34 indices[hex.EncodeToString(k[:])] = v 35 } 36 37 return &pbrpc.ProtoArrayForkChoiceResponse{ 38 PruneThreshold: store.PruneThreshold(), 39 JustifiedEpoch: store.JustifiedEpoch(), 40 FinalizedEpoch: store.FinalizedEpoch(), 41 ProtoArrayNodes: returnedNodes, 42 Indices: indices, 43 }, nil 44 }