Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add go linter - "unused" #11235

Merged
merged 15 commits into from
Sep 5, 2023
Merged

add go linter - "unused" #11235

merged 15 commits into from
Sep 5, 2023

Conversation

snissn
Copy link
Contributor

@snissn snissn commented Sep 2, 2023

Related Issues

when we upgraded go versions, it was pointed out to me that "unused" is a recommended linter. Adding unused triggered a few errors regarding unused close and I clean them up here

Proposed Changes

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

  • Commits have a clear commit message.
  • PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
    • area, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps
  • If the PR affects users (e.g., new feature, bug fix, system requirements change), update the CHANGELOG.md and add details to the UNRELEASED section.
  • New features have usage guidelines and / or documentation updates in
  • Tests exist for new functionality or change in behavior
  • CI is green

@snissn snissn marked this pull request as ready for review September 4, 2023 22:32
@snissn snissn requested a review from a team as a code owner September 4, 2023 22:32
Copy link
Contributor

@fridrik01 fridrik01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -32,6 +32,8 @@ import (
)

// recordPoStFailure records a failure in the journal.
//
//nolint:unused
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these false positives?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they're called over an API.

Copy link
Contributor

@arajasek arajasek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this! One question before ✔️, and would be great to get someone from the miner side of things to look at this too.

@@ -32,6 +32,8 @@ import (
)

// recordPoStFailure records a failure in the journal.
//
//nolint:unused
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they're called over an API.

"testing"
)

func TestQueue(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection to this test, obviously, but I'm surprised it was needed to make the queue lok "used" -- it should already look used because of its use in rate limiting.

Do you understand why this was the case?

Copy link
Contributor Author

@snissn snissn Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I sort of understand, for some reason pop is unused:

chain/sub/ratelimit/queue.go:38:17: func `(*queue).pop` is unused (unused)
func (q *queue) pop() int64 {

it's pretty common to write a little datastructure library, write out a bunch of api/funcs for it, and then not use a few when you have your final implementation. I think there's some combination of peeking and truncating that happens in ./chain/sub/ratelimit/window.go instead of pop, but i haven't done a thorough dive into it. Given my expectation of this pattern of building a general tool and then just using some of it, the test made more sense than deleting pop in case in future we wanted to reorganize this code. also just a simple parallel example, might make sense to write a queue library that lets you take out values from the top or bottom, but so far only use one of them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks for the explanation! Makes total sense.

@snissn snissn merged commit 5e5a81b into master Sep 5, 2023
87 checks passed
@snissn snissn deleted the mikers/chore/unused branch September 5, 2023 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants