diff --git a/.golangci.yml b/.golangci.yml index 6d458a5b7..bc720ccf4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,6 +17,7 @@ linters: - errcheck - gosimple - gocognit + - nilerr - whitespace - misspell diff --git a/beacon-chain/core/helpers/sync_committee.go b/beacon-chain/core/helpers/sync_committee.go index 1066547c7..23cfb2d3a 100644 --- a/beacon-chain/core/helpers/sync_committee.go +++ b/beacon-chain/core/helpers/sync_committee.go @@ -36,7 +36,7 @@ func IsCurrentPeriodSyncCommittee( if err == cache.ErrNonExistingSyncCommitteeKey { val, err := st.ValidatorAtIndex(valIdx) if err != nil { - return false, nil + return false, err } committee, err := st.CurrentSyncCommittee() if err != nil { @@ -73,7 +73,7 @@ func IsNextPeriodSyncCommittee( if err == cache.ErrNonExistingSyncCommitteeKey { val, err := st.ValidatorAtIndex(valIdx) if err != nil { - return false, nil + return false, err } committee, err := st.NextSyncCommittee() if err != nil { @@ -100,7 +100,7 @@ func CurrentPeriodSyncSubcommitteeIndices( if err == cache.ErrNonExistingSyncCommitteeKey { val, err := st.ValidatorAtIndex(valIdx) if err != nil { - return nil, nil + return nil, err } committee, err := st.CurrentSyncCommittee() if err != nil { @@ -134,7 +134,7 @@ func NextPeriodSyncSubcommitteeIndices( if err == cache.ErrNonExistingSyncCommitteeKey { val, err := st.ValidatorAtIndex(valIdx) if err != nil { - return nil, nil + return nil, err } committee, err := st.NextSyncCommittee() if err != nil { diff --git a/beacon-chain/core/helpers/sync_committee_test.go b/beacon-chain/core/helpers/sync_committee_test.go index 21bc6040f..c3860d5de 100644 --- a/beacon-chain/core/helpers/sync_committee_test.go +++ b/beacon-chain/core/helpers/sync_committee_test.go @@ -94,7 +94,7 @@ func TestIsCurrentEpochSyncCommittee_DoesNotExist(t *testing.T) { require.NoError(t, state.SetNextSyncCommittee(syncCommittee)) ok, err := IsCurrentPeriodSyncCommittee(state, 12390192) - require.NoError(t, err) + require.ErrorContains(t, "index 12390192 out of range", err) require.Equal(t, false, ok) } @@ -176,7 +176,7 @@ func TestIsNextEpochSyncCommittee_DoesNotExist(t *testing.T) { require.NoError(t, state.SetNextSyncCommittee(syncCommittee)) ok, err := IsNextPeriodSyncCommittee(state, 120391029) - require.NoError(t, err) + require.ErrorContains(t, "index 120391029 out of range", err) require.Equal(t, false, ok) } @@ -273,7 +273,7 @@ func TestCurrentEpochSyncSubcommitteeIndices_DoesNotExist(t *testing.T) { require.NoError(t, state.SetNextSyncCommittee(syncCommittee)) index, err := CurrentPeriodSyncSubcommitteeIndices(state, 129301923) - require.NoError(t, err) + require.ErrorContains(t, "index 129301923 out of range", err) require.DeepEqual(t, []primitives.CommitteeIndex(nil), index) } @@ -356,7 +356,7 @@ func TestNextEpochSyncSubcommitteeIndices_DoesNotExist(t *testing.T) { require.NoError(t, state.SetNextSyncCommittee(syncCommittee)) index, err := NextPeriodSyncSubcommitteeIndices(state, 21093019) - require.NoError(t, err) + require.ErrorContains(t, "index 21093019 out of range", err) require.DeepEqual(t, []primitives.CommitteeIndex(nil), index) } diff --git a/beacon-chain/rpc/eth/node/node.go b/beacon-chain/rpc/eth/node/node.go index b64038bee..2ab5ea0a8 100644 --- a/beacon-chain/rpc/eth/node/node.go +++ b/beacon-chain/rpc/eth/node/node.go @@ -301,6 +301,7 @@ func (ns *Server) GetHealth(ctx context.Context, _ *emptypb.Empty) (*emptypb.Emp if ns.SyncChecker.Syncing() || ns.SyncChecker.Initialized() { if err := grpc.SetHeader(ctx, metadata.Pairs(grpcutil.HttpCodeMetadataKey, strconv.Itoa(http.StatusPartialContent))); err != nil { // We return a positive result because failing to set a non-gRPC related header should not cause the gRPC call to fail. + //nolint:nilerr return &emptypb.Empty{}, nil } return &emptypb.Empty{}, nil diff --git a/beacon-chain/rpc/testutil/mock_blocker.go b/beacon-chain/rpc/testutil/mock_blocker.go index dac5a8851..904d63ea4 100644 --- a/beacon-chain/rpc/testutil/mock_blocker.go +++ b/beacon-chain/rpc/testutil/mock_blocker.go @@ -22,6 +22,7 @@ func (m *MockBlocker) Block(_ context.Context, b []byte) (interfaces.ReadOnlySig } slotNumber, parseErr := strconv.ParseUint(string(b), 10, 64) if parseErr != nil { + //nolint:nilerr return m.BlockToReturn, nil } return m.SlotBlockMap[primitives.Slot(slotNumber)], nil diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher.go b/beacon-chain/sync/initial-sync/blocks_fetcher.go index 3b59eee44..6b1297c52 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher.go @@ -296,7 +296,7 @@ func (f *blocksFetcher) fetchBlocksFromPeer( blocks, err := f.requestBlocks(ctx, req, peers[i]) if err == nil { f.p2p.Peers().Scorers().BlockProviderScorer().Touch(peers[i]) - return blocks, peers[i], err + return blocks, peers[i], nil } else { log.WithError(err).Debug("Could not request blocks by range") } diff --git a/testing/endtoend/components/eth1/transactions.go b/testing/endtoend/components/eth1/transactions.go index 9a8bb6c13..1d86a396a 100644 --- a/testing/endtoend/components/eth1/transactions.go +++ b/testing/endtoend/components/eth1/transactions.go @@ -110,14 +110,13 @@ func SendTransaction(client *rpc.Client, key *ecdsa.PrivateKey, f *filler.Filler g.Go(func() error { tx, err := txfuzz.RandomValidTx(client, f, sender, nonce+index, gasPrice, nil, al) if err != nil { - return nil + return err } signedTx, err := types.SignTx(tx, types.NewLondonSigner(chainid), key) if err != nil { - return nil + return err } - err = backend.SendTransaction(context.Background(), signedTx) - return nil + return backend.SendTransaction(context.Background(), signedTx) }) } return g.Wait() diff --git a/validator/rpc/beacon.go b/validator/rpc/beacon.go index 841fc96a3..3c41b7048 100644 --- a/validator/rpc/beacon.go +++ b/validator/rpc/beacon.go @@ -70,6 +70,7 @@ func (s *Server) registerBeaconClient() error { func (s *Server) GetBeaconStatus(ctx context.Context, _ *empty.Empty) (*validatorpb.BeaconStatusResponse, error) { syncStatus, err := s.beaconNodeClient.GetSyncStatus(ctx, &emptypb.Empty{}) if err != nil { + //nolint:nilerr return &validatorpb.BeaconStatusResponse{ BeaconNodeEndpoint: s.nodeGatewayEndpoint, Connected: false, diff --git a/validator/rpc/health.go b/validator/rpc/health.go index 5d6e24402..b20dcac95 100644 --- a/validator/rpc/health.go +++ b/validator/rpc/health.go @@ -19,6 +19,7 @@ import ( func (s *Server) GetBeaconNodeConnection(ctx context.Context, _ *emptypb.Empty) (*validatorpb.NodeConnectionResponse, error) { syncStatus, err := s.syncChecker.Syncing(ctx) if err != nil || s.validatorService.Status() != nil { + //nolint:nilerr return &validatorpb.NodeConnectionResponse{ GenesisTime: 0, BeaconNodeEndpoint: s.nodeGatewayEndpoint,