cosmos / interchain-security

Replicated security (aka interchain security V1) is an open sourced IBC application which allows cosmos blockchains to lease their proof-of-stake security to one another.
https://cosmos.github.io/interchain-security/
Other
152 stars 108 forks source link

feat!: store the minimal power to be in the top N on EndBlock #1977

Closed bermuell closed 2 weeks ago

bermuell commented 2 weeks ago

backport of (#1952)

This reverts commit 575cfd3ccec7732e0d1488d80bda7f6172110cf7.

Please go to the Preview tab and select the appropriate sub-template:

Summary by CodeRabbit

coderabbitai[bot] commented 2 weeks ago
Walkthrough ## Walkthrough The recent changes enhance the handling of the minimum power requirement for a validator to be in the top N validators on a consumer chain. This includes refactoring query logic, updating error handling, and introducing new functions for setting, getting, and deleting minimum power in the `Keeper` struct. Test cases and migration logic have also been updated to ensure consistent functionality. ## Changes | Files/Groups | Change Summary | |-----------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------| | `x/ccv/provider/keeper/grpc_query.go` | Refactored to enhance querying for minimum power in the top N, including error logging improvements. | | `x/ccv/provider/keeper/grpc_query_test.go` | Added `pk.SetMinimumPowerInTopN` call in the `TestGetConsumerChain` function. | | `x/ccv/provider/keeper/keeper.go` | Introduced `SetMinimumPowerInTopN`, `GetMinimumPowerInTopN`, and `DeleteMinimumPowerInTopN` functions. | | `x/ccv/provider/keeper/keeper_test.go` | Added `TestMinimumPowerInTopN` function to test new minimum power functions. | | `x/ccv/provider/keeper/legacy_proposal.go` | Updated `HandleLegacyConsumerModificationProposal` to include handling of new top N value. | | `x/ccv/provider/keeper/partial_set_security.go` | Renamed and updated function to `ComputeMinPowerInTopN`. | | `x/ccv/provider/keeper/partial_set_security_test.go` | Updated test function names to align with new minimum power in top N logic. | | `x/ccv/provider/keeper/proposal.go` | Modified `StopConsumerChain` to call `DeleteMinimumPowerInTopN` and updated top N logic in `MakeConsumerGenesis`. | | `x/ccv/provider/keeper/relay.go` | Renamed and added relevant functions related to minimum power in top N. | | `x/ccv/provider/migrations/migrator.go`, `x/ccv/provider/migrations/v6/migrations.go` | Updated migration functions to handle the new minimum power logic for consumer chains. | | `x/ccv/provider/types/keys.go`, `x/ccv/provider/types/keys_test.go` | Added new constants and functions for handling minimum power in top N keys. |

Recent review details **Configuration used: .coderabbit.yml** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 134de6af51c77885e60baa79ecb3f44c423d2f81 and 680b291eb39e86ae2da137b4f152f01f61f109b6.
Files selected for processing (13) * x/ccv/provider/keeper/grpc_query.go (2 hunks) * x/ccv/provider/keeper/grpc_query_test.go (1 hunks) * x/ccv/provider/keeper/keeper.go (1 hunks) * x/ccv/provider/keeper/keeper_test.go (1 hunks) * x/ccv/provider/keeper/legacy_proposal.go (1 hunks) * x/ccv/provider/keeper/partial_set_security.go (2 hunks) * x/ccv/provider/keeper/partial_set_security_test.go (3 hunks) * x/ccv/provider/keeper/proposal.go (2 hunks) * x/ccv/provider/keeper/relay.go (1 hunks) * x/ccv/provider/migrations/migrator.go (1 hunks) * x/ccv/provider/migrations/v6/migrations.go (1 hunks) * x/ccv/provider/types/keys.go (2 hunks) * x/ccv/provider/types/keys_test.go (1 hunks)
Additional context used
Path-based instructions (13)
x/ccv/provider/migrations/v6/migrations.go (1) Pattern `**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/ccv/provider/migrations/migrator.go (1) Pattern `**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/ccv/provider/keeper/legacy_proposal.go (1) Pattern `**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/ccv/provider/types/keys_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"
x/ccv/provider/keeper/grpc_query_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"
x/ccv/provider/keeper/partial_set_security.go (1) Pattern `**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/ccv/provider/keeper/grpc_query.go (1) Pattern `**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/ccv/provider/keeper/relay.go (1) Pattern `**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/ccv/provider/types/keys.go (1) Pattern `**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/ccv/provider/keeper/proposal.go (1) Pattern `**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/ccv/provider/keeper/partial_set_security_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"
x/ccv/provider/keeper/keeper_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"
x/ccv/provider/keeper/keeper.go (1) Pattern `**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (7)
x/ccv/provider/migrations/migrator.go (1)
`57-61`: The function `Migrate5to6` effectively orchestrates multiple migration steps. Ensure comprehensive testing, particularly integration tests, to verify the correct migration of both minimal power settings and legacy parameters.
x/ccv/provider/types/keys_test.go (1)
`64-64`: The addition of `MinimumPowerInTopNBytePrefix` to the test `TestNoDuplicates` ensures that the new key prefix does not conflict with existing ones. Good proactive testing approach.
x/ccv/provider/types/keys.go (2)
`186-188`: The new byte prefix for storing minimum power for top N validators is correctly defined and follows existing naming and structuring conventions. --- `620-622`: The function `MinimumPowerInTopNKey` is correctly implemented to generate keys using the new byte prefix and chain IDs. It adheres to the established patterns in this file.
x/ccv/provider/keeper/proposal.go (1)
`180-180`: The addition of `k.DeleteMinimumPowerInTopN(ctx, chainID)` in the `StopConsumerChain` function is crucial for ensuring that all related data is cleaned up when a consumer chain is stopped. This avoids potential data integrity issues with stale entries.
x/ccv/provider/keeper/keeper_test.go (1)
`835-863`: The new test function `TestMinimumPowerInTopN` adequately covers the functionality for setting, retrieving, and updating the minimum power in top N validators. It also correctly handles edge cases, such as non-existent chain IDs.
x/ccv/provider/keeper/keeper.go (1)
`1576-1584`: **Properly handle deletion operations.** The method `DeleteMinimumPowerInTopN` is straightforward and correctly deletes the minimum power entry from the store. This method is crucial for cleanup operations and appears to be implemented correctly. No changes are necessary here.
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@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 as 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. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.