Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tracing in the validator client #14125

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions validator/client/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot primitives

// Signs input slot with domain selection proof. This is used to create the signature for aggregator selection.
func (v *validator) signSlotWithSelectionProof(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, slot primitives.Slot) (signature []byte, err error) {
ctx, span := trace.StartSpan(ctx, "validator.signSlotWithSelectionProof")
defer span.End()

domain, err := v.domainData(ctx, slots.ToEpoch(slot), params.BeaconConfig().DomainSelectionProof[:])
if err != nil {
return nil, err
Expand Down Expand Up @@ -194,6 +197,9 @@ func (v *validator) waitToSlotTwoThirds(ctx context.Context, slot primitives.Slo
// This returns the signature of validator signing over aggregate and
// proof object.
func (v *validator) aggregateAndProofSig(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, agg *ethpb.AggregateAttestationAndProof, slot primitives.Slot) ([]byte, error) {
ctx, span := trace.StartSpan(ctx, "validator.aggregateAndProofSig")
defer span.End()

d, err := v.domainData(ctx, slots.ToEpoch(agg.Aggregate.Data.Slot), params.BeaconConfig().DomainAggregateAndProof[:])
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions validator/client/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ func (v *validator) duty(pubKey [fieldparams.BLSPubkeyLength]byte) (*ethpb.Dutie

// Given validator's public key, this function returns the signature of an attestation data and its signing root.
func (v *validator) signAtt(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, data *ethpb.AttestationData, slot primitives.Slot) ([]byte, [32]byte, error) {
ctx, span := trace.StartSpan(ctx, "validator.signAtt")
defer span.End()

domain, root, err := v.domainAndSigningRoot(ctx, data)
if err != nil {
return nil, [32]byte{}, err
Expand Down
1 change: 1 addition & 0 deletions validator/client/beacon-api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ go_library(
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_opencensus_go//trace:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
"@org_golang_x_sync//errgroup:go_default_library",
Expand Down
8 changes: 4 additions & 4 deletions validator/client/beacon-api/activation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestActivation_Nominal(t *testing.T) {

// Get does not return any result for non existing key
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
"/eth/v1/beacon/states/head/validators",
nil,
bytes.NewBuffer(reqBytes),
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestActivation_InvalidData(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestActivation_JsonResponseError(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -291,7 +291,7 @@ func TestActivation_JsonResponseError(t *testing.T) {
).Times(1)

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
gomock.Any(),
gomock.Any(),
).Return(
Expand Down
6 changes: 3 additions & 3 deletions validator/client/beacon-api/attestation_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestGetAttestationData_ValidAttestation(t *testing.T) {
produceAttestationDataResponseJson := structs.GetAttestationDataResponse{}

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
fmt.Sprintf("/eth/v1/validator/attestation_data?committee_index=%d&slot=%d", expectedCommitteeIndex, expectedSlot),
&produceAttestationDataResponseJson,
).Return(
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestGetAttestationData_InvalidData(t *testing.T) {
produceAttestationDataResponseJson := structs.GetAttestationDataResponse{}
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
"/eth/v1/validator/attestation_data?committee_index=2&slot=1",
&produceAttestationDataResponseJson,
).Return(
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestGetAttestationData_JsonResponseError(t *testing.T) {
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
produceAttestationDataResponseJson := structs.GetAttestationDataResponse{}
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
fmt.Sprintf("/eth/v1/validator/attestation_data?committee_index=%d&slot=%d", committeeIndex, slot),
&produceAttestationDataResponseJson,
).Return(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
errors.New("foo error"),
)
Expand All @@ -78,7 +78,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
errors.New("bar error"),
)
Expand All @@ -96,7 +96,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForHead(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForHead(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
errors.New("foo error"),
)
Expand All @@ -114,13 +114,13 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForHead(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForHead(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
nil,
)

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(ctx, blockHeaderEndpoint, gomock.Any()).Return(errors.New("bar error"))
jsonRestHandler.EXPECT().Get(gomock.Any(), blockHeaderEndpoint, gomock.Any()).Return(errors.New("bar error"))

beaconChainClient := beaconApiChainClient{
stateValidatorsProvider: stateValidatorsProvider,
Expand Down Expand Up @@ -187,13 +187,13 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForHead(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForHead(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
nil,
)

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(ctx, blockHeaderEndpoint, gomock.Any()).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), blockHeaderEndpoint, gomock.Any()).Return(
nil,
).SetArg(
2,
Expand Down Expand Up @@ -328,7 +328,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
testCase.generateStateValidatorsResponse(),
nil,
)
Expand Down Expand Up @@ -556,7 +556,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(ctx, primitives.Slot(0), make([]string, 0), []primitives.ValidatorIndex{}, nil).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(gomock.Any(), primitives.Slot(0), make([]string, 0), []primitives.ValidatorIndex{}, nil).Return(
testCase.generateJsonStateValidatorsResponse(),
nil,
)
Expand Down Expand Up @@ -745,7 +745,7 @@ func TestGetChainHead(t *testing.T) {

finalityCheckpointsResponse := structs.GetFinalityCheckpointsResponse{}
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(ctx, finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
testCase.finalityCheckpointsError,
).SetArg(
2,
Expand Down Expand Up @@ -844,15 +844,15 @@ func TestGetChainHead(t *testing.T) {
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)

finalityCheckpointsResponse := structs.GetFinalityCheckpointsResponse{}
jsonRestHandler.EXPECT().Get(ctx, finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
nil,
).SetArg(
2,
generateValidFinalityCheckpointsResponse(),
)

headBlockHeadersResponse := structs.GetBlockHeaderResponse{}
jsonRestHandler.EXPECT().Get(ctx, headBlockHeadersEndpoint, &headBlockHeadersResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), headBlockHeadersEndpoint, &headBlockHeadersResponse).Return(
testCase.headBlockHeadersError,
).SetArg(
2,
Expand All @@ -874,15 +874,15 @@ func TestGetChainHead(t *testing.T) {
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)

finalityCheckpointsResponse := structs.GetFinalityCheckpointsResponse{}
jsonRestHandler.EXPECT().Get(ctx, finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
nil,
).SetArg(
2,
generateValidFinalityCheckpointsResponse(),
)

headBlockHeadersResponse := structs.GetBlockHeaderResponse{}
jsonRestHandler.EXPECT().Get(ctx, headBlockHeadersEndpoint, &headBlockHeadersResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), headBlockHeadersEndpoint, &headBlockHeadersResponse).Return(
nil,
).SetArg(
2,
Expand Down Expand Up @@ -940,7 +940,7 @@ func Test_beaconApiBeaconChainClient_GetValidatorPerformance(t *testing.T) {
want := &ethpb.ValidatorPerformanceResponse{}
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
getValidatorPerformanceEndpoint,
nil,
bytes.NewBuffer(request),
Expand Down
16 changes: 8 additions & 8 deletions validator/client/beacon-api/beacon_api_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestGetFork_Nominal(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
forkEndpoint,
&stateForkResponseJson,
).Return(
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestGetFork_Invalid(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
forkEndpoint,
gomock.Any(),
).Return(
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestGetHeaders_Nominal(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
headersEndpoint,
&blockHeadersResponseJson,
).Return(
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestGetHeaders_Invalid(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
headersEndpoint,
gomock.Any(),
).Return(
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestGetLiveness_Nominal(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
livenessEndpoint,
nil,
bytes.NewBuffer(marshalledIndexes),
Expand All @@ -275,7 +275,7 @@ func TestGetLiveness_Invalid(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
livenessEndpoint,
nil,
gomock.Any(),
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestGetIsSyncing_Nominal(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
syncingEndpoint,
&syncingResponseJson,
).Return(
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestGetIsSyncing_Invalid(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
syncingEndpoint,
&syncingResponseJson,
).Return(
Expand Down
8 changes: 4 additions & 4 deletions validator/client/beacon-api/beacon_api_node_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestGetGenesis(t *testing.T) {

genesisProvider := mock.NewMockGenesisProvider(ctrl)
genesisProvider.EXPECT().Genesis(
ctx,
gomock.Any(),
).Return(
testCase.genesisResponse,
testCase.genesisError,
Expand All @@ -124,7 +124,7 @@ func TestGetGenesis(t *testing.T) {

if testCase.queriesDepositContract {
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
"/eth/v1/config/deposit_contract",
&depositContractJson,
).Return(
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestGetSyncStatus(t *testing.T) {
syncingResponse := structs.SyncStatusResponse{}
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
syncingEndpoint,
&syncingResponse,
).Return(
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestGetVersion(t *testing.T) {
var versionResponse structs.GetVersionResponse
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
versionEndpoint,
&versionResponse,
).Return(
Expand Down
Loading
Loading