Skip to content

Commit

Permalink
more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rkapka committed May 30, 2024
1 parent 5e49acc commit 5483aec
Show file tree
Hide file tree
Showing 41 changed files with 236 additions and 236 deletions.
2 changes: 1 addition & 1 deletion validator/accounts/testing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (m *Validator) SetProposerSettings(_ context.Context, settings *proposer.Se
return nil
}

// GetGraffiti for mocking
// Graffiti for mocking
func (m *Validator) Graffiti(_ context.Context, _ [fieldparams.BLSPubkeyLength]byte) ([]byte, error) {
return []byte(m.graffiti), nil
}
Expand Down
2 changes: 1 addition & 1 deletion validator/client/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot primitives

var slotSig []byte
if v.distributed {
slotSig, err = v.getAttSelection(attSelectionKey{slot: slot, index: duty.ValidatorIndex})
slotSig, err = v.attSelection(attSelectionKey{slot: slot, index: duty.ValidatorIndex})
if err != nil {
log.WithError(err).Error("Could not find aggregated selection proof")
if v.emitAccountMetrics {
Expand Down
6 changes: 3 additions & 3 deletions validator/client/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (v *validator) SubmitAttestation(ctx context.Context, slot primitives.Slot,
Data: data,
}

_, signingRoot, err := v.getDomainAndSigningRoot(ctx, indexedAtt.Data)
_, signingRoot, err := v.domainAndSigningRoot(ctx, indexedAtt.Data)
if err != nil {
log.WithError(err).Error("Could not get domain and signing root from attestation")
if v.emitAccountMetrics {
Expand Down Expand Up @@ -199,7 +199,7 @@ 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) {
domain, root, err := v.getDomainAndSigningRoot(ctx, data)
domain, root, err := v.domainAndSigningRoot(ctx, data)
if err != nil {
return nil, [32]byte{}, err
}
Expand All @@ -217,7 +217,7 @@ func (v *validator) signAtt(ctx context.Context, pubKey [fieldparams.BLSPubkeyLe
return sig.Marshal(), root, nil
}

func (v *validator) getDomainAndSigningRoot(ctx context.Context, data *ethpb.AttestationData) (*ethpb.DomainResponse, [32]byte, error) {
func (v *validator) domainAndSigningRoot(ctx context.Context, data *ethpb.AttestationData) (*ethpb.DomainResponse, [32]byte, error) {
domain, err := v.domainData(ctx, data.Target.Epoch, params.BeaconConfig().DomainBeaconAttester[:])
if err != nil {
return nil, [32]byte{}, err
Expand Down
2 changes: 1 addition & 1 deletion validator/client/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func Test_slashableAttestationCheck_UpdatesLowestSignedEpochs(t *testing.T) {
gomock.Any(), // ctx
&ethpb.DomainRequest{Epoch: 10, Domain: []byte{1, 0, 0, 0}},
).Return(&ethpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/)
_, sr, err := validator.getDomainAndSigningRoot(ctx, att.Data)
_, sr, err := validator.domainAndSigningRoot(ctx, att.Data)
require.NoError(t, err)

err = validator.db.SlashableAttestationCheck(context.Background(), att, pubKey, sr, false, nil)
Expand Down
2 changes: 1 addition & 1 deletion validator/client/beacon-api/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *waitForActivationClient) Recv() (*ethpb.ValidatorActivationResponse, er
stringTargetPubKeys[index] = stringPubKey
}

stateValidators, err := c.stateValidatorsProvider.GetStateValidators(c.ctx, stringTargetPubKeys, nil, nil)
stateValidators, err := c.stateValidatorsProvider.StateValidators(c.ctx, stringTargetPubKeys, nil, nil)
if err != nil {
return nil, errors.Wrap(err, "failed to get state validators")
}
Expand Down
2 changes: 1 addition & 1 deletion validator/client/beacon-api/attestation_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)

func (c *beaconApiValidatorClient) getAttestationData(
func (c *beaconApiValidatorClient) attestationData(
ctx context.Context,
reqSlot primitives.Slot,
reqCommitteeIndex primitives.CommitteeIndex,
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 @@ -58,7 +58,7 @@ func TestGetAttestationData_ValidAttestation(t *testing.T) {
).Times(1)

validatorClient := &beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
resp, err := validatorClient.getAttestationData(ctx, primitives.Slot(expectedSlot), primitives.CommitteeIndex(expectedCommitteeIndex))
resp, err := validatorClient.attestationData(ctx, primitives.Slot(expectedSlot), primitives.CommitteeIndex(expectedCommitteeIndex))
assert.NoError(t, err)

require.NotNil(t, resp)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestGetAttestationData_InvalidData(t *testing.T) {
).Times(1)

validatorClient := &beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
_, err := validatorClient.getAttestationData(ctx, 1, 2)
_, err := validatorClient.attestationData(ctx, 1, 2)
assert.ErrorContains(t, testCase.expectedErrorMessage, err)
})
}
Expand All @@ -220,7 +220,7 @@ func TestGetAttestationData_JsonResponseError(t *testing.T) {
).Times(1)

validatorClient := &beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
_, err := validatorClient.getAttestationData(ctx, slot, committeeIndex)
_, err := validatorClient.attestationData(ctx, slot, committeeIndex)
assert.ErrorContains(t, "some specific json response error", err)
}

Expand Down
12 changes: 6 additions & 6 deletions validator/client/beacon-api/beacon_api_beacon_chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type beaconApiChainClient struct {

const getValidatorPerformanceEndpoint = "/prysm/validators/performance"

func (c beaconApiChainClient) getHeadBlockHeaders(ctx context.Context) (*structs.GetBlockHeaderResponse, error) {
func (c beaconApiChainClient) headBlockHeaders(ctx context.Context) (*structs.GetBlockHeaderResponse, error) {
blockHeader := structs.GetBlockHeaderResponse{}
err := c.jsonRestHandler.Get(ctx, "/eth/v1/beacon/headers/head", &blockHeader)
if err != nil {
Expand Down Expand Up @@ -112,7 +112,7 @@ func (c beaconApiChainClient) ChainHead(ctx context.Context, _ *empty.Empty) (*e
return nil, errors.Wrapf(err, "failed to decode previous justified checkpoint root `%s`", finalityCheckpoints.Data.PreviousJustified.Root)
}

blockHeader, err := c.getHeadBlockHeaders(ctx)
blockHeader, err := c.headBlockHeaders(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to get head block headers")
}
Expand Down Expand Up @@ -191,21 +191,21 @@ func (c beaconApiChainClient) Validators(ctx context.Context, in *ethpb.ListVali
if err != nil {
return nil, errors.Wrapf(err, "failed to get first slot for epoch `%d`", queryFilter.Epoch)
}
if stateValidators, err = c.stateValidatorsProvider.GetStateValidatorsForSlot(ctx, slot, pubkeys, in.Indices, statuses); err != nil {
if stateValidators, err = c.stateValidatorsProvider.StateValidatorsForSlot(ctx, slot, pubkeys, in.Indices, statuses); err != nil {
return nil, errors.Wrapf(err, "failed to get state validators for slot `%d`", slot)
}
epoch = slots.ToEpoch(slot)
case *ethpb.ListValidatorsRequest_Genesis:
if stateValidators, err = c.stateValidatorsProvider.GetStateValidatorsForSlot(ctx, 0, pubkeys, in.Indices, statuses); err != nil {
if stateValidators, err = c.stateValidatorsProvider.StateValidatorsForSlot(ctx, 0, pubkeys, in.Indices, statuses); err != nil {
return nil, errors.Wrapf(err, "failed to get genesis state validators")
}
epoch = 0
case nil:
if stateValidators, err = c.stateValidatorsProvider.GetStateValidatorsForHead(ctx, pubkeys, in.Indices, statuses); err != nil {
if stateValidators, err = c.stateValidatorsProvider.StateValidatorsForHead(ctx, pubkeys, in.Indices, statuses); err != nil {
return nil, errors.Wrap(err, "failed to get head state validators")
}

blockHeader, err := c.getHeadBlockHeaders(ctx)
blockHeader, err := c.headBlockHeaders(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to get head block headers")
}
Expand Down
12 changes: 6 additions & 6 deletions validator/client/beacon-api/beacon_api_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func buildURL(path string, queryParams ...neturl.Values) string {
return fmt.Sprintf("%s?%s", path, queryParams[0].Encode())
}

func (c *beaconApiValidatorClient) getFork(ctx context.Context) (*structs.GetStateForkResponse, error) {
func (c *beaconApiValidatorClient) fork(ctx context.Context) (*structs.GetStateForkResponse, error) {
const endpoint = "/eth/v1/beacon/states/head/fork"

stateForkResponseJson := &structs.GetStateForkResponse{}
Expand All @@ -60,7 +60,7 @@ func (c *beaconApiValidatorClient) getFork(ctx context.Context) (*structs.GetSta
return stateForkResponseJson, nil
}

func (c *beaconApiValidatorClient) getHeaders(ctx context.Context) (*structs.GetBlockHeadersResponse, error) {
func (c *beaconApiValidatorClient) headers(ctx context.Context) (*structs.GetBlockHeadersResponse, error) {
const endpoint = "/eth/v1/beacon/headers"

blockHeadersResponseJson := &structs.GetBlockHeadersResponse{}
Expand All @@ -72,7 +72,7 @@ func (c *beaconApiValidatorClient) getHeaders(ctx context.Context) (*structs.Get
return blockHeadersResponseJson, nil
}

func (c *beaconApiValidatorClient) getLiveness(ctx context.Context, epoch primitives.Epoch, validatorIndexes []string) (*structs.GetLivenessResponse, error) {
func (c *beaconApiValidatorClient) liveness(ctx context.Context, epoch primitives.Epoch, validatorIndexes []string) (*structs.GetLivenessResponse, error) {
const endpoint = "/eth/v1/validator/liveness/"
url := endpoint + strconv.FormatUint(uint64(epoch), 10)

Expand All @@ -90,7 +90,7 @@ func (c *beaconApiValidatorClient) getLiveness(ctx context.Context, epoch primit
return livenessResponseJson, nil
}

func (c *beaconApiValidatorClient) getSyncing(ctx context.Context) (*structs.SyncStatusResponse, error) {
func (c *beaconApiValidatorClient) syncing(ctx context.Context) (*structs.SyncStatusResponse, error) {
const endpoint = "/eth/v1/node/syncing"

syncingResponseJson := &structs.SyncStatusResponse{}
Expand All @@ -103,7 +103,7 @@ func (c *beaconApiValidatorClient) getSyncing(ctx context.Context) (*structs.Syn
}

func (c *beaconApiValidatorClient) isSyncing(ctx context.Context) (bool, error) {
response, err := c.getSyncing(ctx)
response, err := c.syncing(ctx)
if err != nil || response == nil || response.Data == nil {
return true, errors.Wrapf(err, "failed to get syncing status")
}
Expand All @@ -112,7 +112,7 @@ func (c *beaconApiValidatorClient) isSyncing(ctx context.Context) (bool, error)
}

func (c *beaconApiValidatorClient) isOptimistic(ctx context.Context) (bool, error) {
response, err := c.getSyncing(ctx)
response, err := c.syncing(ctx)
if err != nil || response == nil || response.Data == nil {
return true, errors.Wrapf(err, "failed to get syncing status")
}
Expand Down
12 changes: 6 additions & 6 deletions validator/client/beacon-api/beacon_api_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestGetFork_Nominal(t *testing.T) {
jsonRestHandler: jsonRestHandler,
}

fork, err := validatorClient.getFork(ctx)
fork, err := validatorClient.fork(ctx)
require.NoError(t, err)
assert.DeepEqual(t, &expected, fork)
}
Expand All @@ -148,7 +148,7 @@ func TestGetFork_Invalid(t *testing.T) {
jsonRestHandler: jsonRestHandler,
}

_, err := validatorClient.getFork(ctx)
_, err := validatorClient.fork(ctx)
require.ErrorContains(t, "custom error", err)
}

Expand Down Expand Up @@ -190,7 +190,7 @@ func TestGetHeaders_Nominal(t *testing.T) {
jsonRestHandler: jsonRestHandler,
}

headers, err := validatorClient.getHeaders(ctx)
headers, err := validatorClient.headers(ctx)
require.NoError(t, err)
assert.DeepEqual(t, &expected, headers)
}
Expand All @@ -215,7 +215,7 @@ func TestGetHeaders_Invalid(t *testing.T) {
jsonRestHandler: jsonRestHandler,
}

_, err := validatorClient.getHeaders(ctx)
_, err := validatorClient.headers(ctx)
require.ErrorContains(t, "custom error", err)
}

Expand Down Expand Up @@ -261,7 +261,7 @@ func TestGetLiveness_Nominal(t *testing.T) {
).Times(1)

validatorClient := &beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
liveness, err := validatorClient.getLiveness(ctx, 42, indexes)
liveness, err := validatorClient.liveness(ctx, 42, indexes)

require.NoError(t, err)
assert.DeepEqual(t, &expected, liveness)
Expand All @@ -285,7 +285,7 @@ func TestGetLiveness_Invalid(t *testing.T) {
).Times(1)

validatorClient := &beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
_, err := validatorClient.getLiveness(ctx, 42, nil)
_, err := validatorClient.liveness(ctx, 42, nil)

require.ErrorContains(t, "custom error", err)
}
Expand Down
2 changes: 1 addition & 1 deletion validator/client/beacon-api/beacon_api_node_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *beaconApiNodeClient) SyncStatus(ctx context.Context, _ *empty.Empty) (*
}

func (c *beaconApiNodeClient) Genesis(ctx context.Context, _ *empty.Empty) (*ethpb.Genesis, error) {
genesisJson, err := c.genesisProvider.GetGenesis(ctx)
genesisJson, err := c.genesisProvider.Genesis(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to get genesis")
}
Expand Down
16 changes: 8 additions & 8 deletions validator/client/beacon-api/beacon_api_validator_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ func (c *beaconApiValidatorClient) DomainData(ctx context.Context, in *ethpb.Dom
domainType := bytesutil.ToBytes4(in.Domain)

return wrapInMetrics[*ethpb.DomainResponse]("DomainData", func() (*ethpb.DomainResponse, error) {
return c.getDomainData(ctx, in.Epoch, domainType)
return c.domainData(ctx, in.Epoch, domainType)
})
}

func (c *beaconApiValidatorClient) AttestationData(ctx context.Context, in *ethpb.AttestationDataRequest) (*ethpb.AttestationData, error) {
return wrapInMetrics[*ethpb.AttestationData]("AttestationData", func() (*ethpb.AttestationData, error) {
return c.getAttestationData(ctx, in.Slot, in.CommitteeIndex)
return c.attestationData(ctx, in.Slot, in.CommitteeIndex)
})
}

func (c *beaconApiValidatorClient) BeaconBlock(ctx context.Context, in *ethpb.BlockRequest) (*ethpb.GenericBeaconBlock, error) {
return wrapInMetrics[*ethpb.GenericBeaconBlock]("BeaconBlock", func() (*ethpb.GenericBeaconBlock, error) {
return c.getBeaconBlock(ctx, in.Slot, in.RandaoReveal, in.Graffiti)
return c.beaconBlock(ctx, in.Slot, in.RandaoReveal, in.Graffiti)
})
}

Expand All @@ -87,19 +87,19 @@ func (c *beaconApiValidatorClient) FeeRecipientByPubKey(_ context.Context, _ *et

func (c *beaconApiValidatorClient) SyncCommitteeContribution(ctx context.Context, in *ethpb.SyncCommitteeContributionRequest) (*ethpb.SyncCommitteeContribution, error) {
return wrapInMetrics[*ethpb.SyncCommitteeContribution]("SyncCommitteeContribution", func() (*ethpb.SyncCommitteeContribution, error) {
return c.getSyncCommitteeContribution(ctx, in)
return c.syncCommitteeContribution(ctx, in)
})
}

func (c *beaconApiValidatorClient) SyncMessageBlockRoot(ctx context.Context, _ *empty.Empty) (*ethpb.SyncMessageBlockRootResponse, error) {
return wrapInMetrics[*ethpb.SyncMessageBlockRootResponse]("SyncMessageBlockRoot", func() (*ethpb.SyncMessageBlockRootResponse, error) {
return c.getSyncMessageBlockRoot(ctx)
return c.syncMessageBlockRoot(ctx)
})
}

func (c *beaconApiValidatorClient) SyncSubcommitteeIndex(ctx context.Context, in *ethpb.SyncSubcommitteeIndexRequest) (*ethpb.SyncSubcommitteeIndexResponse, error) {
return wrapInMetrics[*ethpb.SyncSubcommitteeIndexResponse]("SyncSubcommitteeIndex", func() (*ethpb.SyncSubcommitteeIndexResponse, error) {
return c.getSyncSubcommitteeIndex(ctx, in)
return c.syncSubcommitteeIndex(ctx, in)
})
}

Expand Down Expand Up @@ -212,11 +212,11 @@ func (c *beaconApiValidatorClient) EventStreamIsRunning() bool {
}

func (c *beaconApiValidatorClient) AggregatedSelections(ctx context.Context, selections []iface.BeaconCommitteeSelection) ([]iface.BeaconCommitteeSelection, error) {
return c.getAggregatedSelection(ctx, selections)
return c.aggregatedSelection(ctx, selections)
}

func (c *beaconApiValidatorClient) AggregatedSyncSelections(ctx context.Context, selections []iface.SyncCommitteeSelection) ([]iface.SyncCommitteeSelection, error) {
return c.getAggregatedSyncSelections(ctx, selections)
return c.aggregatedSyncSelections(ctx, selections)
}

func wrapInMetrics[Resp any](action string, f func() (Resp, error)) (Resp, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/validator/client/beacon-api/mock"
)

// Make sure that AttestationData() returns the same thing as the internal getAttestationData()
// Make sure that AttestationData() returns the same thing as the internal attestationData()
func TestBeaconApiValidatorClient_GetAttestationDataValid(t *testing.T) {
const slot = primitives.Slot(1)
const committeeIndex = primitives.CommitteeIndex(2)
Expand All @@ -43,7 +43,7 @@ func TestBeaconApiValidatorClient_GetAttestationDataValid(t *testing.T) {
).Times(2)

validatorClient := beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
expectedResp, expectedErr := validatorClient.getAttestationData(ctx, slot, committeeIndex)
expectedResp, expectedErr := validatorClient.attestationData(ctx, slot, committeeIndex)

resp, err := validatorClient.AttestationData(
context.Background(),
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestBeaconApiValidatorClient_GetAttestationDataError(t *testing.T) {
).Times(2)

validatorClient := beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
expectedResp, expectedErr := validatorClient.getAttestationData(ctx, slot, committeeIndex)
expectedResp, expectedErr := validatorClient.attestationData(ctx, slot, committeeIndex)

resp, err := validatorClient.AttestationData(
context.Background(),
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestBeaconApiValidatorClient_DomainDataValid(t *testing.T) {
resp, err := validatorClient.DomainData(context.Background(), &ethpb.DomainRequest{Epoch: epoch, Domain: domainType})

domainTypeArray := bytesutil.ToBytes4(domainType)
expectedResp, expectedErr := validatorClient.getDomainData(ctx, epoch, domainTypeArray)
expectedResp, expectedErr := validatorClient.domainData(ctx, epoch, domainTypeArray)
assert.DeepEqual(t, expectedErr, err)
assert.DeepEqual(t, expectedResp, resp)
}
Expand Down
2 changes: 1 addition & 1 deletion validator/client/beacon-api/beacon_committee_selections.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type aggregatedSelectionResponse struct {
Data []iface.BeaconCommitteeSelection `json:"data"`
}

func (c *beaconApiValidatorClient) getAggregatedSelection(ctx context.Context, selections []iface.BeaconCommitteeSelection) ([]iface.BeaconCommitteeSelection, error) {
func (c *beaconApiValidatorClient) aggregatedSelection(ctx context.Context, selections []iface.BeaconCommitteeSelection) ([]iface.BeaconCommitteeSelection, error) {
body, err := json.Marshal(selections)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal selections")
Expand Down
4 changes: 2 additions & 2 deletions validator/client/beacon-api/domain_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)

func (c *beaconApiValidatorClient) getDomainData(ctx context.Context, epoch primitives.Epoch, domainType [4]byte) (*ethpb.DomainResponse, error) {
func (c *beaconApiValidatorClient) domainData(ctx context.Context, epoch primitives.Epoch, domainType [4]byte) (*ethpb.DomainResponse, error) {
// Get the fork version from the given epoch
fork, err := forks.Fork(epoch)
if err != nil {
return nil, errors.Wrapf(err, "failed to get fork version for epoch %d", epoch)
}

// Get the genesis validator root
genesis, err := c.genesisProvider.GetGenesis(ctx)
genesis, err := c.genesisProvider.Genesis(ctx)
if err != nil {
return nil, errors.Wrapf(err, "failed to get genesis info")
}
Expand Down
Loading

0 comments on commit 5483aec

Please sign in to comment.