diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index c923e89d9..dc622e4c7 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,9 +19,9 @@ jobs: go-version: '1.20.6' - uses: actions/checkout@v3 - name: golangci-lint - uses: golangci/golangci-lint-action@master + uses: golangci/golangci-lint-action@v3 with: - version: v1.51.2 + version: v1.52.2 - name: notify failure if: failure() && github.ref == 'refs/heads/main' env: diff --git a/.golangci.yml b/.golangci.yml index be53e8b22..71c6bb3b8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -74,6 +74,8 @@ linters-settings: disabled: true - name: cognitive-complexity disabled: true + - name: comment-spacings + disabled: true # Doesn't support latest go spec comments # Some configured revive rules - name: unhandled-error arguments: diff --git a/app/errors/errors.go b/app/errors/errors.go index 3cece11b4..d245b276c 100644 --- a/app/errors/errors.go +++ b/app/errors/errors.go @@ -73,7 +73,7 @@ func SkipWrap(err error, msg string, skip int, fields ...z.Field) error { } return structured{ - err: fmt.Errorf("%s: %w", msg, err), //nolint: forbidigo // Wrap error message using stdlib. + err: fmt.Errorf("%s: %w", msg, err), //nolint:forbidigo // Wrap error message using stdlib. fields: fields, stack: stack, } diff --git a/app/errors/go113.go b/app/errors/go113.go index 7c097a8d4..2add5dcbd 100644 --- a/app/errors/go113.go +++ b/app/errors/go113.go @@ -26,7 +26,7 @@ func Is(err, target error) bool { return stderrors.Is(err, target) } // repeatedly calling Unwrap. // // An error matches target if the error's concrete value is assignable to the value -// pointed to by target, or if the error has a method As(interface{}) bool such that +// pointed to by target, or if the error has a method As(any) bool such that // As(target) returns true. In the latter case, the As method is responsible for // setting target. // diff --git a/app/tracer/trace_test.go b/app/tracer/trace_test.go index 5e631573b..2b6b77578 100644 --- a/app/tracer/trace_test.go +++ b/app/tracer/trace_test.go @@ -36,7 +36,7 @@ func TestStdOutTracer(t *testing.T) { require.NoError(t, stop(ctx)) - var m map[string]interface{} + var m map[string]any d := json.NewDecoder(&buf) err = d.Decode(&m) diff --git a/app/z/zapfield.go b/app/z/zapfield.go index e452dd1d8..014a74c66 100644 --- a/app/z/zapfield.go +++ b/app/z/zapfield.go @@ -98,7 +98,7 @@ func F64(key string, val float64) Field { // Any returns a wrapped zap string field with the string version of value. // Note we are not using zap.Any since logfmt formatter doesn't support it. -func Any(key string, val interface{}) Field { +func Any(key string, val any) Field { return func(add func(zap.Field)) { add(zap.String(key, fmt.Sprint(val))) } diff --git a/cmd/markdown_internal_test.go b/cmd/markdown_internal_test.go index 670d7b1a8..d8c88111e 100644 --- a/cmd/markdown_internal_test.go +++ b/cmd/markdown_internal_test.go @@ -185,7 +185,7 @@ func TestTrackerReasonReference(t *testing.T) { writeMarkdown(t, "../docs/reasons.md", tpl, reasons) } -func writeMarkdown(t *testing.T, file string, tpl *template.Template, data interface{}) { +func writeMarkdown(t *testing.T, file string, tpl *template.Template, data any) { t.Helper() var buf bytes.Buffer diff --git a/core/validatorapi/router.go b/core/validatorapi/router.go index 12f0c2a0f..37f4c1819 100644 --- a/core/validatorapi/router.go +++ b/core/validatorapi/router.go @@ -236,7 +236,7 @@ func (a apiError) Error() string { // handlerFunc is a convenient handler function providing a context, parsed path parameters, // the request body, and returning the response struct or an error. -type handlerFunc func(ctx context.Context, params map[string]string, query url.Values, typ contentType, body []byte) (res interface{}, headers http.Header, err error) +type handlerFunc func(ctx context.Context, params map[string]string, query url.Values, typ contentType, body []byte) (res any, headers http.Header, err error) // wrap adapts the handler function returning a standard http handler. // It does tracing, metrics and response and error writing. @@ -283,7 +283,7 @@ func wrap(endpoint string, handler handlerFunc) http.Handler { } // writeResponse writes the 200 OK response and json response body. -func writeResponse(ctx context.Context, w http.ResponseWriter, endpoint string, response interface{}, headers http.Header) { +func writeResponse(ctx context.Context, w http.ResponseWriter, endpoint string, response any, headers http.Header) { if response == nil { return } @@ -315,7 +315,7 @@ func wrapTrace(endpoint string, handler http.HandlerFunc) http.Handler { // getValidator returns a handler function for the get validators by pubkey or index endpoint. func getValidators(p eth2client.ValidatorsProvider) handlerFunc { - return func(ctx context.Context, params map[string]string, query url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, params map[string]string, query url.Values, _ contentType, _ []byte) (any, http.Header, error) { stateID := params["state_id"] resp, err := getValidatorsByID(ctx, p, stateID, getValidatorIDs(query)...) @@ -331,7 +331,7 @@ func getValidators(p eth2client.ValidatorsProvider) handlerFunc { // getValidator returns a handler function for the get validators by pubkey or index endpoint. func getValidator(p eth2client.ValidatorsProvider) handlerFunc { - return func(ctx context.Context, params map[string]string, _ url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, params map[string]string, _ url.Values, _ contentType, _ []byte) (any, http.Header, error) { stateID := params["state_id"] id := params["validator_id"] @@ -353,7 +353,7 @@ func getValidator(p eth2client.ValidatorsProvider) handlerFunc { // attestationData returns a handler function for the attestation data endpoint. func attestationData(p eth2client.AttestationDataProvider) handlerFunc { - return func(ctx context.Context, _ map[string]string, query url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, query url.Values, _ contentType, _ []byte) (any, http.Header, error) { slot, err := uintQuery(query, "slot") if err != nil { return nil, nil, err @@ -379,7 +379,7 @@ func attestationData(p eth2client.AttestationDataProvider) handlerFunc { // submitAttestations returns a handler function for the attestation submitter endpoint. func submitAttestations(p eth2client.AttestationsSubmitter) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { var atts []*eth2p0.Attestation err := unmarshal(typ, body, &atts) if err != nil { @@ -392,7 +392,7 @@ func submitAttestations(p eth2client.AttestationsSubmitter) handlerFunc { // proposerDuties returns a handler function for the proposer duty endpoint. func proposerDuties(p eth2client.ProposerDutiesProvider) handlerFunc { - return func(ctx context.Context, params map[string]string, _ url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, params map[string]string, _ url.Values, _ contentType, _ []byte) (any, http.Header, error) { epoch, err := uintParam(params, "epoch") if err != nil { return nil, nil, err @@ -417,7 +417,7 @@ func proposerDuties(p eth2client.ProposerDutiesProvider) handlerFunc { // attesterDuties returns a handler function for the attester duty endpoint. func attesterDuties(p eth2client.AttesterDutiesProvider) handlerFunc { - return func(ctx context.Context, params map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, params map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { epoch, err := uintParam(params, "epoch") if err != nil { return nil, nil, err @@ -445,7 +445,7 @@ func attesterDuties(p eth2client.AttesterDutiesProvider) handlerFunc { // syncCommitteeDuties returns a handler function for the sync committee duty endpoint. func syncCommitteeDuties(p eth2client.SyncCommitteeDutiesProvider) handlerFunc { - return func(ctx context.Context, params map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, params map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { epoch, err := uintParam(params, "epoch") if err != nil { return nil, nil, err @@ -469,7 +469,7 @@ func syncCommitteeDuties(p eth2client.SyncCommitteeDutiesProvider) handlerFunc { // syncCommitteeContribution returns a handler function for get sync committee contribution endpoint. func syncCommitteeContribution(s eth2client.SyncCommitteeContributionProvider) handlerFunc { - return func(ctx context.Context, _ map[string]string, query url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, query url.Values, _ contentType, _ []byte) (any, http.Header, error) { slot, err := uintQuery(query, "slot") if err != nil { return nil, nil, err @@ -497,7 +497,7 @@ func syncCommitteeContribution(s eth2client.SyncCommitteeContributionProvider) h // submitContributionAndProofs returns a handler function for sync committee contributions submitter endpoint. func submitContributionAndProofs(s eth2client.SyncCommitteeContributionsSubmitter) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { var contributionAndProofs []*altair.SignedContributionAndProof err := unmarshal(typ, body, &contributionAndProofs) if err != nil { @@ -510,7 +510,7 @@ func submitContributionAndProofs(s eth2client.SyncCommitteeContributionsSubmitte // proposeBlock receives the randao from the validator and returns the unsigned BeaconBlock. func proposeBlock(p eth2client.BeaconBlockProposalProvider) handlerFunc { - return func(ctx context.Context, params map[string]string, query url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, params map[string]string, query url.Values, _ contentType, _ []byte) (any, http.Header, error) { slot, err := uintParam(params, "slot") if err != nil { return nil, nil, err @@ -588,7 +588,7 @@ func proposeBlock(p eth2client.BeaconBlockProposalProvider) handlerFunc { // proposeBlindedBlock receives the randao from the validator and returns the unsigned BlindedBeaconBlock. func proposeBlindedBlock(p eth2client.BlindedBeaconBlockProposalProvider) handlerFunc { - return func(ctx context.Context, params map[string]string, query url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, params map[string]string, query url.Values, _ contentType, _ []byte) (any, http.Header, error) { slot, err := uintParam(params, "slot") if err != nil { return nil, nil, err @@ -642,7 +642,7 @@ func proposeBlindedBlock(p eth2client.BlindedBeaconBlockProposalProvider) handle } func submitBlock(p eth2client.BeaconBlockSubmitter) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { capellaBlock := new(capella.SignedBeaconBlock) err := unmarshal(typ, body, capellaBlock) if err == nil { @@ -692,7 +692,7 @@ func submitBlock(p eth2client.BeaconBlockSubmitter) handlerFunc { } func submitBlindedBlock(p eth2client.BlindedBeaconBlockSubmitter) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { // The blinded block maybe either bellatrix or capella. capellaBlock := new(eth2capella.SignedBlindedBeaconBlock) err := unmarshal(typ, body, capellaBlock) @@ -722,7 +722,7 @@ func submitBlindedBlock(p eth2client.BlindedBeaconBlockSubmitter) handlerFunc { // submitValidatorRegistrations returns a handler function for the validator (builder) registration submitter endpoint. func submitValidatorRegistrations(r eth2client.ValidatorRegistrationsSubmitter) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { var unversioned []*eth2v1.SignedValidatorRegistration if err := unmarshal(typ, body, &unversioned); err != nil { return nil, nil, errors.Wrap(err, "unmarshal signed builder registration") @@ -742,7 +742,7 @@ func submitValidatorRegistrations(r eth2client.ValidatorRegistrationsSubmitter) // aggregateBeaconCommitteeSelections receives partial beacon committee selections and returns aggregated selections. func aggregateBeaconCommitteeSelections(a eth2exp.BeaconCommitteeSelectionAggregator) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (res interface{}, headers http.Header, err error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (res any, headers http.Header, err error) { var selections []*eth2exp.BeaconCommitteeSelection if err := unmarshal(typ, body, &selections); err != nil { return nil, nil, errors.Wrap(err, "unmarshal beacon committee selections") @@ -759,7 +759,7 @@ func aggregateBeaconCommitteeSelections(a eth2exp.BeaconCommitteeSelectionAggreg // aggregateSyncCommitteeSelections receives partial sync committee selections and returns aggregated selections. func aggregateSyncCommitteeSelections(a eth2exp.SyncCommitteeSelectionAggregator) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (res interface{}, headers http.Header, err error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (res any, headers http.Header, err error) { var selections []*eth2exp.SyncCommitteeSelection if err := unmarshal(typ, body, &selections); err != nil { return nil, nil, errors.Wrap(err, "unmarshal sync committee selections") @@ -776,7 +776,7 @@ func aggregateSyncCommitteeSelections(a eth2exp.SyncCommitteeSelectionAggregator // submitExit returns a handler function for the exit submitter endpoint. func submitExit(p eth2client.VoluntaryExitSubmitter) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { exit := new(eth2p0.SignedVoluntaryExit) if err := unmarshal(typ, body, exit); err != nil { return nil, nil, errors.Wrap(err, "unmarshal signed voluntary exit") @@ -787,7 +787,7 @@ func submitExit(p eth2client.VoluntaryExitSubmitter) handlerFunc { } func proposerConfig(p eth2exp.ProposerConfigProvider) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, _ contentType, _ []byte) (any, http.Header, error) { resp, err := p.ProposerConfig(ctx) if err != nil { return nil, nil, errors.Wrap(err, "proposer config") @@ -798,7 +798,7 @@ func proposerConfig(p eth2exp.ProposerConfigProvider) handlerFunc { } func aggregateAttestation(p eth2client.AggregateAttestationProvider) handlerFunc { - return func(ctx context.Context, _ map[string]string, query url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, query url.Values, _ contentType, _ []byte) (any, http.Header, error) { slot, err := uintQuery(query, "slot") if err != nil { return nil, nil, err @@ -823,7 +823,7 @@ func aggregateAttestation(p eth2client.AggregateAttestationProvider) handlerFunc } func submitAggregateAttestations(s eth2client.AggregateAttestationsSubmitter) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { var aggs []*eth2p0.SignedAggregateAndProof err := unmarshal(typ, body, &aggs) if err != nil { @@ -840,7 +840,7 @@ func submitAggregateAttestations(s eth2client.AggregateAttestationsSubmitter) ha } func submitSyncCommitteeMessages(s eth2client.SyncCommitteeMessagesSubmitter) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { var msgs []*altair.SyncCommitteeMessage err := unmarshal(typ, body, &msgs) if err != nil { @@ -859,14 +859,14 @@ func submitSyncCommitteeMessages(s eth2client.SyncCommitteeMessagesSubmitter) ha // submitProposalPreparations swallows fee-recipient-address from validator client as it should be // configured by charon from cluster-lock.json and VC need not be configured with correct fee-recipient-address. func submitProposalPreparations() handlerFunc { - return func(context.Context, map[string]string, url.Values, contentType, []byte) (interface{}, http.Header, error) { + return func(context.Context, map[string]string, url.Values, contentType, []byte) (any, http.Header, error) { return nil, nil, nil } } // nodeVersion returns the version of the node. func nodeVersion(p eth2client.NodeVersionProvider) handlerFunc { - return func(ctx context.Context, _ map[string]string, _ url.Values, _ contentType, _ []byte) (interface{}, http.Header, error) { + return func(ctx context.Context, _ map[string]string, _ url.Values, _ contentType, _ []byte) (any, http.Header, error) { version, err := p.NodeVersion(ctx) if err != nil { return nil, nil, err @@ -999,7 +999,7 @@ func writeError(ctx context.Context, w http.ResponseWriter, endpoint string, err // unmarshal parses body with the appropriate unmarshaler based on the contentType and stores the result // in the value pointed to by v. -func unmarshal(typ contentType, body []byte, v interface{}) error { +func unmarshal(typ contentType, body []byte, v any) error { if len(body) == 0 { return apiError{ StatusCode: http.StatusBadRequest, diff --git a/core/validatorapi/router_internal_test.go b/core/validatorapi/router_internal_test.go index 797e59c1f..abb320e04 100644 --- a/core/validatorapi/router_internal_test.go +++ b/core/validatorapi/router_internal_test.go @@ -1261,7 +1261,7 @@ func (h testHandler) newBeaconHandler(t *testing.T) http.Handler { writeResponse(ctx, w, "", res, nil) }) mux.HandleFunc("/eth/v1/config/spec", func(w http.ResponseWriter, r *http.Request) { - res := map[string]interface{}{ + res := map[string]any{ "SLOTS_PER_EPOCH": fmt.Sprint(slotsPerEpoch), } writeResponse(ctx, w, "", nest(res, "data"), nil) @@ -1291,7 +1291,7 @@ func (h testHandler) newBeaconHandler(t *testing.T) http.Handler { } // nest returns a json nested version the data objected. Note nests must be provided in inverse order. -func nest(data interface{}, nests ...string) interface{} { +func nest(data any, nests ...string) any { res := data for _, nest := range nests { diff --git a/eth2util/keymanager/keymanager_test.go b/eth2util/keymanager/keymanager_test.go index 3da17ccee..63b444c52 100644 --- a/eth2util/keymanager/keymanager_test.go +++ b/eth2util/keymanager/keymanager_test.go @@ -148,7 +148,7 @@ type mockKeymanagerReq struct { // noopKeystore is a mock keystore for use in tests. type noopKeystore struct { - Crypto map[string]interface{} `json:"crypto"` + Crypto map[string]any `json:"crypto"` } // decrypt returns the secret from the encrypted keystore. diff --git a/eth2util/keystore/keystore.go b/eth2util/keystore/keystore.go index 658ca54cf..fdb5cb73b 100644 --- a/eth2util/keystore/keystore.go +++ b/eth2util/keystore/keystore.go @@ -117,12 +117,12 @@ func storeKeysInternal(secrets []tbls.PrivateKey, dir string, filenameFmt string // Keystore json file representation as a Go struct. type Keystore struct { - Crypto map[string]interface{} `json:"crypto"` - Description string `json:"description"` - Pubkey string `json:"pubkey"` - Path string `json:"path"` - ID string `json:"uuid"` - Version uint `json:"version"` + Crypto map[string]any `json:"crypto"` + Description string `json:"description"` + Pubkey string `json:"pubkey"` + Path string `json:"path"` + ID string `json:"uuid"` + Version uint `json:"version"` } // Encrypt returns the secret as an encrypted Keystore using pbkdf2 cipher. diff --git a/p2p/p2p.go b/p2p/p2p.go index 2398ea645..6417d377a 100644 --- a/p2p/p2p.go +++ b/p2p/p2p.go @@ -55,7 +55,7 @@ func NewTCPNode(ctx context.Context, cfg Config, key *k1.PrivateKey, connGater C return nil, err } - var tcpOpts []interface{} // libp2p.Transport requires empty interface options. + var tcpOpts []any // libp2p.Transport requires empty interface options. if cfg.DisableReuseport { tcpOpts = append(tcpOpts, tcp.DisableReuseport()) } diff --git a/testutil/golden.go b/testutil/golden.go index f3e84b4ec..4064093b7 100644 --- a/testutil/golden.go +++ b/testutil/golden.go @@ -68,7 +68,7 @@ func RequireGoldenBytes(t *testing.T, data []byte, opts ...func(*string)) { // RequireGoldenJSON asserts that a golden testdata file exists containing the JSON serialised form of the data object. // This is heavily inspired from https://github.com/sebdah/goldie. -func RequireGoldenJSON(t *testing.T, data interface{}, opts ...func(*string)) { +func RequireGoldenJSON(t *testing.T, data any, opts ...func(*string)) { t.Helper() if _, ok := data.(proto.Message); ok { diff --git a/testutil/integration/helpers_test.go b/testutil/integration/helpers_test.go index c8531d979..b3c905dd4 100644 --- a/testutil/integration/helpers_test.go +++ b/testutil/integration/helpers_test.go @@ -106,13 +106,13 @@ type asserter struct { func (a *asserter) await(ctx context.Context, t *testing.T, expect int) error { t.Helper() - var actual map[interface{}]bool + var actual map[any]bool ok := assert.Eventually(t, func() bool { if ctx.Err() != nil { return true } - actual = make(map[interface{}]bool) + actual = make(map[any]bool) a.callbacks.Range(func(k, v interface{}) bool { actual[k] = true diff --git a/testutil/trackpr/track.go b/testutil/trackpr/track.go index cdccb3e10..e658fe878 100644 --- a/testutil/trackpr/track.go +++ b/testutil/trackpr/track.go @@ -111,7 +111,7 @@ func track(ctx context.Context, ghToken string, pr PR, organization string, proj // getProjectData returns project data for the GitHub project. func getProjectData(ctx context.Context, client *gh.Client, organization string, projectNumber int) (projectData, error) { query := new(projectQuery) - variables := map[string]interface{}{ + variables := map[string]any{ "org": gh.String(organization), "number": gh.Int(projectNumber), }