-
Couldn't load subscription status.
- Fork 242
feat: add simulation endpoint for gov proposal #400
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
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. 💤 Files selected but had no reviewable changes (1)
⛔ Files ignored due to path filters (1)
You can disable this status message by setting the 📝 WalkthroughWalkthroughA 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 Changes
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
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this 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 mismatchThe comment says
// result is the result of the simulation.while the field is pluralresults. Either useresult(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 outererr, 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 informationYou 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
GasWantedis taken fromsdkCtx.GasMeter().Limit(). For gRPC queries the meter is oftenInfiniteGasMeter, whose limit is zero. Consider computing wanted gas as the sum ofGasUsedor exposing a realistic value from cache context.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
x/gov/types/query.pb.gois excluded by!**/*.pb.go,!**/*.pb.gox/gov/types/query.pb.gw.gois 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 ReportAttention: Patch coverage is
Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
There was a problem hiding this 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 thanv1beta11for the ABCI dependencyThe alias
v1beta11is non-intuitive and easy to confuse withv1beta1, which is already imported in the same file for pagination types.
Using a semantic alias (e.g.abciorabciV1) 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 consistentThe comment still reads “result is the result of the simulation.” but the proto field was renamed to
resultsand 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 clientsThe service descriptor now exposes both
RedelegationsandRedelegationsOfDelegator, 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 orderDuring marshalling the code serialises
Statusafter theunknownFieldsblob.
While functionally correct, the Protobuf wire format prefers known fields first; this keeps streaming encoders simpler and can save a small copy whenunknownFieldsis 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
⛔ Files ignored due to path filters (4)
api/initia/gov/v1/query_grpc.pb.gois excluded by!**/*.pb.go,!**/*.pb.goapi/initia/mstaking/v1/query_grpc.pb.gois excluded by!**/*.pb.go,!**/*.pb.gox/gov/types/query.pb.gois excluded by!**/*.pb.go,!**/*.pb.gox/gov/types/query.pb.gw.gois 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 supportThe 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 fieldsThe protobuf descriptor updates properly annotate
release_rateanddilution_rateascosmos.Dectypes 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/aminois 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 spottedThe fast-reflection scaffolding for
QuerySimulateProposalRequesthas 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 detectedAll descriptor wiring for the new
statusfield looks correct (field number, indexes, reflection helpers).
No action required.
There was a problem hiding this 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 issueNil-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 messageThe 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 messagesWhen 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 logsThe 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
📒 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 CacheContextThe implementation correctly uses a cached context to prevent actual state changes during simulation, which is crucial for a simulation endpoint.
197-202: Robust execution flowThe code properly uses the cached context when executing handlers and handles errors appropriately. This ensures simulations don't affect the actual blockchain state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
close #397