Skip to content

Commit

Permalink
chore(ci): update nilnil linter config (#3421)
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 authored Aug 5, 2023
1 parent e0fa0d9 commit d5c2c7f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions dot/state/grandpa_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions dot/state/slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
}
}
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions dot/sync/bootstrap_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions dot/sync/tip_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/trie/node/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/grandpa/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d5c2c7f

Please sign in to comment.