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

fix(gov): correct queryServer and autocli functionality #725

Merged
merged 1 commit into from
Oct 10, 2024
Merged

Conversation

zakir-code
Copy link
Contributor

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

Summary by CodeRabbit

  • New Features

    • Introduced a new QueryServer type for improved query handling.
    • Added backward compatibility with a legacyQueryServer type.
    • Enhanced AppModule structure with new methods for better organization.
  • Bug Fixes

    • Streamlined test setup for governance message server implementation.
  • Chores

    • Updated internal logic for module management and query server registration.
    • Simplified instantiation of msgServer and govImpl in tests.

Copy link

coderabbitai bot commented Oct 10, 2024

Walkthrough

The pull request introduces several modifications across multiple files, primarily focusing on the restructuring of module management and the governance query server. The AutoCliOpts method in app.go now utilizes a more comprehensive module manager. The grpc_query.go file defines a new QueryServer type, enhancing the separation of concerns and backward compatibility. The test files have been updated to streamline the initialization of the msgServer, reflecting changes in how governance logic is handled. Overall, these changes enhance clarity and organization within the codebase.

Changes

File Path Change Summary
app/app.go Updated AutoCliOpts method to use app.mm.Modules instead of app.ModuleBasics. Minor formatting adjustments and comments added.
x/gov/keeper/grpc_query.go Introduced QueryServer type, updated method receivers for SwitchParams, CustomParams, and TallyResult. Added legacyQueryServer type for backward compatibility with a new TallyResult method.
x/gov/keeper/keeper_test.go Removed govkeeper import, updated msgServer initialization to use keeper.NewMsgServerImpl, and modified query server registration. Added TestCheckContractAddressIsDisabled function for new test scenarios.
x/gov/keeper/msg_server.go Changed NewMsgServerImpl signature to accept only *Keeper, simplifying msgServer instantiation. Maintained existing logic in methods like SubmitProposal and Deposit.
x/gov/module.go Restructured AppModule to embed AppModuleBasic, updated constructor, and added new methods (IsOnePerModuleType, IsAppModule, etc.). Changed variable names for clarity and modified RegisterServices method.
x/migrate/keeper/gov_test.go Simplified instantiation of govImpl by directly calling fxgovkeeper.NewMsgServerImpl. Test functions remain structurally similar, focusing on proposal submission and validation.

Possibly related PRs

🐇 In the meadow, changes bloom,
With modules dancing, making room.
From AutoCliOpts to queries anew,
Governance flows like morning dew.
A hop, a skip, we code with glee,
In every line, a rabbit's spree! 🐰✨


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.

CodeRabbit Configuration 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 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 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

@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: 3

🧹 Outside diff range and nitpick comments (5)
x/migrate/keeper/gov_test.go (1)

32-32: LGTM! Consider adding a comment for clarity.

The simplification of govImpl instantiation is a good change. It directly uses fxgovkeeper.NewMsgServerImpl, which aligns with the overall modifications mentioned in the PR summary.

Consider adding a brief comment explaining the purpose of govImpl for better code readability:

+// Create a new governance message server implementation
 govImpl := fxgovkeeper.NewMsgServerImpl(suite.App.GovKeeper)
x/gov/keeper/msg_server.go (1)

27-31: LGTM: Function signature simplified and implementation improved.

The changes to NewMsgServerImpl are well-structured and align with the PR objectives. The simplified function signature and use of govkeeper.NewMsgServerImpl(k.Keeper) improve maintainability and consistency with the Cosmos SDK.

Consider adding error handling:

 func NewMsgServerImpl(k *Keeper) types.MsgServerPro {
+	if k == nil {
+		panic("Keeper cannot be nil")
+	}
 	return &msgServer{
 		MsgServer: govkeeper.NewMsgServerImpl(k.Keeper),
 		Keeper:    k,
 	}
 }

This addition would prevent potential nil pointer dereferences if the function is called with a nil Keeper.

x/gov/keeper/keeper_test.go (1)

Line range hint 307-346: LGTM: Comprehensive test cases for CheckContractAddressIsDisabled

The new TestCheckContractAddressIsDisabled function is a well-structured addition to the test suite. It uses table-driven tests to cover various scenarios, including empty disabled list, disabled address, disabled address and method, and non-disabled cases. This comprehensive approach ensures thorough testing of the CheckContractAddressIsDisabled function.

Consider adding a test case for an invalid hex address or method ID to ensure the function handles malformed input correctly.

x/gov/keeper/grpc_query.go (2)

25-28: Consider renaming the field k for clarity

In the QueryServer struct:

type QueryServer struct {
    v1.QueryServer
    k *Keeper
}

The field k refers to the keeper instance, but using a single-letter variable can reduce readability. Consider renaming k to keeper for better clarity and consistency.


107-110: Rename field qs to avoid confusion

In the legacyQueryServer struct:

type legacyQueryServer struct {
    v1beta1.QueryServer
    qs v1.QueryServer
}

The field qs is similar to the receiver q, which may cause confusion. Consider renaming qs to queryServer for clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7f95522 and ed4d9dd.

📒 Files selected for processing (6)
  • app/app.go (1 hunks)
  • x/gov/keeper/grpc_query.go (5 hunks)
  • x/gov/keeper/keeper_test.go (1 hunks)
  • x/gov/keeper/msg_server.go (2 hunks)
  • x/gov/module.go (2 hunks)
  • x/migrate/keeper/gov_test.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (12)
x/migrate/keeper/gov_test.go (2)

77-77: LGTM! Consistent with previous change.

The simplification of govImpl instantiation is consistent with the change in TestMigrateGovInactive. This maintains uniformity across both test functions, which is a good practice.


Line range hint 1-124: Overall, the changes look good and align with the PR objectives.

The modifications in this file simplify the instantiation of the governance message server (govImpl) in both test functions. These changes:

  1. Improve code clarity by directly using fxgovkeeper.NewMsgServerImpl.
  2. Maintain consistency across both test functions.
  3. Do not alter the core functionality of the tests.

The changes align with the PR objectives of correcting queryServer and autocli functionality, specifically in the context of governance-related operations.

x/gov/keeper/msg_server.go (2)

13-13: LGTM: Import addition is appropriate.

The addition of the govkeeper import is consistent with the changes made in the NewMsgServerImpl function. This import allows the use of govkeeper.NewMsgServerImpl(), which is now being utilized in the updated implementation.


Line range hint 1-265: LGTM: Changes well-integrated with existing code.

The modifications to NewMsgServerImpl and the addition of the govkeeper import are well-integrated with the rest of the file. The existing method implementations and the msgServer struct remain unchanged and compatible with the new changes. This approach maintains the current functionality while improving the code structure.

x/gov/keeper/keeper_test.go (1)

50-53: LGTM: Simplified initialization of msgServer and queryClient

The changes to the SetupTest method streamline the initialization process by directly utilizing the keeper implementation from the fx-core module. This simplification removes the dependency on the govkeeper from cosmos-sdk and aligns with the overall refactoring of the governance module.

app/app.go (1)

Line range hint 446-452: Approved: Enhanced module iteration in AutoCliOpts

This change improves the AutoCliOpts method by iterating over app.mm.Modules instead of app.ModuleBasics. This modification ensures that all registered modules, including any additional or custom modules, are properly included in the autocli options. This aligns well with the PR objective of correcting autocli functionality.

The new implementation should provide a more comprehensive set of autocli options, potentially including modules that may not have been present in the basic module manager. This change enhances the flexibility and completeness of the autocli feature.

x/gov/keeper/grpc_query.go (2)

119-133: Ensure compatibility in TallyResult for legacy queries

In the legacyQueryServer.TallyResult method, you're converting the response to a legacy format. Verify that all fields are correctly converted and that the legacy clients receive the expected data.


Line range hint 69-104: Ensure proper error handling in TallyResult

In the TallyResult method, while handling different proposal statuses, ensure that all potential errors are properly checked and returned.

Run the following script to check for unhandled errors:

This script searches for instances where an error is assigned but not immediately checked, which could lead to unhandled errors.

x/gov/module.go (4)

85-88: Embedding AppModuleBasic and renaming variables for clarity

Embedding AppModuleBasic directly into AppModule enhances code modularity and leverages Go's embedding capabilities for cleaner interface implementation. Renaming ak and bk to accountKeeper and bankKeeper improves readability by making the variable names more descriptive.


96-99: Ensure proper initialization of AppModuleBasic

In the NewAppModule function, AppModuleBasic is initialized with an empty struct. If AppModuleBasic requires specific initialization (e.g., proposal handlers), consider invoking NewAppModuleBasic to ensure all necessary fields are properly set.

Verify if AppModuleBasic needs to be initialized with proposal handlers or other parameters. If so, update the initialization accordingly:

func NewAppModule(cdc codec.Codec, keeper *keeper.Keeper, ak govtypes.AccountKeeper, bk govtypes.BankKeeper, ss govtypes.ParamSubspace) AppModule {
    return AppModule{
-       AppModuleBasic: AppModuleBasic{},
+       AppModuleBasic: NewAppModuleBasic(/* pass necessary parameters */),
        keeper:         keeper,
        accountKeeper:  ak,
        bankKeeper:     bk,
        cdc:            cdc,
        legacySubspace: ss,
    }
}

105-110: Confirm empty method implementations for interface compliance

The methods IsOnePerModuleType and IsAppModule have empty bodies to satisfy the depinject.OnePerModuleType and appmodule.AppModule interfaces. Ensure that these methods do not require any additional logic and that empty implementations are acceptable.

Confirm that the interfaces are marker interfaces and that no further implementation is necessary.


162-162: Correct implementation of ConsensusVersion method

The ConsensusVersion method correctly returns the consensus version from the gov module. This ensures that the module's consensus version is accurately communicated during upgrades.

x/gov/keeper/grpc_query.go Show resolved Hide resolved
x/gov/keeper/grpc_query.go Show resolved Hide resolved
x/gov/module.go Show resolved Hide resolved
@zakir-code zakir-code merged commit c74e683 into main Oct 10, 2024
10 checks passed
@zakir-code zakir-code deleted the zakir/gov branch October 10, 2024 09:21
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.

1 participant