Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sh-cha
Copy link
Contributor

@sh-cha sh-cha commented May 8, 2025

close #397

@sh-cha sh-cha self-assigned this May 8, 2025
@sh-cha sh-cha requested a review from a team as a code owner May 8, 2025 09:23
@coderabbitai
Copy link

coderabbitai bot commented May 8, 2025

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • client/docs/statik/statik.go
⛔ Files ignored due to path filters (1)
  • client/docs/swagger-ui/swagger.yaml is excluded by !**/*.yaml

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

A new "SimulateProposal" feature was introduced to the governance module, allowing simulation of proposal execution without committing state changes. This includes updates to the protobuf service, CLI commands, utility parsing functions, and the query server to process, simulate, and return gas and execution results for proposed governance messages. Additionally, delegation-related request messages in the staking module were extended with a new Status field for filtering by bond status. Several protobuf-generated files across multiple modules were updated to add imports and refresh raw descriptor data without API changes.

Changes

File(s) Change Summary
proto/initia/gov/v1/query.proto Added SimulateProposal RPC, request/response messages, and necessary imports to the Query service.
x/gov/client/cli/query.go Added the simulate-proposal CLI query command for simulating governance proposals from a JSON file.
x/gov/client/cli/util.go Introduced parseSubmitProposal utility to parse and decode proposal messages from a file.
x/gov/keeper/custom_grpc_query.go Implemented SimulateProposal method in CustomQueryServer to simulate proposal messages and return results/gas info.
x/gov/keeper/custom_grpc_query_test.go Added test Test_CustomGrpcQuerier_SimulateProposal validating simulation success and failure scenarios.
api/initia/gov/v1/query.pulsar.go Added protobuf messages and RPC method implementation for SimulateProposal with full reflection support.
api/initia/mstaking/v1/query.pulsar.go Added Status string field to delegation-related request messages for filtering by bond status.
api/initia/mstaking/v1/staking.pulsar.go Added import for amino protobuf dependency and updated raw protobuf descriptor data.
api/initia/mstaking/v1/tx.pulsar.go Updated protobuf raw descriptor data for staking transaction messages with no API changes.
api/initia/move/v1/types.pulsar.go Added import for cosmos-proto and updated raw protobuf descriptor data.
api/initia/move/v1/tx.pulsar.go Updated protobuf raw descriptor data for move transaction messages with no API changes.
api/initia/reward/v1/query.pulsar.go Added amino and cosmos-proto imports and updated protobuf descriptor metadata.
api/initia/reward/v1/types.pulsar.go Added cosmos-proto import and updated protobuf descriptor data for reward module types.
api/initia/distribution/v1/distribution.pulsar.go Added cosmos-proto import and updated protobuf descriptor data for distribution module.
api/initia/dynamicfee/v1/types.pulsar.go Added cosmos-proto import and updated protobuf descriptor data for dynamic fee types.
x/gov/keeper/common_test.go Changed bank message server registration in test setup to use movebank.NewMsgServerImpl.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant QueryServer
    participant Keeper
    participant CosmosSDK

    User->>CLI: Run 'simulate-proposal' with proposal.json
    CLI->>CLI: Parse proposal file into MsgSubmitProposal
    CLI->>QueryServer: Query SimulateProposal(MsgSubmitProposal)
    QueryServer->>Keeper: Unpack and iterate proposal messages
    loop For each message
        Keeper->>CosmosSDK: Find handler, simulate execution
        CosmosSDK-->>Keeper: Return result or error
    end
    Keeper->>QueryServer: Collect gas info and results
    QueryServer->>CLI: Return QuerySimulateProposalResponse
    CLI->>User: Print simulation results
Loading

Poem

In the warren of governance, a rabbit now knows,
How to simulate proposals before the real show.
Gas and results, with no state to commit,
Hop through the messages—each one a perfect fit!
With a nibble of JSON and a twitch of the nose,
Simulate, celebrate, see how your proposal goes!
🥕✨


🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 sequence diagram to generate a sequence diagram of the changes in this 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.

@github-actions
Copy link

github-actions bot commented May 8, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

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

🧹 Nitpick comments (4)
proto/initia/gov/v1/query.proto (1)

137-140: Docstring/field name mismatch

The comment says // result is the result of the simulation. while the field is plural results. Either use result (singular) or pluralise the comment to keep documentation consistent.

x/gov/client/cli/util.go (1)

33-38: Minor: reuse loop variable and avoid re-shadowing error

err := ... inside the loop shadows the outer err, losing context if needed later. You can reuse the variable safely:

-    var msg sdk.Msg
-    err := cdc.UnmarshalInterfaceJSON(anyJSON, &msg)
+    var msg sdk.Msg
+    err = cdc.UnmarshalInterfaceJSON(anyJSON, &msg)
x/gov/keeper/custom_grpc_query.go (2)

176-179: Preserve panic information

You replace the actual panic with a generic message, losing valuable debugging info. Capture it instead:

if r := recover(); r != nil {
    err = fmt.Errorf("panic executing msg %d: %v", msgIndex, r)
}

203-209: GasWanted set to gas limit of an ‘infinite’ meter – may always be zero

GasWanted is taken from sdkCtx.GasMeter().Limit(). For gRPC queries the meter is often InfiniteGasMeter, whose limit is zero. Consider computing wanted gas as the sum of GasUsed or exposing a realistic value from cache context.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0415b0 and 05c52b6.

⛔ Files ignored due to path filters (2)
  • x/gov/types/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/gov/types/query.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
📒 Files selected for processing (4)
  • proto/initia/gov/v1/query.proto (3 hunks)
  • x/gov/client/cli/query.go (2 hunks)
  • x/gov/client/cli/util.go (1 hunks)
  • x/gov/keeper/custom_grpc_query.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
x/gov/client/cli/query.go (1)
app/const.go (1)
  • AppName (15-15)
x/gov/keeper/custom_grpc_query.go (1)
x/gov/keeper/keeper.go (1)
  • Keeper (23-65)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: golangci-lint
  • GitHub Check: Run test and upload codecov
  • GitHub Check: Analyze (go)

@codecov
Copy link

codecov bot commented May 8, 2025

Codecov Report

Attention: Patch coverage is 21.21212% with 104 lines in your changes missing coverage. Please review.

Project coverage is 40.10%. Comparing base (c0415b0) to head (0181966).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
x/gov/client/cli/query.go 0.00% 75 Missing ⚠️
x/gov/client/cli/util.go 0.00% 20 Missing ⚠️
x/gov/keeper/custom_grpc_query.go 75.67% 6 Missing and 3 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #400      +/-   ##
==========================================
- Coverage   40.19%   40.10%   -0.10%     
==========================================
  Files         294      295       +1     
  Lines       27547    27679     +132     
==========================================
+ Hits        11072    11100      +28     
- Misses      14772    14873     +101     
- Partials     1703     1706       +3     
Files with missing lines Coverage Δ
x/gov/keeper/custom_grpc_query.go 49.24% <75.67%> (+10.29%) ⬆️
x/gov/client/cli/util.go 0.00% <0.00%> (ø)
x/gov/client/cli/query.go 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

🧹 Nitpick comments (4)
api/initia/gov/v1/query.pulsar.go (2)

6-8: Prefer a clearer alias than v1beta11 for the ABCI dependency

The alias v1beta11 is non-intuitive and easy to confuse with v1beta1, which is already imported in the same file for pagination types.
Using a semantic alias (e.g. abci or abciV1) greatly improves readability and avoids future mix-ups.

-import (
-    _ "cosmossdk.io/api/amino"
-    v1beta11 "cosmossdk.io/api/cosmos/base/abci/v1beta1"
+import (
+    _ "cosmossdk.io/api/amino"
+    abci "cosmossdk.io/api/cosmos/base/abci/v1beta1"  // clearer alias

6153-6157: Doc-comment is singular, field is plural – keep them consistent

The comment still reads “result is the result of the simulation.” but the proto field was renamed to results and is a repeated list.
Update the comment to avoid confusion for client developers and API users.

-// result is the result of the simulation.
-Results []*v1beta11.Result `protobuf:"bytes,2,rep,name=results,proto3" json:"results,omitempty"`
+// results are the execution results of the simulation for each message.
+Results []*v1beta11.Result `protobuf:"bytes,2,rep,name=results,proto3" json:"results,omitempty"`
api/initia/mstaking/v1/query.pulsar.go (2)

15664-15672: Duplicate “Redelegations” RPCs may confuse clients

The service descriptor now exposes both Redelegations and RedelegationsOfDelegator, but they share the same request/response types. Unless there is a clear semantic difference, keeping both endpoints will:

  • Break gRPC‐REST gateway generation (duplicate HTTP paths).
  • Require extra client-side maintenance.
  • Increase API surface without functional gain.

Please confirm that both names are needed; otherwise drop the obsolete one or alias it only at the CLI layer.


6279-6285: Minor performance nit – marshal order

During marshalling the code serialises Status after the unknownFields blob.
While functionally correct, the Protobuf wire format prefers known fields first; this keeps streaming encoders simpler and can save a small copy when unknownFields is large.

Not critical (generated file), just flagging in case the generator template can be tweaked.

Also applies to: 11649-11655

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 05c52b6 and e6f6527.

⛔ Files ignored due to path filters (4)
  • api/initia/gov/v1/query_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • api/initia/mstaking/v1/query_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/gov/types/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/gov/types/query.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
📒 Files selected for processing (11)
  • api/initia/distribution/v1/distribution.pulsar.go (2 hunks)
  • api/initia/dynamicfee/v1/types.pulsar.go (2 hunks)
  • api/initia/gov/v1/query.pulsar.go (7 hunks)
  • api/initia/move/v1/tx.pulsar.go (1 hunks)
  • api/initia/move/v1/types.pulsar.go (2 hunks)
  • api/initia/mstaking/v1/query.pulsar.go (31 hunks)
  • api/initia/mstaking/v1/staking.pulsar.go (2 hunks)
  • api/initia/mstaking/v1/tx.pulsar.go (2 hunks)
  • api/initia/reward/v1/query.pulsar.go (2 hunks)
  • api/initia/reward/v1/types.pulsar.go (2 hunks)
  • proto/initia/gov/v1/query.proto (3 hunks)
✅ Files skipped from review due to trivial changes (6)
  • api/initia/reward/v1/query.pulsar.go
  • api/initia/move/v1/tx.pulsar.go
  • api/initia/dynamicfee/v1/types.pulsar.go
  • api/initia/move/v1/types.pulsar.go
  • api/initia/distribution/v1/distribution.pulsar.go
  • api/initia/mstaking/v1/tx.pulsar.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • proto/initia/gov/v1/query.proto
🧰 Additional context used
🧬 Code Graph Analysis (1)
api/initia/gov/v1/query.pulsar.go (1)
api/initia/gov/v1/gov.pulsar.go (6)
  • Proposal (5228-5280)
  • Proposal (5295-5295)
  • Proposal (5298-5300)
  • TallyResult (5166-5177)
  • TallyResult (5192-5192)
  • TallyResult (5195-5197)
🔇 Additional comments (6)
api/initia/reward/v1/types.pulsar.go (2)

7-7: Import addition enhances protobuf support

The import of the cosmos-proto package is added for its side effects, which likely includes registering custom type encoders, validators, or protobuf extensions necessary for the simulation endpoint functionality.


792-838: Improved type metadata for decimal fields

The protobuf descriptor updates properly annotate release_rate and dilution_rate as cosmos.Dec types with appropriate YAML annotations. This ensures these fields are correctly serialized and deserialized in the governance proposal simulation process. The changes align with modern Cosmos SDK conventions by migrating from legacy import paths to the newer cosmos-proto standard.

api/initia/mstaking/v1/staking.pulsar.go (2)

5-5: Import for Amino appears consistent with protobuf regeneration.

The added import of cosmossdk.io/api/amino is consistent with the protobuf code regeneration approach seen throughout this PR. This is a side-effect import (using _) which ensures Amino's init function runs but doesn't expose the package's identifiers directly.


13961-14302: Binary descriptor update aligns with protobuf regeneration.

The updated protobuf raw descriptor data reflects the regenerated protobuf code with updated dependencies and options, including references to the newly imported Amino package. While this is machine-generated code, the update pattern is consistent with similar changes seen across other modules.

These mechanical updates maintain consistency with the broader protobuf regeneration pattern while not changing the API surface or functionality of the staking module.

api/initia/gov/v1/query.pulsar.go (1)

4683-4693: Generated code looks correct – no functional issues spotted

The fast-reflection scaffolding for QuerySimulateProposalRequest has the expected descriptor wiring and unknown-field handling.
No action needed here.

api/initia/mstaking/v1/query.pulsar.go (1)

5929-5941: Generated code – no manual edits detected

All descriptor wiring for the new status field looks correct (field number, indexes, reflection helpers).
No action required.

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

♻️ Duplicate comments (1)
x/gov/keeper/custom_grpc_query.go (1)

167-169: ⚠️ Potential issue

Nil-request guard missing

Similar to other query methods in this file, the implementation should check for nil requests at the beginning to prevent panics:

func (q CustomQueryServer) SimulateProposal(ctx context.Context, req *customtypes.QuerySimulateProposalRequest) (*customtypes.QuerySimulateProposalResponse, error) {
+   if req == nil || req.MsgSubmitProposal == nil {
+       return nil, status.Error(codes.InvalidArgument, "request cannot be nil")
+   }
    results := make([]sdk.Result, 0, len(req.MsgSubmitProposal.GetMessages()))
🧹 Nitpick comments (3)
x/gov/keeper/custom_grpc_query.go (3)

175-184: Improve panic recovery error message

The panic recovery mechanism is good, but the error message could be more informative to aid debugging:

defer func() {
    if r := recover(); r != nil {
-       err = fmt.Errorf("panic from msg %d", msgIndex)
+       err = fmt.Errorf("panic from msg %d: %v", msgIndex, r)
    }
}()

185-196: Consider adding message type details to error messages

When a message is invalid or has no handler, adding the message type to the error would help with debugging:

var msg sdk.Msg
err := q.Keeper.cdc.UnpackAny(anyMsg, &msg)
if err != nil {
-   return nil, status.Errorf(codes.InvalidArgument, "invalid message %d", msgIndex)
+   return nil, status.Errorf(codes.InvalidArgument, "invalid message %d: %s", msgIndex, err.Error())
}

handler := q.Keeper.router.Handler(msg)
if handler == nil {
-   return nil, status.Errorf(codes.InvalidArgument, "invalid message %d", msgIndex)
+   return nil, status.Errorf(codes.InvalidArgument, "no handler for message %d of type %T", msgIndex, msg)
}

167-211: Consider exposing simulation logs

The current implementation returns results and gas information but doesn't expose the logs generated during simulation. These logs can be valuable for debugging proposal execution:

return &customtypes.QuerySimulateProposalResponse{
    GasInfo: sdk.GasInfo{
        GasWanted: cacheCtx.GasMeter().Limit(),
        GasUsed:   cacheCtx.GasMeter().GasConsumed(),
    },
    Results: results,
+   // Consider adding logs from the cached context if available
}, nil
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 56f93ec and 9b56741.

📒 Files selected for processing (2)
  • x/gov/client/cli/query.go (2 hunks)
  • x/gov/keeper/custom_grpc_query.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/gov/client/cli/query.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
x/gov/keeper/custom_grpc_query.go (2)
api/initia/gov/v1/query.pulsar.go (6)
  • QuerySimulateProposalRequest (6112-6118)
  • QuerySimulateProposalRequest (6133-6133)
  • QuerySimulateProposalRequest (6136-6138)
  • QuerySimulateProposalResponse (6148-6157)
  • QuerySimulateProposalResponse (6172-6172)
  • QuerySimulateProposalResponse (6175-6177)
x/gov/keeper/keeper.go (1)
  • Keeper (23-65)
🔇 Additional comments (2)
x/gov/keeper/custom_grpc_query.go (2)

172-174: Good use of CacheContext

The implementation correctly uses a cached context to prevent actual state changes during simulation, which is crucial for a simulation endpoint.


197-202: Robust execution flow

The code properly uses the cached context when executing handlers and handles errors appropriately. This ensures simulations don't affect the actual blockchain state.

Copy link
Member

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

LGTM

@beer-1 beer-1 added the enhancement New feature or request label May 9, 2025
@beer-1 beer-1 changed the title add simulation endpoint for gov proposal feat: add simulation endpoint for gov proposal May 9, 2025
@beer-1 beer-1 merged commit d2e4b37 into main May 9, 2025
9 checks passed
@beer-1 beer-1 deleted the feat/proposal-msg-simulation branch May 9, 2025 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: dry run field on MsgSubmitProposal of gov module

2 participants