From d5c2c7fe3132b97fc6fa208bebcd254582ffb611 Mon Sep 17 00:00:00 2001 From: Timothy Wu <tim.wu@chainsafe.io> Date: Sat, 5 Aug 2023 00:54:37 -0400 Subject: [PATCH] chore(ci): update `nilnil` linter config (#3421) --- .golangci.yml | 7 +++++++ dot/state/grandpa_changes.go | 22 +++++++++++----------- dot/state/slot.go | 12 ++++++------ dot/sync/bootstrap_syncer.go | 3 +-- dot/sync/tip_syncer.go | 3 +-- internal/trie/node/decode.go | 2 +- lib/grandpa/message_handler.go | 2 +- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 10f665d55a..8f4967776a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,6 +25,13 @@ linters-settings: line-length: 120 # tab width in spaces. Default to 1. tab-width: 1 + + nilnil: + checked-types: + - func + - iface + - map + - chan misspell: locale: UK diff --git a/dot/state/grandpa_changes.go b/dot/state/grandpa_changes.go index 0ca04857d0..044d7145cf 100644 --- a/dot/state/grandpa_changes.go +++ b/dot/state/grandpa_changes.go @@ -21,7 +21,7 @@ type pendingChange struct { announcingHeader *types.Header } -func (p pendingChange) String() string { +func (p *pendingChange) String() string { return fmt.Sprintf("announcing header: %s (#%d), delay: %d, effective block number: %d, next authorities: %d", p.announcingHeader.Hash().Short(), p.announcingHeader.Number, p.delay, p.effectiveNumber(), len(p.nextAuthorities)) } @@ -35,7 +35,7 @@ type orderedPendingChanges []pendingChange func (oc *orderedPendingChanges) Len() int { return len(*oc) } // findApplicable try to retrieve an applicable change from the slice of forced changes -func (oc orderedPendingChanges) findApplicable(importedHash common.Hash, importedNumber uint, +func (oc *orderedPendingChanges) findApplicable(importedHash common.Hash, importedNumber uint, isDescendatOf isDescendantOfFunc) (*pendingChange, error) { return oc.lookupChangeWhere(func(forced pendingChange) (bool, error) { @@ -57,9 +57,9 @@ func (oc orderedPendingChanges) findApplicable(importedHash common.Hash, importe } // lookupChangeWhere return the first pending change which satisfy the condition -func (oc orderedPendingChanges) lookupChangeWhere(condition conditionFunc[pendingChange]) ( +func (oc *orderedPendingChanges) lookupChangeWhere(condition conditionFunc[pendingChange]) ( pendingChange *pendingChange, err error) { - for _, change := range oc { + for _, change := range *oc { ok, err := condition(change) if err != nil { return pendingChange, fmt.Errorf("failed while applying condition: %w", err) @@ -70,7 +70,7 @@ func (oc orderedPendingChanges) lookupChangeWhere(condition conditionFunc[pendin } } - return nil, nil //nolint:nilnil + return nil, nil } // importChange only tracks the pending change if and only if it is the @@ -188,7 +188,7 @@ func (c *pendingChangeNode) importNode(blockHash common.Hash, blockNumber uint, // node ancestry using the `isDescendantOfFunc` type changeTree []*pendingChangeNode -func (ct changeTree) Len() int { return len(ct) } +func (ct *changeTree) Len() int { return len(*ct) } func (ct *changeTree) importChange(pendingChange *pendingChange, isDescendantOf isDescendantOfFunc) error { for _, root := range *ct { imported, err := root.importNode(pendingChange.announcingHeader.Hash(), @@ -215,9 +215,9 @@ func (ct *changeTree) importChange(pendingChange *pendingChange, isDescendantOf // lookupChangesWhere returns the first change which satisfy the // condition whithout modify the current state of the change tree -func (ct changeTree) lookupChangeWhere(condition conditionFunc[*pendingChangeNode]) ( +func (ct *changeTree) lookupChangeWhere(condition conditionFunc[*pendingChangeNode]) ( changeNode *pendingChangeNode, err error) { - for _, root := range ct { + for _, root := range *ct { ok, err := condition(root) if err != nil { return nil, fmt.Errorf("failed while applying condition: %w", err) @@ -228,7 +228,7 @@ func (ct changeTree) lookupChangeWhere(condition conditionFunc[*pendingChangeNod } } - return nil, nil //nolint:nilnil + return nil, nil } // findApplicable try to retrieve an applicable change @@ -261,7 +261,7 @@ func (ct *changeTree) findApplicable(hash common.Hash, number uint, // 1. contains the same hash as the one we're looking for. // 2. contains a lower or equal effective number as the one we're looking for. // 3. does not contains pending changes to be applied. -func (ct changeTree) findApplicableChange(hash common.Hash, number uint, +func (ct *changeTree) findApplicableChange(hash common.Hash, number uint, isDescendantOf isDescendantOfFunc) (changeNode *pendingChangeNode, err error) { return ct.lookupChangeWhere(func(pcn *pendingChangeNode) (bool, error) { if pcn.change.effectiveNumber() > number { @@ -300,7 +300,7 @@ func (ct changeTree) findApplicableChange(hash common.Hash, number uint, // pruneChanges will remove changes whose are not descendant of the hash argument // this function updates the current state of the change tree func (ct *changeTree) pruneChanges(hash common.Hash, isDescendantOf isDescendantOfFunc) error { - onBranchChanges := []*pendingChangeNode{} + var onBranchChanges []*pendingChangeNode for _, root := range *ct { scheduledChangeHash := root.change.announcingHeader.Hash() diff --git a/dot/state/slot.go b/dot/state/slot.go index 9ffdc0ad1d..240532c035 100644 --- a/dot/state/slot.go +++ b/dot/state/slot.go @@ -49,13 +49,13 @@ func (s *SlotState) CheckEquivocation(slotNow, slot uint64, header *types.Header // We don't check equivocations for old headers out of our capacity. // checking slotNow is greater than slot to avoid overflow, same as saturating_sub if saturatingSub(slotNow, slot) > maxSlotCapacity { - return nil, nil //nolint:nilnil + return nil, nil } slotEncoded := make([]byte, 8) binary.LittleEndian.PutUint64(slotEncoded, slot) - currentSlotKey := bytes.Join([][]byte{slotHeaderMapKey, slotEncoded[:]}, nil) + currentSlotKey := bytes.Join([][]byte{slotHeaderMapKey, slotEncoded}, nil) encodedHeadersWithSigners, err := s.db.Get(currentSlotKey) if err != nil && !errors.Is(err, chaindb.ErrKeyNotFound) { return nil, fmt.Errorf("getting key slot header map key %d: %w", slot, err) @@ -99,7 +99,7 @@ func (s *SlotState) CheckEquivocation(slotNow, slot uint64, header *types.Header if slotNow < firstSavedSlot { // The code below assumes that slots will be visited sequentially. - return nil, nil //nolint:nilnil + return nil, nil } for _, headerAndSigner := range headersWithSigners { @@ -118,7 +118,7 @@ func (s *SlotState) CheckEquivocation(slotNow, slot uint64, header *types.Header // We don't need to continue in case of duplicated header, // since it's already saved and a possible equivocation // would have been detected before. - return nil, nil //nolint:nilnil + return nil, nil } } } @@ -133,7 +133,7 @@ func (s *SlotState) CheckEquivocation(slotNow, slot uint64, header *types.Header slotEncoded := make([]byte, 8) binary.LittleEndian.PutUint64(slotEncoded, s) - toDelete := bytes.Join([][]byte{slotHeaderMapKey, slotEncoded[:]}, nil) + toDelete := bytes.Join([][]byte{slotHeaderMapKey, slotEncoded}, nil) keysToDelete = append(keysToDelete, toDelete) } } @@ -182,7 +182,7 @@ func (s *SlotState) CheckEquivocation(slotNow, slot uint64, header *types.Header return nil, fmt.Errorf("failed to flush batch operations: %w", err) } - return nil, nil //nolint:nilnil + return nil, nil } func saturatingSub(a, b uint64) uint64 { diff --git a/dot/sync/bootstrap_syncer.go b/dot/sync/bootstrap_syncer.go index 4b0b1ecc39..f6b912b0df 100644 --- a/dot/sync/bootstrap_syncer.go +++ b/dot/sync/bootstrap_syncer.go @@ -32,7 +32,7 @@ func (s *bootstrapSyncer) handleNewPeerState(ps *peerState) (*worker, error) { } if ps.number <= head.Number { - return nil, nil //nolint:nilnil + return nil, nil } return &worker{ @@ -44,7 +44,6 @@ func (s *bootstrapSyncer) handleNewPeerState(ps *peerState) (*worker, error) { }, nil } -//nolint:nilnil func (s *bootstrapSyncer) handleWorkerResult(res *worker) ( workerToRetry *worker, err error) { // if there is an error, potentially retry the worker diff --git a/dot/sync/tip_syncer.go b/dot/sync/tip_syncer.go index 00d2318cff..9eeb640c53 100644 --- a/dot/sync/tip_syncer.go +++ b/dot/sync/tip_syncer.go @@ -40,7 +40,7 @@ func (s *tipSyncer) handleNewPeerState(ps *peerState) (*worker, error) { } if ps.number <= fin.Number { - return nil, nil //nolint:nilnil + return nil, nil } return &worker{ @@ -52,7 +52,6 @@ func (s *tipSyncer) handleNewPeerState(ps *peerState) (*worker, error) { }, nil } -//nolint:nilnil func (s *tipSyncer) handleWorkerResult(res *worker) ( workerToRetry *worker, err error) { if res.err == nil { diff --git a/internal/trie/node/decode.go b/internal/trie/node/decode.go index 8fba10c963..1e2cf5c614 100644 --- a/internal/trie/node/decode.go +++ b/internal/trie/node/decode.go @@ -41,7 +41,7 @@ func Decode(reader io.Reader) (n *Node, err error) { switch variant { case emptyVariant: - return nil, nil //nolint:nilnil + return nil, nil case leafVariant, leafWithHashedValueVariant: n, err = decodeLeaf(reader, variant, partialKeyLength) if err != nil { diff --git a/lib/grandpa/message_handler.go b/lib/grandpa/message_handler.go index 4051fe3bda..5b821f0469 100644 --- a/lib/grandpa/message_handler.go +++ b/lib/grandpa/message_handler.go @@ -130,7 +130,7 @@ func (h *MessageHandler) handleNeighbourMessage(msg *NeighbourPacketV1) error { func (h *MessageHandler) handleCatchUpRequest(msg *CatchUpRequest) (*ConsensusMessage, error) { if !h.grandpa.authority { - return nil, nil //nolint:nilnil + return nil, nil } logger.Debugf("received catch up request for round %d and set id %d",