One more validator client cleanup (#14048)

* interface names

* interface method names

* inspection

* regenerate pb and mock

* Revert beacon node changes

* build fix

* review

* more functions

* combine parameters
This commit is contained in:
Radosław Kapka
2024-06-01 00:53:58 +09:00
committed by GitHub
parent 836d369c6c
commit 3ab759e163
98 changed files with 1085 additions and 1106 deletions

View File

@@ -253,7 +253,7 @@ func TestServer_VoluntaryExit(t *testing.T) {
}
mockNodeClient.EXPECT().
GetGenesis(gomock.Any(), gomock.Any()).
Genesis(gomock.Any(), gomock.Any()).
Return(&ethpb.Genesis{GenesisTime: genesisTime}, nil)
mockValidatorClient.EXPECT().

View File

@@ -25,7 +25,7 @@ import (
func (s *Server) GetBeaconStatus(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(r.Context(), "validator.web.beacon.GetBeaconStatus")
defer span.End()
syncStatus, err := s.nodeClient.GetSyncStatus(ctx, &emptypb.Empty{})
syncStatus, err := s.nodeClient.SyncStatus(ctx, &emptypb.Empty{})
if err != nil {
log.WithError(err).Error("beacon node call to get sync status failed")
httputil.WriteJson(w, &BeaconStatusResponse{
@@ -35,16 +35,16 @@ func (s *Server) GetBeaconStatus(w http.ResponseWriter, r *http.Request) {
})
return
}
genesis, err := s.nodeClient.GetGenesis(ctx, &emptypb.Empty{})
genesis, err := s.nodeClient.Genesis(ctx, &emptypb.Empty{})
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "GetGenesis call failed").Error(), http.StatusInternalServerError)
httputil.HandleError(w, errors.Wrap(err, "Genesis call failed").Error(), http.StatusInternalServerError)
return
}
genesisTime := uint64(time.Unix(genesis.GenesisTime.Seconds, 0).Unix())
address := genesis.DepositContractAddress
chainHead, err := s.chainClient.GetChainHead(ctx, &emptypb.Empty{})
chainHead, err := s.chainClient.ChainHead(ctx, &emptypb.Empty{})
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "GetChainHead").Error(), http.StatusInternalServerError)
httputil.HandleError(w, errors.Wrap(err, "ChainHead").Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &BeaconStatusResponse{
@@ -59,7 +59,7 @@ func (s *Server) GetBeaconStatus(w http.ResponseWriter, r *http.Request) {
// GetValidatorPerformance is a wrapper around the /eth/v1alpha1 endpoint of the same name.
func (s *Server) GetValidatorPerformance(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(r.Context(), "validator.web.beacon.GetValidatorPerformance")
ctx, span := trace.StartSpan(r.Context(), "validator.web.beacon.ValidatorPerformance")
defer span.End()
publicKeys := r.URL.Query()["public_keys"]
pubkeys := make([][]byte, len(publicKeys))
@@ -85,9 +85,9 @@ func (s *Server) GetValidatorPerformance(w http.ResponseWriter, r *http.Request)
req := &ethpb.ValidatorPerformanceRequest{
PublicKeys: pubkeys,
}
validatorPerformance, err := s.chainClient.GetValidatorPerformance(ctx, req)
validatorPerformance, err := s.chainClient.ValidatorPerformance(ctx, req)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "GetValidatorPerformance call failed").Error(), http.StatusInternalServerError)
httputil.HandleError(w, errors.Wrap(err, "ValidatorPerformance call failed").Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, ValidatorPerformanceResponseFromConsensus(validatorPerformance))
@@ -133,9 +133,9 @@ func (s *Server) GetValidatorBalances(w http.ResponseWriter, r *http.Request) {
PageSize: int32(ps),
PageToken: pageToken,
}
listValidatorBalances, err := s.chainClient.ListValidatorBalances(ctx, req)
listValidatorBalances, err := s.chainClient.ValidatorBalances(ctx, req)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "ListValidatorBalances call failed").Error(), http.StatusInternalServerError)
httputil.HandleError(w, errors.Wrap(err, "ValidatorBalances call failed").Error(), http.StatusInternalServerError)
return
}
response, err := ValidatorBalancesResponseFromConsensus(listValidatorBalances)
@@ -187,9 +187,9 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
PageSize: int32(ps),
PageToken: pageToken,
}
validators, err := s.chainClient.ListValidators(ctx, req)
validators, err := s.chainClient.Validators(ctx, req)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "ListValidators call failed").Error(), http.StatusInternalServerError)
httputil.HandleError(w, errors.Wrap(err, "Validators call failed").Error(), http.StatusInternalServerError)
return
}
response, err := ValidatorsResponseFromConsensus(validators)
@@ -204,9 +204,9 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
func (s *Server) GetPeers(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(r.Context(), "validator.web.beacon.GetPeers")
defer span.End()
peers, err := s.nodeClient.ListPeers(ctx, &emptypb.Empty{})
peers, err := s.nodeClient.Peers(ctx, &emptypb.Empty{})
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "ListPeers call failed").Error(), http.StatusInternalServerError)
httputil.HandleError(w, errors.Wrap(err, "Peers call failed").Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, peers)

View File

@@ -22,7 +22,7 @@ import (
func TestGetBeaconStatus_NotConnected(t *testing.T) {
ctrl := gomock.NewController(t)
nodeClient := validatormock.NewMockNodeClient(ctrl)
nodeClient.EXPECT().GetSyncStatus(
nodeClient.EXPECT().SyncStatus(
gomock.Any(), // ctx
gomock.Any(),
).Return(nil /*response*/, errors.New("uh oh"))
@@ -48,12 +48,12 @@ func TestGetBeaconStatus_OK(t *testing.T) {
ctrl := gomock.NewController(t)
nodeClient := validatormock.NewMockNodeClient(ctrl)
chainClient := validatormock.NewMockChainClient(ctrl)
nodeClient.EXPECT().GetSyncStatus(
nodeClient.EXPECT().SyncStatus(
gomock.Any(), // ctx
gomock.Any(),
).Return(&ethpb.SyncStatus{Syncing: true}, nil)
timeStamp := timestamppb.New(time.Unix(0, 0))
nodeClient.EXPECT().GetGenesis(
nodeClient.EXPECT().Genesis(
gomock.Any(), // ctx
gomock.Any(),
).Return(&ethpb.Genesis{

View File

@@ -15,10 +15,10 @@ import (
// GetVersion returns the beacon node and validator client versions
func (s *Server) GetVersion(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(r.Context(), "validator.web.health.GetVersion")
ctx, span := trace.StartSpan(r.Context(), "validator.web.health.Version")
defer span.End()
beacon, err := s.nodeClient.GetVersion(ctx, &emptypb.Empty{})
beacon, err := s.nodeClient.Version(ctx, &emptypb.Empty{})
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
return

View File

@@ -173,7 +173,7 @@ func TestServer_GetVersion(t *testing.T) {
ctx: ctx,
nodeClient: mockNodeClient,
}
mockNodeClient.EXPECT().GetVersion(gomock.Any(), gomock.Any()).Return(&eth.Version{
mockNodeClient.EXPECT().Version(gomock.Any(), gomock.Any()).Return(&eth.Version{
Version: "4.10.1",
Metadata: "beacon node",
}, nil)

View File

@@ -347,7 +347,7 @@ func (s *Server) SetVoluntaryExit(w http.ResponseWriter, r *http.Request) {
epoch := primitives.Epoch(e)
if rawEpoch == "" {
genesisResponse, err := s.nodeClient.GetGenesis(ctx, &emptypb.Empty{})
genesisResponse, err := s.nodeClient.Genesis(ctx, &emptypb.Empty{})
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "Failed to get genesis time").Error(), http.StatusInternalServerError)
return
@@ -842,7 +842,7 @@ func (s *Server) DeleteGasLimit(w http.ResponseWriter, r *http.Request) {
}
func (s *Server) GetGraffiti(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(r.Context(), "validator.keymanagerAPI.GetGraffiti")
ctx, span := trace.StartSpan(r.Context(), "validator.keymanagerAPI.Graffiti")
defer span.End()
if s.validatorService == nil {
@@ -854,7 +854,7 @@ func (s *Server) GetGraffiti(w http.ResponseWriter, r *http.Request) {
return
}
graffiti, err := s.validatorService.GetGraffiti(ctx, bytesutil.ToBytes48(pubkey))
graffiti, err := s.validatorService.Graffiti(ctx, bytesutil.ToBytes48(pubkey))
if err != nil {
if strings.Contains(err.Error(), "unavailable") {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)

View File

@@ -738,7 +738,7 @@ func TestServer_SetVoluntaryExit(t *testing.T) {
Return(&eth.DomainResponse{SignatureDomain: make([]byte, common.HashLength)}, nil /*err*/)
mockNodeClient.EXPECT().
GetGenesis(gomock.Any(), gomock.Any()).
Genesis(gomock.Any(), gomock.Any()).
Times(3).
Return(&eth.Genesis{GenesisTime: genesisTime}, nil)
@@ -841,7 +841,7 @@ func TestServer_SetVoluntaryExit(t *testing.T) {
resp := &SetVoluntaryExitResponse{}
require.NoError(t, json.Unmarshal(w.Body.Bytes(), resp))
if tt.w.epoch == 0 {
genesisResponse, err := s.nodeClient.GetGenesis(ctx, &emptypb.Empty{})
genesisResponse, err := s.nodeClient.Genesis(ctx, &emptypb.Empty{})
require.NoError(t, err)
tt.w.epoch, err = client.CurrentEpoch(genesisResponse.GenesisTime)
require.NoError(t, err)
@@ -1102,7 +1102,7 @@ func TestServer_SetGasLimit(t *testing.T) {
}
if tt.beaconReturn != nil {
beaconClient.EXPECT().GetFeeRecipientByPubKey(
beaconClient.EXPECT().FeeRecipientByPubKey(
gomock.Any(),
gomock.Any(),
).Return(tt.beaconReturn.resp, tt.beaconReturn.error)