From ff9961683338fc278a5be683393ce71b37c81bec Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Fri, 8 Dec 2023 07:07:52 -0600 Subject: [PATCH] Fix staticcheck violations (#13301) * Fix violations of sa2002 * Fix violations of sa4005 * Fix violations of sa4010 * Fix violations for sa4023 * Comment on commented static checks --- BUILD.bazel | 12 ++++++------ beacon-chain/cache/depositcache/deposits_cache.go | 5 ++++- beacon-chain/rpc/eth/rewards/handlers_test.go | 2 -- testing/endtoend/endtoend_test.go | 2 +- validator/testing/mock_protector.go | 12 ++++++------ 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 3d5a380f1..9faef0995 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -104,7 +104,7 @@ STATICCHECK_ANALYZERS = [ "sa1016", "sa1017", "sa1018", - # "sa1019", + # "sa1019", # TODO: Fix all uses of deprecated things. "sa1020", "sa1021", "sa1023", @@ -117,7 +117,7 @@ STATICCHECK_ANALYZERS = [ "sa1030", "sa2000", "sa2001", - # "sa2002", + "sa2002", "sa2003", "sa3000", "sa3001", @@ -125,11 +125,11 @@ STATICCHECK_ANALYZERS = [ "sa4001", "sa4003", "sa4004", - # "sa4005", - # "sa4006", + "sa4005", + # "sa4006", # TODO: Fix violations of unused arguments. "sa4008", "sa4009", - # "sa4010", + "sa4010", "sa4011", "sa4012", "sa4013", @@ -142,7 +142,7 @@ STATICCHECK_ANALYZERS = [ "sa4020", "sa4021", "sa4022", - # "sa4023", + "sa4023", "sa4024", "sa4025", "sa4026", diff --git a/beacon-chain/cache/depositcache/deposits_cache.go b/beacon-chain/cache/depositcache/deposits_cache.go index 844a34737..879659fc4 100644 --- a/beacon-chain/cache/depositcache/deposits_cache.go +++ b/beacon-chain/cache/depositcache/deposits_cache.go @@ -314,7 +314,10 @@ func (dc *DepositCache) PruneProofs(ctx context.Context, untilDepositIndex int64 // Deposits returns the cached internal deposit tree. func (fd *FinalizedDeposits) Deposits() cache.MerkleTree { - return fd.deposits + if fd.deposits != nil { + return fd.deposits + } + return nil } // MerkleTrieIndex represents the last finalized index in diff --git a/beacon-chain/rpc/eth/rewards/handlers_test.go b/beacon-chain/rpc/eth/rewards/handlers_test.go index 12c3e041f..3fc3ec0a7 100644 --- a/beacon-chain/rpc/eth/rewards/handlers_test.go +++ b/beacon-chain/rpc/eth/rewards/handlers_test.go @@ -477,11 +477,9 @@ func TestAttestationRewards(t *testing.T) { require.NoError(t, st.SetSlot(params.BeaconConfig().SlotsPerEpoch*3-1)) validators := make([]*eth.Validator, 0, valCount) balances := make([]uint64, 0, valCount) - secretKeys := make([]bls.SecretKey, 0, valCount) for i := 0; i < valCount; i++ { blsKey, err := bls.RandKey() require.NoError(t, err) - secretKeys = append(secretKeys, blsKey) validators = append(validators, ð.Validator{ PublicKey: blsKey.PublicKey().Marshal(), ExitEpoch: params.BeaconConfig().FarFutureEpoch, diff --git a/testing/endtoend/endtoend_test.go b/testing/endtoend/endtoend_test.go index 197cea619..c9ccbf7be 100644 --- a/testing/endtoend/endtoend_test.go +++ b/testing/endtoend/endtoend_test.go @@ -212,7 +212,7 @@ func (r *testRunner) testDepositsAndTx(ctx context.Context, g *errgroup.Group, // for further deposit testing. err := r.depositor.SendAndMine(ctx, minGenesisActiveCount, int(e2e.DepositCount), e2etypes.PostGenesisDepositBatch, false) if err != nil { - r.t.Fatal(err) + r.t.Error(err) } } r.testTxGeneration(ctx, g, keystorePath, []e2etypes.ComponentRunner{}) diff --git a/validator/testing/mock_protector.go b/validator/testing/mock_protector.go index 005cc4591..d26a58414 100644 --- a/validator/testing/mock_protector.go +++ b/validator/testing/mock_protector.go @@ -16,19 +16,19 @@ type MockProtector struct { } // CheckAttestationSafety returns bool with allow attestation value. -func (mp MockProtector) CheckAttestationSafety(_ context.Context, _ *eth.IndexedAttestation) bool { - mp.VerifyAttestationCalled = true // skipcq: RVV-B0006 +func (mp *MockProtector) CheckAttestationSafety(_ context.Context, _ *eth.IndexedAttestation) bool { + mp.VerifyAttestationCalled = true return mp.AllowAttestation } // CheckBlockSafety returns bool with allow block value. -func (mp MockProtector) CheckBlockSafety(_ context.Context, _ *eth.SignedBeaconBlockHeader) bool { - mp.VerifyBlockCalled = true // skipcq: RVV-B0006 +func (mp *MockProtector) CheckBlockSafety(_ context.Context, _ *eth.SignedBeaconBlockHeader) bool { + mp.VerifyBlockCalled = true return mp.AllowBlock } // Status returns nil. -func (mp MockProtector) Status() error { - mp.StatusCalled = true // skipcq: RVV-B0006 +func (mp *MockProtector) Status() error { + mp.StatusCalled = true return nil }