From 3bc808352f92768c52fdd46e6c0986569199e81c Mon Sep 17 00:00:00 2001 From: Anukul Sangwan <44864521+anukul@users.noreply.github.com> Date: Thu, 29 Jun 2023 09:38:26 -0600 Subject: [PATCH] run `ineffassign` for all code (#12578) * run `ineffassign` for all code * fix reported ineffassign errors * remove redundant changes * fix remaining ineffassign errors --------- Co-authored-by: Nishant Das --- api/client/beacon/checkpoint_test.go | 3 +++ encoding/ssz/detect/configfork_test.go | 3 +++ nogo_config.json | 10 +++++----- testing/endtoend/component_handler_test.go | 2 +- testing/endtoend/components/eth1/transactions.go | 11 +++++++---- testing/endtoend/components/lighthouse_validator.go | 5 ----- testing/endtoend/endtoend_test.go | 1 - 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/api/client/beacon/checkpoint_test.go b/api/client/beacon/checkpoint_test.go index b879a9064..ceb5eb240 100644 --- a/api/client/beacon/checkpoint_test.go +++ b/api/client/beacon/checkpoint_test.go @@ -128,6 +128,7 @@ func TestDownloadWeakSubjectivityCheckpoint(t *testing.T) { wst, err := util.NewBeaconState() require.NoError(t, err) fork, err := forkForEpoch(cfg, epoch) + require.NoError(t, err) require.NoError(t, wst.SetFork(fork)) // set up checkpoint block @@ -226,6 +227,7 @@ func TestDownloadBackwardsCompatibleCombined(t *testing.T) { wst, err := util.NewBeaconState() require.NoError(t, err) fork, err := forkForEpoch(cfg, cfg.GenesisEpoch) + require.NoError(t, err) require.NoError(t, wst.SetFork(fork)) // set up checkpoint block @@ -399,6 +401,7 @@ func TestDownloadFinalizedData(t *testing.T) { st, err := util.NewBeaconState() require.NoError(t, err) fork, err := forkForEpoch(cfg, epoch) + require.NoError(t, err) require.NoError(t, st.SetFork(fork)) require.NoError(t, st.SetSlot(slot)) diff --git a/encoding/ssz/detect/configfork_test.go b/encoding/ssz/detect/configfork_test.go index 5fb8165ca..b4191a684 100644 --- a/encoding/ssz/detect/configfork_test.go +++ b/encoding/ssz/detect/configfork_test.go @@ -134,6 +134,7 @@ func TestUnmarshalState(t *testing.T) { }() bc := params.BeaconConfig() altairSlot, err := slots.EpochStart(bc.AltairForkEpoch) + require.NoError(t, err) bellaSlot, err := slots.EpochStart(bc.BellatrixForkEpoch) require.NoError(t, err) cases := []struct { @@ -205,6 +206,7 @@ func TestUnmarshalBlock(t *testing.T) { altairv := bytesutil.ToBytes4(params.BeaconConfig().AltairForkVersion) bellav := bytesutil.ToBytes4(params.BeaconConfig().BellatrixForkVersion) altairS, err := slots.EpochStart(params.BeaconConfig().AltairForkEpoch) + require.NoError(t, err) bellaS, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch) require.NoError(t, err) cases := []struct { @@ -296,6 +298,7 @@ func TestUnmarshalBlindedBlock(t *testing.T) { altairv := bytesutil.ToBytes4(params.BeaconConfig().AltairForkVersion) bellav := bytesutil.ToBytes4(params.BeaconConfig().BellatrixForkVersion) altairS, err := slots.EpochStart(params.BeaconConfig().AltairForkEpoch) + require.NoError(t, err) bellaS, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch) require.NoError(t, err) cases := []struct { diff --git a/nogo_config.json b/nogo_config.json index e6b79e1b2..282523f08 100644 --- a/nogo_config.json +++ b/nogo_config.json @@ -147,11 +147,11 @@ } }, "ineffassign": { - "only_files": { - "beacon-chain/.*": "", - "shared/.*": "", - "slasher/.*": "", - "validator/.*": "" + "exclude_files": { + "external/.*": "Third party code", + "rules_go_work-.*": "Third party code", + ".*\\.pb.*.go": "Generated code is ok", + ".*generated\\.ssz\\.go": "Generated code is ok" } }, "properpermissions": { diff --git a/testing/endtoend/component_handler_test.go b/testing/endtoend/component_handler_test.go index cd44b9244..37e18c3ff 100644 --- a/testing/endtoend/component_handler_test.go +++ b/testing/endtoend/component_handler_test.go @@ -256,7 +256,7 @@ func (c *componentHandler) required() []e2etypes.ComponentRunner { func (c *componentHandler) printPIDs(logger func(string, ...interface{})) { msg := "\nPID of components. Attach a debugger... if you dare!\n\n" - msg = "This test PID: " + strconv.Itoa(os.Getpid()) + " (parent=" + strconv.Itoa(os.Getppid()) + ")\n" + msg += "This test PID: " + strconv.Itoa(os.Getpid()) + " (parent=" + strconv.Itoa(os.Getppid()) + ")\n" // Beacon chain nodes msg += fmt.Sprintf("Beacon chain nodes: %v\n", PIDsFromMultiComponentRunner(c.beaconNodes)) diff --git a/testing/endtoend/components/eth1/transactions.go b/testing/endtoend/components/eth1/transactions.go index 86d3d3b49..3627b2387 100644 --- a/testing/endtoend/components/eth1/transactions.go +++ b/testing/endtoend/components/eth1/transactions.go @@ -114,7 +114,7 @@ func SendTransaction(client *rpc.Client, key *ecdsa.PrivateKey, f *filler.Filler for i := uint64(0); i < N; i++ { index := i g.Go(func() error { - tx, err := txfuzz.RandomValidTx(client, f, sender, nonce+index, expectedPrice, nil, al) + tx, err := txfuzz.RandomValidTx(client, f, sender, nonce+index, gasPrice, nil, al) if err != nil { // In the event the transaction constructed is not valid, we continue with the routine // rather than complete stop it. @@ -129,9 +129,12 @@ func SendTransaction(client *rpc.Client, key *ecdsa.PrivateKey, f *filler.Filler return nil } err = backend.SendTransaction(context.Background(), signedTx) - // We continue on if the constructed transaction is invalid - // and can't be submitted on chain. - //nolint:nilerr + if err != nil { + // We continue on if the constructed transaction is invalid + // and can't be submitted on chain. + //nolint:nilerr + return nil + } return nil }) } diff --git a/testing/endtoend/components/lighthouse_validator.go b/testing/endtoend/components/lighthouse_validator.go index a5faf8b48..8e4129fcd 100644 --- a/testing/endtoend/components/lighthouse_validator.go +++ b/testing/endtoend/components/lighthouse_validator.go @@ -172,11 +172,6 @@ func (v *LighthouseValidatorNode) Start(ctx context.Context) error { } _, _, index, _ := v.config, v.validatorNum, v.index, v.offset - beaconRPCPort := e2e.TestParams.Ports.PrysmBeaconNodeRPCPort + index - if beaconRPCPort >= e2e.TestParams.Ports.PrysmBeaconNodeRPCPort+e2e.TestParams.BeaconNodeCount { - // Point any extra validator clients to a node we know is running. - beaconRPCPort = e2e.TestParams.Ports.PrysmBeaconNodeRPCPort - } kPath := e2e.TestParams.TestPath + fmt.Sprintf("/lighthouse-validator-%d", index) testNetDir := e2e.TestParams.TestPath + fmt.Sprintf("/lighthouse-testnet-%d", index) httpPort := e2e.TestParams.Ports.LighthouseBeaconNodeHTTPPort diff --git a/testing/endtoend/endtoend_test.go b/testing/endtoend/endtoend_test.go index 2408d61ba..b5d3c0c2e 100644 --- a/testing/endtoend/endtoend_test.go +++ b/testing/endtoend/endtoend_test.go @@ -516,7 +516,6 @@ func (r *testRunner) defaultEndToEndRun() error { if err := r.testCheckpointSync(ctx, g, index, conns, httpEndpoints[0], benr, menr); err != nil { return errors.Wrap(err, "checkpoint sync test failed") } - index += 1 } if config.ExtraEpochs > 0 {