prysm-pulse/beacon-chain/rpc/debug/forkchoice.go
Preston Van Loon fd80f73286
Improve make() capacity allocations (#6517)
* attestationutil.AttestingIndices: Minor improvement on indices array allocation
* progress
* more progress on makes
* progress
* more progress
* Merge branch 'master' of github.com:prysmaticlabs/prysm into memory1
* gaz
* fmt and imports
* Merge branch 'master' into memory2
* Min()
* remove spaces
* Merge branch 'master' of github.com:prysmaticlabs/prysm into memory2
* revert beacon-chain/operations/attestations/kv/block.go
* partially revert beacon-chain/operations/attestations/kv/aggregated.go
* Merge branch 'master' into memory2
* Merge branch 'master' into memory2
2020-07-09 15:50:58 +00:00

44 lines
1.2 KiB
Go

package debug
import (
"context"
"encoding/hex"
ptypes "github.com/gogo/protobuf/types"
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
)
// GetProtoArrayForkChoice returns proto array fork choice store.
func (ds *Server) GetProtoArrayForkChoice(ctx context.Context, _ *ptypes.Empty) (*pbrpc.ProtoArrayForkChoiceResponse, error) {
store := ds.HeadFetcher.ProtoArrayStore()
nodes := store.Nodes
returnedNodes := make([]*pbrpc.ProtoArrayNode, len(nodes))
for i := 0; i < len(returnedNodes); i++ {
returnedNodes[i] = &pbrpc.ProtoArrayNode{
Slot: nodes[i].Slot,
Root: nodes[i].Root[:],
Parent: nodes[i].Parent,
JustifiedEpoch: nodes[i].JustifiedEpoch,
FinalizedEpoch: nodes[i].FinalizedEpoch,
Weight: nodes[i].Weight,
BestChild: nodes[i].BestChild,
BestDescendant: nodes[i].BestDescendant,
}
}
indices := make(map[string]uint64, len(store.NodeIndices))
for k, v := range store.NodeIndices {
indices[hex.EncodeToString(k[:])] = v
}
return &pbrpc.ProtoArrayForkChoiceResponse{
PruneThreshold: store.PruneThreshold,
JustifiedEpoch: store.JustifiedEpoch,
FinalizedEpoch: store.FinalizedEpoch,
ProtoArrayNodes: returnedNodes,
Indices: indices,
}, nil
}