2021-02-22 22:48:49 +00:00
|
|
|
package debugv1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
ptypes "github.com/gogo/protobuf/types"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1"
|
2021-04-14 17:01:24 +00:00
|
|
|
"go.opencensus.io/trace"
|
2021-03-29 21:04:35 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2021-02-22 22:48:49 +00:00
|
|
|
)
|
|
|
|
|
2021-03-29 21:04:35 +00:00
|
|
|
// GetBeaconState returns the full beacon state for a given state id.
|
|
|
|
func (ds *Server) GetBeaconState(ctx context.Context, req *ethpb.StateRequest) (*ethpb.BeaconStateResponse, error) {
|
|
|
|
state, err := ds.StateFetcher.State(ctx, req.StateId)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.Internal, "could not get state: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
protoState, err := state.ToProto()
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.Internal, "could not convert state to proto: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ðpb.BeaconStateResponse{
|
|
|
|
Data: protoState,
|
|
|
|
}, nil
|
2021-02-22 22:48:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 21:04:35 +00:00
|
|
|
// ListForkChoiceHeads retrieves the fork choice leaves for the current head.
|
|
|
|
func (ds *Server) ListForkChoiceHeads(ctx context.Context, _ *ptypes.Empty) (*ethpb.ForkChoiceHeadsResponse, error) {
|
2021-04-14 17:01:24 +00:00
|
|
|
ctx, span := trace.StartSpan(ctx, "debugv1.ListForkChoiceHeads")
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
headRoots, headSlots := ds.HeadFetcher.ChainHeads()
|
|
|
|
resp := ðpb.ForkChoiceHeadsResponse{
|
|
|
|
Data: make([]*ethpb.ForkChoiceHead, len(headRoots)),
|
|
|
|
}
|
|
|
|
for i := range headRoots {
|
|
|
|
resp.Data[i] = ðpb.ForkChoiceHead{
|
|
|
|
Root: headRoots[i][:],
|
|
|
|
Slot: headSlots[i],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
2021-02-22 22:48:49 +00:00
|
|
|
}
|