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(client/v2): fix marshalling of queries with any #18309

Merged
merged 10 commits into from
Nov 3, 2023
Merged

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Oct 30, 2023

Description

ref: #18256

While investigating #18256 I have noticed that doing the following, after having submitted a proposal without amino annotations, would lead to the following:

$ simd q gov proposal 1
cannot marshal response proposal:{id:1  messages:{[/cosmos.protocolpool.v1.MsgCommunityPoolSpend]:{authority:"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"  recipient:"cosmos13fmxs08hvt6k2hez7vlk6qsgllykcumvp5u65z"}}  status:PROPOSAL_STATUS_DEPOSIT_PERIOD  final_tally_result:{yes_count:"0"  abstain_count:"0"  no_count:"0"  no_with_veto_count:"0"}  submit_time:{seconds:1698686061  nanos:741926444}  deposit_end_time:{seconds:1698858861  nanos:741926444}  total_deposit:{denom:"stake"  amount:"10000"}  metadata:"ipfs://CID"  title:"autocli test"  summary:"testing"  proposer:"cosmos1acmdqwzyglh0fyh4u8sdsgp8ej50hfeafsy40d"}: message /cosmos.protocolpool.v1.MsgCommunityPoolSpend is packed into an any field, so requires an amino.name annotation

In the backported PR, x/tx changes will be reverted as x/tx is tagged from main. x/tx v0.12 will be tagged once this PR is merged.


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
  • added ! to 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
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • 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.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

Refactor:

  • Updated the FileResolver field in the Builder struct to use appOptions.ClientCtx.InterfaceRegistry instead of proto.HybridResolver, enhancing the type of FileResolver field.
  • Improved the marshalAny and marshalDynamic functions by removing the named variable and error check, and introducing the enc.beginMarshal function with an additional boolean argument.

New Features:

  • Enhanced the encoder in version v0.12.0 to default amino types to the message type URL.
  • Added a new function getMessageAminoNameAny that returns the amino name of a message or the message URL if the URL is not available.

Style:

  • Made formatting changes in the Marshal function in the Encoder struct.

Chores:

  • Removed the import of github.com/cosmos/gogoproto/proto package in client/v2/autocli/app.go.
  • Added a new import statement for the package "github.com/cosmos/gogoproto/proto" in x/tx/signing/aminojson/options.go.

@julienrbrt julienrbrt added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Oct 30, 2023
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2023

Warning

Rate Limit Exceeded

@julienrbrt has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 18 minutes and 2 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. 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 repository.
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 Files that changed from the base of the PR and between c47bb5d and af6046e.

Walkthrough

The changes primarily revolve around the update and improvement of the encoder in the project. The encoder now defaults amino types to the message type URL. The modifications also include changes in the handling of Any messages, function signatures, and import statements.

Changes

File Path Summary
client/v2/autocli/app.go The import of github.com/cosmos/gogoproto/proto package is removed. The FileResolver field of the Builder struct is changed from proto.HybridResolver to appOptions.ClientCtx.InterfaceRegistry.
x/tx/CHANGELOG.md Version v0.12.0 includes an improvement that updates the encoder so that amino types default to the message type URL.
x/tx/signing/aminojson/any.go
x/tx/signing/aminojson/json_marshal.go
Changes in the marshalAny and marshalDynamic functions. The named variable and the associated error check have been removed. The beginMarshal function is called with an additional boolean argument set to true. The Marshal function in the Encoder struct is modified to handle the new isAny parameter.
x/tx/signing/aminojson/options.go A new import statement for the package "github.com/cosmos/gogoproto/proto" is introduced. The function getMessageAminoName now accepts a protoreflect.Message parameter instead of proto.Message. A new function getMessageAminoNameAny is added.

Poem

🍂 As the leaves fall this November, 🍁
Code changes we shall always remember. 📝
Encoder updates, oh so fine, 🌟
Making our codebase truly shine. 💫
Celebrate the changes, big and small, 🎉
In the world of code, they matter to us all. 💻
So here's to the devs, working day and night, 🌞🌜
Making sure every bit is just right. 👌
As we hop into the season of giving, 🎁
Let's appreciate the joy of coding and living! 🐇🥕


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.json

@julienrbrt julienrbrt marked this pull request as ready for review November 1, 2023 12:18
@julienrbrt julienrbrt requested a review from a team as a code owner November 1, 2023 12:18
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 630836e and 104193a.
Files ignored due to filter (2)
  • client/v2/go.mod
  • x/tx/go.mod
Files selected for processing (5)
  • client/v2/autocli/app.go (2 hunks)
  • x/tx/CHANGELOG.md (1 hunks)
  • x/tx/signing/aminojson/any.go (2 hunks)
  • x/tx/signing/aminojson/json_marshal.go (2 hunks)
  • x/tx/signing/aminojson/options.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • x/tx/CHANGELOG.md
  • x/tx/signing/aminojson/any.go
Additional comments: 7
client/v2/autocli/app.go (2)
  • 1-6: The import of github.com/cosmos/gogoproto/proto package has been removed. Ensure that this package is not used elsewhere in the file.

  • 65-71: The FileResolver field of the Builder struct has been changed from proto.HybridResolver to appOptions.ClientCtx.InterfaceRegistry. This implies a change in the type of appOptions.ClientCtx.InterfaceRegistry. Ensure that this change is compatible with the rest of the codebase.

x/tx/signing/aminojson/options.go (3)
  • 2-8: The new import statement for the package "github.com/cosmos/gogoproto/proto" is introduced. Ensure that this package is included in your dependencies.

  • 16-24: The function getMessageAminoName now accepts a protoreflect.Message parameter instead of proto.Message. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 29-46: The function getMessageAminoNameAny now accepts a protoreflect.Message parameter instead of proto.Message and returns a string instead of a string and a boolean. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

x/tx/signing/aminojson/json_marshal.go (2)
  • 156-162: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [156-171]

The Marshal function has been updated to include a false argument in the beginMarshal function call. This change is likely due to the addition of the isAny parameter in the beginMarshal function. Ensure that this change does not affect other parts of the codebase that use the Marshal function.

  • 173-187: The beginMarshal function now accepts an additional isAny parameter. This parameter is used to determine how the name and named variables are set. If isAny is true, the getMessageAminoNameAny function is used to set name and named is set to true. Otherwise, the getMessageAminoName function is used to set name and named. This change allows for different handling of the message based on whether it is an Any message or not. Ensure that this change does not affect other parts of the codebase that use the beginMarshal function.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 630836e and 104193a.
Files ignored due to filter (2)
  • client/v2/go.mod
  • x/tx/go.mod
Files selected for processing (5)
  • client/v2/autocli/app.go (2 hunks)
  • x/tx/CHANGELOG.md (1 hunks)
  • x/tx/signing/aminojson/any.go (2 hunks)
  • x/tx/signing/aminojson/json_marshal.go (2 hunks)
  • x/tx/signing/aminojson/options.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • x/tx/CHANGELOG.md
  • x/tx/signing/aminojson/any.go
Additional comments: 7
client/v2/autocli/app.go (2)
  • 1-6: The removal of the github.com/cosmos/gogoproto/proto package import is fine as long as there are no references to it in the rest of the file.

  • 65-71: The change of FileResolver from proto.HybridResolver to appOptions.ClientCtx.InterfaceRegistry changes the type of FileResolver. Ensure that all usages of FileResolver are compatible with the new type.

- FileResolver:          proto.HybridResolver,
+ FileResolver:          appOptions.ClientCtx.InterfaceRegistry,
x/tx/signing/aminojson/json_marshal.go (2)
  • 156-160: The Marshal function has been updated to include a new isAny parameter in the beginMarshal function call. This allows for different handling of the message based on whether it is an Any message or not. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 173-187: The beginMarshal function has been updated to handle the new isAny parameter and determine the name and named values accordingly. This change allows for different handling of the message based on whether it is an Any message or not. The named variable and associated error check have been removed, and the enc.beginMarshal function is now called with an additional boolean argument.

x/tx/signing/aminojson/options.go (3)
  • 2-8: The new import statement for the package "github.com/cosmos/gogoproto/proto" is introduced. Ensure that this package is included in your dependencies.

  • 14-24: The function getMessageAminoName has been updated to accept a protoreflect.Message parameter instead of proto.Message. This change should be reflected wherever this function is called.

- func getMessageAminoName(msg proto.Message) (string, bool) {
+ func getMessageAminoName(msg protoreflect.Message) (string, bool) {
  • 26-46: A new function getMessageAminoNameAny has been added. This function returns the amino name of a message if it has been set by the amino.name option, or the message URL if it cannot get the URL. This function seems to be a more flexible version of getMessageAminoName and could be used in cases where the amino name might not be set.
func getMessageAminoNameAny(msg protoreflect.Message) string {
	messageOptions := msg.Descriptor().Options()
	if proto.HasExtension(messageOptions, amino.E_Name) {
		name := proto.GetExtension(messageOptions, amino.E_Name)
		return name.(string)
	}

	msgURL := "/" + string(msg.Descriptor().FullName())
	if msgURL != "/" {
		return msgURL
	}

	if m, ok := msg.(gogoproto.Message); ok {
		return "/" + gogoproto.MessageName(m)
	}

	return ""
}

Copy link
Contributor

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -66,7 +65,7 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error {
builder := &Builder{
Builder: flag.Builder{
TypeResolver: protoregistry.GlobalTypes,
FileResolver: proto.HybridResolver,
FileResolver: appOptions.ClientCtx.InterfaceRegistry,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why favouring interface registry over the proto.HybridResolver?

x/tx/signing/aminojson/options.go Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 104193a and e54a39d.
Files ignored due to filter (1)
  • client/v2/go.mod
Files selected for processing (1)
  • x/tx/signing/aminojson/options_test.go (1 hunks)
Additional comments: 1
x/tx/signing/aminojson/options_test.go (1)
  • 1-30: The tests are well written and cover the main functionality of the functions they are testing. They also handle both positive and negative cases. Good job on that.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e54a39d and c47bb5d.
Files selected for processing (1)
  • client/debug/main.go (1 hunks)
Additional comments: 1
client/debug/main.go (1)
  • 86-92: The cobra.ExactArgs(1) ensures that the command requires exactly one argument. This is a good practice for command-line tools as it provides a clear interface for the user.

@julienrbrt julienrbrt added this pull request to the merge queue Nov 3, 2023
Merged via the queue into main with commit 2caf00d Nov 3, 2023
60 of 61 checks passed
@julienrbrt julienrbrt deleted the julien/autocli-any branch November 3, 2023 10:20
mergify bot pushed a commit that referenced this pull request Nov 3, 2023
(cherry picked from commit 2caf00d)

# Conflicts:
#	client/debug/main.go
#	client/v2/autocli/app.go
#	client/v2/go.mod
#	x/tx/CHANGELOG.md
#	x/tx/signing/aminojson/json_marshal.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release C:CLI C:x/tx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants