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

chore: remove unused local variables #22340

Merged
merged 4 commits into from
Oct 23, 2024
Merged

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Oct 23, 2024

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Enhanced error logging for key-value store iterator closure.
    • Improved test coverage for cache and mempool functionalities, including new test cases for transaction ordering and cache behavior.
  • Bug Fixes

    • Streamlined logic for handling delegations in the staking keeper.
  • Tests

    • Added multiple new test functions for CacheKVStore and priority nonce mempool.
    • Improved validation logic and concurrency tests for transaction handling.
  • Documentation

    • Updated comments and documentation for clarity in test cases and methods.

Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

📝 Walkthrough

Walkthrough

The pull request introduces modifications across several files in a Go project. Key changes include an update to the .golangci.yml configuration file to alter linter settings, specifically regarding the usage of local variables. The simapp/export.go file sees the removal of a counter variable in the prepForZeroHeightGenesis method, along with enhanced error logging. The test files store/cachekv/store_test.go and types/mempool/priority_nonce_test.go have been updated with new test cases and improved validation logic. Additionally, the x/staking/keeper/query_utils.go file has been modified to streamline the GetAllDelegatorDelegations method.

Changes

File Change Summary
.golangci.yml Added local-variables-are-used: false under the unused section.
simapp/export.go Removed counter variable from prepForZeroHeightGenesis method; enhanced error logging for iterator closure; retained existing error handling mechanisms.
store/cachekv/store_test.go Added new test functions for CacheKVStore, expanded iterator tests, included checks for panic conditions, introduced random operation tests, refined assertions.
types/mempool/priority_nonce_test.go Added new test cases for transaction ordering; simplified validateOrder function; refined transaction replacement logic; enhanced concurrency tests; improved random transaction generation.
x/staking/keeper/query_utils.go Removed variable i from GetAllDelegatorDelegations method; updated return statement to directly return the delegations slice.

Possibly related PRs

Suggested reviewers

  • lucaslopezf
  • sontrinh16
  • aaronc
  • testinginprod
  • julienrbrt

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1d804cc and 16bfedd.

📒 Files selected for processing (1)
  • types/mempool/priority_nonce_test.go (0 hunks)
💤 Files with no reviewable changes (1)
  • types/mempool/priority_nonce_test.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
.golangci.yml (1)

123-123: Add newline at end of file

Add a newline character at the end of the file to follow POSIX standards and common best practices.

   unused:
     local-variables-are-used: false
+
🧰 Tools
🪛 yamllint

[error] 123-123: no new line character at the end of file

(new-line-at-end-of-file)

types/mempool/priority_nonce_test.go (2)

Line range hint 598-609: Correct grammatical errors in function comments

The comments within the validateOrder function contain grammatical errors that affect readability:

  • "Then if t2.sender have the same sender" should be "Then if t1 and t2 have the same sender".
  • "t3.n < t2.n" should likely be "t3.n < t2.n or t3.n <= t2.n" for consistency.
  • The sentence structures can be improved for clarity.

Consider revising the comments as follows:

  // Given two transactions t1 and t2, where t2.p > t1.p but t2.i < t1.i,
- // Then if t2.sender have the same sender then t2.nonce > t1.nonce
- // or
- // If t1 and t2 have different senders then there must be some t3 with
- // t3.sender == t2.sender and t3.n < t2.n and t3.p <= t1.p
+ // then if t1 and t2 have the same sender, t2.nonce should be greater than t1.nonce.
+ // If t1 and t2 have different senders, then there must be some transaction t3 with
+ // t3.sender == t2.sender, t3.n < t2.n, and t3.p <= t1.p.

Line range hint 93-185: Refactor duplicated test code in TestPriorityNonceTxOrderWithAdapter and TestPriorityNonceTxOrder

The test functions TestPriorityNonceTxOrderWithAdapter and TestPriorityNonceTxOrder have significant duplication in their setup and execution logic. Refactoring shared code into helper functions or methods will reduce redundancy, enhance readability, and make future maintenance easier.

Also applies to: 186-274

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8fa3090 and 1d804cc.

📒 Files selected for processing (6)
  • .golangci.yml (1 hunks)
  • schema/indexer/start.go (1 hunks)
  • simapp/export.go (0 hunks)
  • store/cachekv/store_test.go (0 hunks)
  • types/mempool/priority_nonce_test.go (1 hunks)
  • x/staking/keeper/query_utils.go (0 hunks)
💤 Files with no reviewable changes (3)
  • simapp/export.go
  • store/cachekv/store_test.go
  • x/staking/keeper/query_utils.go
🧰 Additional context used
📓 Path-based instructions (2)
schema/indexer/start.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

types/mempool/priority_nonce_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

🪛 yamllint
.golangci.yml

[error] 123-123: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
schema/indexer/start.go (1)

123-123: LGTM! Improved error wrapping.

The change from %v to %w verb in fmt.Errorf is a good improvement as it properly wraps the original error, allowing better error handling and stack trace preservation up the call chain. This follows Go's error handling best practices.

Comment on lines +122 to +123
unused:
local-variables-are-used: false
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Reconsider disabling unused local variable checks

This change appears to contradict the PR's objective of removing unused local variables. Setting local-variables-are-used: false will prevent the linter from detecting unused variables, which could lead to code quality issues and dead code accumulation in the future.

Consider removing these lines to maintain strict checking for unused variables:

-  unused:
-    local-variables-are-used: false
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
unused:
local-variables-are-used: false
🧰 Tools
🪛 yamllint

[error] 123-123: no new line character at the end of file

(new-line-at-end-of-file)

@@ -588,6 +588,7 @@ func validateOrder(mtxs []sdk.Tx) error {
}
}
}
_ = iterations
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Unused variable 'iterations' should be removed

The variable iterations in the validateOrder function is declared but never used in a meaningful way. Assigning _ = iterations is unnecessary and only suppresses the compiler warning. Considering the PR's objective to remove unused local variables, it's better to remove the variable entirely to clean up the code.

Apply the following diff to eliminate the unused variable:

 func validateOrder(mtxs []sdk.Tx) error {
-   iterations := 0
     var itxs []txSpec
     for i, mtx := range mtxs {
-     iterations++
       tx := mtx.(testTx)
       itxs = append(itxs, txSpec{p: int(tx.priority), n: int(tx.nonce), a: tx.address, i: i})
     }

     // Existing logic...

-   _ = iterations
     // fmt.Printf("validation in iterations: %d\n", iterations)
     return nil
 }

Committable suggestion was skipped due to low confidence.

schema/indexer/start.go Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the C:schema label Oct 23, 2024
@tac0turtle tac0turtle added this pull request to the merge queue Oct 23, 2024
Merged via the queue into cosmos:main with commit 1515856 Oct 23, 2024
72 of 75 checks passed
@zakir-code zakir-code deleted the zakir/unused branch October 23, 2024 08:50
@julienrbrt
Copy link
Member

@Mergifyio backport release/v0.52.x

Copy link
Contributor

mergify bot commented Oct 23, 2024

backport release/v0.52.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Oct 23, 2024
(cherry picked from commit 1515856)

# Conflicts:
#	store/cachekv/store_test.go
julienrbrt added a commit that referenced this pull request Oct 23, 2024
Co-authored-by: zakir <80246097+zakir-code@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
alpe added a commit that referenced this pull request Oct 25, 2024
* main: (157 commits)
  feat(core): add ConfigMap type (#22361)
  test: migrate e2e/genutil to systemtest (#22325)
  feat(accounts): re-introduce bundler (#21562)
  feat(log): add slog-backed Logger type (#22347)
  fix(x/tx): add feePayer as signer (#22311)
  test: migrate e2e/baseapp to integration tests (#22357)
  test: add x/circuit system tests (#22331)
  test: migrate e2e/tx tests to systemtest (#22152)
  refactor(simdv2): allow non-comet server components (#22351)
  build(deps): Bump rtCamp/action-slack-notify from 2.3.1 to 2.3.2 (#22352)
  fix(server/v2): respect context cancellation in start command (#22346)
  chore(simdv2): allow overriding the --home flag (#22348)
  feat(server/v2): add SimulateWithState to AppManager (#22335)
  docs(x/accounts): improve comments (#22339)
  chore: remove unused local variables (#22340)
  test: x/accounts systemtests (#22320)
  chore(client): use command's configured output (#22334)
  perf(log): use sonic json lib  (#22233)
  build(deps): bump x/tx (#22327)
  fix(x/accounts/lockup): fix proto path (#22319)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants