From 314bc513af5afa2f248e590b58c2946f8a3d70db Mon Sep 17 00:00:00 2001 From: terence tsao Date: Fri, 30 Aug 2019 13:50:21 -0700 Subject: [PATCH] Fixed validator pubkey -> index getter (#3361) --- beacon-chain/db/kv/validators.go | 9 ++------- beacon-chain/rpc/beacon_chain_server.go | 4 ++-- beacon-chain/rpc/validator_server.go | 6 +++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/beacon-chain/db/kv/validators.go b/beacon-chain/db/kv/validators.go index a7d0e7c84..be7b4d770 100644 --- a/beacon-chain/db/kv/validators.go +++ b/beacon-chain/db/kv/validators.go @@ -1,7 +1,6 @@ package kv import ( - "bytes" "context" "encoding/binary" "time" @@ -99,12 +98,8 @@ func (k *Store) ValidatorIndex(ctx context.Context, publicKey [48]byte) (uint64, if enc == nil { return nil } - var err error - buf := bytes.NewBuffer(enc) - validatorIdx, err = binary.ReadUvarint(buf) - if err != nil { - return err - } + validatorIdx = binary.LittleEndian.Uint64(enc) + ok = true return nil }) diff --git a/beacon-chain/rpc/beacon_chain_server.go b/beacon-chain/rpc/beacon_chain_server.go index b1c7b56be..f5c8c4670 100644 --- a/beacon-chain/rpc/beacon_chain_server.go +++ b/beacon-chain/rpc/beacon_chain_server.go @@ -279,7 +279,7 @@ func (bs *BeaconChainServer) ListValidatorBalances( return nil, status.Errorf(codes.Internal, "could not retrieve validator index: %v", err) } if !ok { - return nil, status.Errorf(codes.Internal, "could validator index for public key %#x not found", pubKey) + return nil, status.Errorf(codes.Internal, "could not find validator index for public key %#x not found", pubKey) } } @@ -400,7 +400,7 @@ func (bs *BeaconChainServer) ListValidatorAssignments( return nil, status.Errorf(codes.Internal, "could not retrieve validator index: %v", err) } if !ok { - return nil, status.Errorf(codes.Internal, "could validator index for public key %#x not found", pubKey) + return nil, status.Errorf(codes.Internal, "could not find validator index for public key %#x not found", pubKey) } } diff --git a/beacon-chain/rpc/validator_server.go b/beacon-chain/rpc/validator_server.go index 344f99da4..e62c64e06 100644 --- a/beacon-chain/rpc/validator_server.go +++ b/beacon-chain/rpc/validator_server.go @@ -95,7 +95,7 @@ func (vs *ValidatorServer) ValidatorIndex(ctx context.Context, req *pb.Validator return nil, status.Errorf(codes.Internal, "could not retrieve validator index: %v", err) } if !ok { - return nil, status.Errorf(codes.Internal, "could validator index for public key %#x not found", req.PublicKey) + return nil, status.Errorf(codes.Internal, "could not find validator index for public key %#x not found", req.PublicKey) } } return &pb.ValidatorIndexResponse{Index: uint64(index)}, nil @@ -125,7 +125,7 @@ func (vs *ValidatorServer) ValidatorPerformance( return nil, status.Errorf(codes.Internal, "could not retrieve validator index: %v", err) } if !ok { - return nil, status.Errorf(codes.Internal, "could validator index for public key %#x not found", req.PublicKey) + return nil, status.Errorf(codes.Internal, "could not find validator index for public key %#x not found", req.PublicKey) } headState = vs.chainService.(blockchain.HeadRetriever).HeadState() @@ -238,7 +238,7 @@ func (vs *ValidatorServer) assignment( return nil, status.Errorf(codes.Internal, "could not retrieve validator index: %v", err) } if !ok { - return nil, status.Errorf(codes.Internal, "could validator index for public key %#x not found", pubkey) + return nil, status.Errorf(codes.Internal, "could not find validator index for public key %#x not found", pubkey) } }