2020-05-26 23:24:38 +00:00
|
|
|
package debug
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
|
|
|
|
2021-03-12 00:03:19 +00:00
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
2020-05-26 23:24:38 +00:00
|
|
|
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetProtoArrayForkChoice returns proto array fork choice store.
|
2021-03-12 00:03:19 +00:00
|
|
|
func (ds *Server) GetProtoArrayForkChoice(_ context.Context, _ *empty.Empty) (*pbrpc.ProtoArrayForkChoiceResponse, error) {
|
2020-05-26 23:24:38 +00:00
|
|
|
store := ds.HeadFetcher.ProtoArrayStore()
|
|
|
|
|
2020-08-08 01:37:08 +00:00
|
|
|
nodes := store.Nodes()
|
2020-05-26 23:24:38 +00:00
|
|
|
returnedNodes := make([]*pbrpc.ProtoArrayNode, len(nodes))
|
|
|
|
|
|
|
|
for i := 0; i < len(returnedNodes); i++ {
|
2020-08-08 01:37:08 +00:00
|
|
|
r := nodes[i].Root()
|
2020-05-26 23:24:38 +00:00
|
|
|
returnedNodes[i] = &pbrpc.ProtoArrayNode{
|
2020-08-08 01:37:08 +00:00
|
|
|
Slot: nodes[i].Slot(),
|
|
|
|
Root: r[:],
|
|
|
|
Parent: nodes[i].Parent(),
|
|
|
|
JustifiedEpoch: nodes[i].JustifiedEpoch(),
|
|
|
|
FinalizedEpoch: nodes[i].FinalizedEpoch(),
|
|
|
|
Weight: nodes[i].Weight(),
|
|
|
|
BestChild: nodes[i].BestChild(),
|
|
|
|
BestDescendant: nodes[i].BestDescendant(),
|
2020-05-26 23:24:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-08 01:37:08 +00:00
|
|
|
indices := make(map[string]uint64, len(store.NodesIndices()))
|
|
|
|
for k, v := range store.NodesIndices() {
|
2020-05-26 23:24:38 +00:00
|
|
|
indices[hex.EncodeToString(k[:])] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pbrpc.ProtoArrayForkChoiceResponse{
|
2020-08-08 01:37:08 +00:00
|
|
|
PruneThreshold: store.PruneThreshold(),
|
|
|
|
JustifiedEpoch: store.JustifiedEpoch(),
|
|
|
|
FinalizedEpoch: store.FinalizedEpoch(),
|
2020-05-26 23:24:38 +00:00
|
|
|
ProtoArrayNodes: returnedNodes,
|
|
|
|
Indices: indices,
|
|
|
|
}, nil
|
|
|
|
}
|