From 835dce5f6ed82fc3f080282f61de17e6906eaba3 Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:07:48 -0600 Subject: [PATCH] Enable wastedassign linter & fix findings (#13507) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Radosław Kapka --- .golangci.yml | 1 - beacon-chain/execution/block_reader.go | 2 +- beacon-chain/state/fieldtrie/field_trie.go | 2 +- beacon-chain/sync/rpc_status.go | 2 +- beacon-chain/sync/subscriber.go | 7 +++---- container/doubly-linked-list/list.go | 1 - testing/assertions/assertions.go | 2 +- testing/endtoend/evaluators/execution_engine.go | 2 +- 8 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index aeed26d3300b..63c6d3c523fe 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -80,7 +80,6 @@ linters: - thelper - unparam - varnamelen - - wastedassign - wrapcheck - wsl diff --git a/beacon-chain/execution/block_reader.go b/beacon-chain/execution/block_reader.go index f502b5161307..4093931094f4 100644 --- a/beacon-chain/execution/block_reader.go +++ b/beacon-chain/execution/block_reader.go @@ -113,7 +113,7 @@ func (s *Service) BlockByTimestamp(ctx context.Context, time uint64) (*types.Hea cursorNum := big.NewInt(0).SetUint64(latestBlkHeight) cursorTime := latestBlkTime - numOfBlocks := uint64(0) + var numOfBlocks uint64 estimatedBlk := cursorNum.Uint64() maxTimeBuffer := searchThreshold * params.BeaconConfig().SecondsPerETH1Block // Terminate if we can't find an acceptable block after diff --git a/beacon-chain/state/fieldtrie/field_trie.go b/beacon-chain/state/fieldtrie/field_trie.go index 33693a95e216..981c111c21f1 100644 --- a/beacon-chain/state/fieldtrie/field_trie.go +++ b/beacon-chain/state/fieldtrie/field_trie.go @@ -60,7 +60,7 @@ func NewFieldTrie(field types.FieldIndex, fieldInfo types.DataType, elements int if err := validateElements(field, fieldInfo, elements, length); err != nil { return nil, err } - numOfElems := 0 + var numOfElems int if val, ok := elements.(sliceAccessor); ok { numOfElems = val.Len(val.State()) } else { diff --git a/beacon-chain/sync/rpc_status.go b/beacon-chain/sync/rpc_status.go index 7c7665aa2952..2f9f79b2f98e 100644 --- a/beacon-chain/sync/rpc_status.go +++ b/beacon-chain/sync/rpc_status.go @@ -210,7 +210,7 @@ func (s *Service) statusRPCHandler(ctx context.Context, msg interface{}, stream "error": err, }).Debug("Invalid status message from peer") - respCode := byte(0) + var respCode byte switch err { case p2ptypes.ErrGeneric: respCode = responseCodeServerError diff --git a/beacon-chain/sync/subscriber.go b/beacon-chain/sync/subscriber.go index 188e1d33e00f..8215dd2c0ce6 100644 --- a/beacon-chain/sync/subscriber.go +++ b/beacon-chain/sync/subscriber.go @@ -257,7 +257,8 @@ func (s *Service) subscribeWithBase(topic string, validator wrappedVal, handle s func (s *Service) wrapAndReportValidation(topic string, v wrappedVal) (string, pubsub.ValidatorEx) { return topic, func(ctx context.Context, pid peer.ID, msg *pubsub.Message) (res pubsub.ValidationResult) { defer messagehandler.HandlePanic(ctx, msg) - res = pubsub.ValidationIgnore // Default: ignore any message that panics. + // Default: ignore any message that panics. + res = pubsub.ValidationIgnore // nolint:wastedassign ctx, cancel := context.WithTimeout(ctx, pubsubMessageTimeout) defer cancel() messageReceivedCounter.WithLabelValues(topic).Inc() @@ -781,10 +782,8 @@ func isDigestValid(digest [4]byte, genesis time.Time, genValRoot [32]byte) (bool } func agentString(pid peer.ID, hst host.Host) string { - agString := "" - ok := false rawVersion, storeErr := hst.Peerstore().Get(pid, "AgentVersion") - agString, ok = rawVersion.(string) + agString, ok := rawVersion.(string) if storeErr != nil || !ok { agString = "" } diff --git a/container/doubly-linked-list/list.go b/container/doubly-linked-list/list.go index fad1d4a321bd..e45414366462 100644 --- a/container/doubly-linked-list/list.go +++ b/container/doubly-linked-list/list.go @@ -94,7 +94,6 @@ func (l *List[T]) Remove(n *Node[T]) { n.next.prev = n.prev } } - n = nil l.len-- } diff --git a/testing/assertions/assertions.go b/testing/assertions/assertions.go index 6fcf998bba11..27aa74815036 100644 --- a/testing/assertions/assertions.go +++ b/testing/assertions/assertions.go @@ -52,7 +52,7 @@ func DeepEqual(loggerFn assertionLoggerFn, expected, actual interface{}, msg ... if !isDeepEqual(expected, actual) { errMsg := parseMsg("Values are not equal", msg...) _, file, line, _ := runtime.Caller(2) - diff := "" + var diff string if _, isProto := expected.(proto.Message); isProto { diff = ProtobufPrettyDiff(expected, actual) } else { diff --git a/testing/endtoend/evaluators/execution_engine.go b/testing/endtoend/evaluators/execution_engine.go index caae3d8a505a..13a57aef3ba5 100644 --- a/testing/endtoend/evaluators/execution_engine.go +++ b/testing/endtoend/evaluators/execution_engine.go @@ -83,7 +83,7 @@ func optimisticSyncEnabled(_ *types.EvaluationContext, conns ...*grpc.ClientConn } func retrieveHeadSlot(resp *beacon.GetBlockV2Response) (uint64, error) { - headSlot := uint64(0) + var headSlot uint64 var err error switch resp.Version { case version.String(version.Phase0):