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

refactor: remove invariants #22994

Merged
merged 18 commits into from
Dec 20, 2024
Merged

refactor: remove invariants #22994

merged 18 commits into from
Dec 20, 2024

Conversation

aljo242
Copy link
Contributor

@aljo242 aljo242 commented Dec 18, 2024

Description

Closes: #22993

  • remove from modules
  • deprecate Invariant and InvariantRegistry types and associated methods (can be removed in future)

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

    • Added support for simulating nested messages.
    • Introduced functionality for importing hex keys via standard input.
    • Enhanced version command to return v2 server information.
  • Improvements

    • Upgraded RocksDB libraries.
    • Simplified testing frameworks.
  • Bug Fixes

    • Disabled async pruning in the prune command.
    • Improved error handling for out-of-gas panics in gRPC query handlers.
  • Deprecations

    • Marked several types and methods related to invariants as deprecated, including Invariant, Invariants, and InvariantRegistry.
  • Tests

    • Removed tests related to invariant registration and improved overall test coverage for module interactions.

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Warning

Rate limit exceeded

@aljo242 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8a0d167 and 34bfbae.

📒 Files selected for processing (3)
  • docs/build/building-modules/11-structure.md (0 hunks)
  • testutil/mock/types_mock_appmodule.go (0 hunks)
  • x/group/go.mod (1 hunks)
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request focuses on removing invariant-related code from various Cosmos SDK modules. The changes involve deprecating and removing invariant types, interfaces, and methods across multiple packages. The primary objective is to eliminate unused invariant functionality, particularly after the removal of the x/crisis module. The modifications span several modules, including bank, distribution, governance, group, and staking, with consistent removal of invariant-related code and deprecation of associated types and interfaces.

Changes

File Change Summary
CHANGELOG.md Updated with new entries for version v0.52.0, including deprecation of invariants
types/invariant.go Marked Invariant, Invariants, InvariantRegistry, and FormatInvariant as deprecated
Multiple x/*/module.go files Removed RegisterInvariants method from various module implementations
Multiple x/*/keeper/invariants.go files Completely removed invariant-related functions for bank, distribution, governance, group, and staking modules

Assessment against linked issues

Objective Addressed Explanation
Remove Invariants code from modules [#22993]
Deprecate Invariant types and interfaces [#22993]

Possibly related PRs

Suggested labels

C:x/authz

Suggested reviewers

  • kocubinski
  • JulianToledano
  • facundomedica
  • testinginprod
  • akhilkumarpilli

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@julienrbrt julienrbrt changed the title chore: remove invariants refactor!: remove invariants Dec 18, 2024
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

ACK. You need go run go mod tidy all script and make mocks.

We should backport this as it isn't breaking and a nice clean-up. This way this can be deleted from main afterwards.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Dec 18, 2024
@julienrbrt julienrbrt changed the title refactor!: remove invariants refactor: remove invariants Dec 18, 2024
@julienrbrt
Copy link
Member

Could you remove it as well from the structure.md documentation?

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: 0

🔭 Outside diff range comments (1)
types/module/module.go (1)

Invariant deprecation needs additional cleanup

While the code marks invariants as deprecated, there are still several active references and usages throughout the codebase that should be addressed:

  • types/invariant.go contains the core invariant types and interfaces that are marked as deprecated but still in use
  • Several modules still contain invariant-related code:
    • x/bank: Contains invariant checks in balance management
    • x/staking: Has invariant-dependent logic in slash operations
    • x/auth: Contains supply invariant references
  • Server configuration still includes invariant check period flag (FlagInvCheckPeriod)

Since invariants are being deprecated, these remaining usages should be refactored to use alternative validation mechanisms or be removed if no longer needed.

🔗 Analysis chain

Line range hint 87-399: Verify complete removal of invariant usage

Let's ensure no active usage of invariants remains in the codebase.


Let me gather more context to ensure we have a complete picture.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of invariants in the codebase

# Search for any remaining invariant registrations
echo "Checking for invariant registrations..."
rg -l "RegisterInvariants|HasInvariants" --type go

# Search for any remaining invariant implementations
echo "Checking for invariant implementations..."
ast-grep --pattern 'type $_ struct {
  $$$
}

func ($x $_) RegisterInvariants($y $_) {
  $$$
}'

Length of output: 355


Script:

#!/bin/bash
# Search for any remaining invariant-related code or references
echo "Checking for any invariant-related code..."
rg -A 5 "invariant" --type go

# Search for any remaining SDK invariant registry usage
echo "Checking for InvariantRegistry usage..."
rg -A 5 "InvariantRegistry" --type go

# Check for any remaining test files that might be using invariants
echo "Checking test files for invariant usage..."
rg -l "invariant" --type go --glob "*_test.go"

Length of output: 14319

🧹 Nitpick comments (2)
CHANGELOG.md (2)

67-68: Fix inconsistent bullet point formatting

The bullet points under "Deprecated" use inconsistent formatting - some use * while others use -. Standardize on one format for consistency.


Line range hint 2392-2396: Consider removing redundant previous changelog link

The link to previous changelog at the end appears redundant since this file already contains comprehensive history. Consider removing or updating the note.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a68f032 and 945ec98.

📒 Files selected for processing (19)
  • CHANGELOG.md (1 hunks)
  • testutil/mock/types_invariant.go (0 hunks)
  • testutil/mock/types_mock_appmodule.go (0 hunks)
  • testutil/mock/types_module_module.go (0 hunks)
  • types/invariant.go (1 hunks)
  • types/module/mock_appmodule_test.go (1 hunks)
  • types/module/module.go (2 hunks)
  • types/module/module_test.go (0 hunks)
  • x/bank/keeper/invariants.go (0 hunks)
  • x/bank/module.go (0 hunks)
  • x/distribution/keeper/invariants.go (0 hunks)
  • x/distribution/module.go (0 hunks)
  • x/gov/keeper/invariants.go (0 hunks)
  • x/gov/module.go (0 hunks)
  • x/group/keeper/invariants.go (0 hunks)
  • x/group/keeper/invariants_test.go (0 hunks)
  • x/group/module/module.go (0 hunks)
  • x/staking/keeper/invariants.go (0 hunks)
  • x/staking/module.go (0 hunks)
💤 Files with no reviewable changes (15)
  • x/gov/keeper/invariants.go
  • x/group/keeper/invariants_test.go
  • x/distribution/module.go
  • testutil/mock/types_mock_appmodule.go
  • x/gov/module.go
  • x/staking/module.go
  • x/bank/keeper/invariants.go
  • x/distribution/keeper/invariants.go
  • x/bank/module.go
  • testutil/mock/types_invariant.go
  • types/module/module_test.go
  • x/group/keeper/invariants.go
  • x/staking/keeper/invariants.go
  • x/group/module/module.go
  • testutil/mock/types_module_module.go
✅ Files skipped from review due to trivial changes (1)
  • types/invariant.go
🧰 Additional context used
📓 Path-based instructions (3)
types/module/module.go (1)

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

types/module/mock_appmodule_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"

CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

🔇 Additional comments (4)
types/module/mock_appmodule_test.go (1)

Line range hint 1-24: LGTM: Clean removal of invariant-related code

The removal of HasInvariants from the test interfaces is consistent with the deprecation of invariants across the codebase.

types/module/module.go (2)

Line range hint 87-92: LGTM: Clear deprecation notice for HasInvariants interface

The deprecation notice clearly communicates that invariants are no longer used from modules.


Line range hint 393-399: LGTM: Consistent deprecation notice for RegisterInvariants method

The deprecation notice for the method aligns with the interface deprecation.

CHANGELOG.md (1)

Line range hint 1-2396: Documentation structure and organization looks good

The CHANGELOG follows standard practices with:

  • Clear version sections
  • Categorized changes (Features, Improvements, Bug Fixes etc.)
  • PR references
  • Breaking changes clearly marked

types/invariant.go Outdated Show resolved Hide resolved
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

left one comment otherwise looks good. Love seeing code deleted

@aljo242 aljo242 enabled auto-merge December 19, 2024 17:48
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: 0

🧹 Nitpick comments (2)
CHANGELOG.md (2)

Line range hint 1-1: Add missing title to changelog

The changelog should start with a clear title like "# Changelog" at the top of the file.

+ # Changelog

Line range hint 15-25: Consider adding version comparison table

For better readability, consider adding a version comparison table at the top showing key differences between major versions.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 945ec98 and 8a0d167.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • types/invariant.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • types/invariant.go
🧰 Additional context used
📓 Path-based instructions (1)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

🔇 Additional comments (1)
CHANGELOG.md (1)

Line range hint 1-1200: LGTM on overall changelog structure and content

The changelog follows good practices:

  • Clear version sections with dates
  • Categorized changes (Features, Improvements, Bug Fixes etc.)
  • Links to PRs/issues
  • Breaking changes clearly marked
  • Detailed descriptions of changes

@julienrbrt
Copy link
Member

@aljo242 you need #22994 (review) otherwise it won't merged.
Additionally, could you do this: #22994 (comment) in here too :)

@aljo242 aljo242 added this pull request to the merge queue Dec 20, 2024
Merged via the queue into main with commit 71ddfbd Dec 20, 2024
77 of 79 checks passed
@aljo242 aljo242 deleted the chore/remove-invariants branch December 20, 2024 17:20
mergify bot pushed a commit that referenced this pull request Dec 20, 2024
Co-authored-by: Marko <[email protected]>
(cherry picked from commit 71ddfbd)

# Conflicts:
#	CHANGELOG.md
#	testutil/mock/types_mock_appmodule.go
#	x/distribution/keeper/invariants.go
#	x/group/go.mod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:x/bank C:x/distribution distribution module related C:x/gov C:x/group C:x/staking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Invariants code from modules