Improve Validator Index RPC Error Handling (#11363)

* adding in nil check for head

* adding changes based on feedback

* Update beacon-chain/rpc/prysm/v1alpha1/validator/server_test.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
james-prysm 2022-08-31 11:42:49 -05:00 committed by GitHub
parent 9729b2ec77
commit 52d48b328f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -123,6 +123,9 @@ func (vs *Server) ValidatorIndex(ctx context.Context, req *ethpb.ValidatorIndexR
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not determine head state: %v", err)
}
if st == nil || st.IsNil() {
return nil, status.Errorf(codes.Internal, "head state is empty")
}
index, ok := st.ValidatorIndexByPubkey(bytesutil.ToBytes48(req.PublicKey))
if !ok {
return nil, status.Errorf(codes.NotFound, "Could not find validator index for public key %#x", req.PublicKey)

View File

@ -48,6 +48,18 @@ func TestValidatorIndex_OK(t *testing.T) {
assert.NoError(t, err, "Could not get validator index")
}
func TestValidatorIndex_StateEmpty(t *testing.T) {
Server := &Server{
HeadFetcher: &mockChain.ChainService{},
}
pubKey := pubKey(1)
req := &ethpb.ValidatorIndexRequest{
PublicKey: pubKey,
}
_, err := Server.ValidatorIndex(context.Background(), req)
assert.ErrorContains(t, "head state is empty", err)
}
func TestWaitForActivation_ContextClosed(t *testing.T) {
beaconState, err := v1.InitializeFromProto(&ethpb.BeaconState{
Slot: 0,