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

feat(client/v2): support gov proposals #18461

Merged
merged 14 commits into from
Nov 15, 2023
Merged

feat(client/v2): support gov proposals #18461

merged 14 commits into from
Nov 15, 2023

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Nov 14, 2023

Description

Closes: #18376
ref: #17222

  • Let autocli create gov proposals
  • Update autocli config of modules to support that

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

  • New Features

    • Introduced support for governance proposals across various modules, allowing users to submit proposals for updating module parameters.
    • Added new CLI commands for creating governance proposals in different modules such as auth, bank, consensus, crisis, distribution, gov, mint, slashing, and staking.
    • Implemented new flags to control command behavior, including disabling prompts and proposal submissions.
  • Enhancements

    • Improved AutoCLI functionality to automatically create governance proposals by setting a field in RpcCommandOptions.
    • Enhanced command-line interface options with additional fields for usage, description, examples, and positional arguments.
  • Bug Fixes

    • Corrected capitalization in the README heading for consistency.
    • Fixed validation functions to correctly handle sdk.Coins and URLs.
  • Documentation

    • Updated README to include tips on creating governance proposals using AutoCLI.
    • Provided usage examples and descriptions for new CLI commands related to governance proposals.
  • Refactor

    • Renamed functions and updated comments to better reflect their purpose and functionality.
  • Style

    • Standardized capitalization in documentation headings.
  • Tests

    • Added tests for new validation functions to ensure proper handling of user input.

Copy link
Contributor

coderabbitai bot commented Nov 14, 2023

Walkthrough

Walkthrough

The updates across various files introduce a new feature for governance proposals, allowing users to submit proposals to update module parameters via the CLI. This includes new commands, flags, and validation functions to support the feature. Breaking changes are made by removing address codecs from certain options, and the context now handles address codecs. The autocli package sees significant enhancements to handle government proposals, and new validation functions are added to ensure user input is correct.

Changes

File(s) Change Summary
client/v2/CHANGELOG.md Introduced support for governance proposals and API breaking changes by removing address codecs from options.
client/v2/README.md, client/v2/autocli/msg.go Added tips and handling for creating gov proposals with AutoCLI.
client/v2/autocli/flag/builder.go Modified addMessageFlags function to adjust the assignment of flagOptsByFlagName.
client/v2/autocli/msg.go, x/*/autocli.go Added new functions and commands for handling gov proposals and updating module params.
client/v2/internal/flags/flags.go, x/gov/client/cli/tx.go Introduced new flags for disabling prompts and proposal creation.
client/v2/internal/prompt/..., client/prompt_validation.go Added new validation functions and tests for user input, including non-empty, URL, and sdk.Coins validation.
x/auth/autocli.go, x/bank/autocli.go, x/consensus/autocli.go, x/crisis/autocli.go, x/distribution/autocli.go, x/gov/autocli.go, x/mint/autocli.go, x/slashing/autocli.go, x/staking/autocli.go Added or updated CLI commands and options for submitting proposals to update module parameters, marked as governance proposals.
x/upgrade/autocli.go, x/upgrade/client/cli/tx.go Modified and removed functions related to upgrade proposals, marking some as government proposals.
x/gov/client/cli/prompt.go, x/gov/client/cli/util.go Commented on using proto messages for simplification and refactored flag reading functions.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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.v2.json

@julienrbrt julienrbrt added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Nov 14, 2023
@julienrbrt julienrbrt marked this pull request as ready for review November 14, 2023 12:47
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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 98e7cae and 59acfa5.
Files selected for processing (11)
  • client/v2/internal/prompt/validation.go (1 hunks)
  • client/v2/internal/prompt/validation_test.go (1 hunks)
  • x/auth/autocli.go (1 hunks)
  • x/bank/autocli.go (2 hunks)
  • x/consensus/autocli.go (2 hunks)
  • x/crisis/autocli.go (2 hunks)
  • x/distribution/autocli.go (4 hunks)
  • x/gov/autocli.go (1 hunks)
  • x/mint/autocli.go (2 hunks)
  • x/slashing/autocli.go (1 hunks)
  • x/staking/autocli.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • client/v2/internal/prompt/validation_test.go
Additional comments: 23
x/consensus/autocli.go (2)
  • 1-11: The import of "fmt" and "github.com/cosmos/cosmos-sdk/version" is necessary for the new functionality. Ensure that these imports are used elsewhere in the file to avoid importing them unnecessarily.

  • 31-43: The addition of the GovProposal field and the new fields Use, Short, Example, and PositionalArgs are in line with the pull request's goal to enable governance proposals through the AutoCLI. Ensure that the Example field's usage of version.AppName is consistent with how the application's name should be displayed and that the PositionalArgs correctly map to the fields expected by the UpdateParams RPC method.

x/slashing/autocli.go (2)
  • 46-54: The new CLI command "update-params-proposal" is correctly flagged as a governance proposal and includes an example usage. However, ensure that the placeholder { params } in the Example field is intended to be replaced by users with actual JSON-encoded parameters. If not, consider providing a more concrete example.

  • 54-54: The GovProposal field is set to true, indicating that this command is for submitting a governance proposal. This is a key update for the feature being implemented. Ensure that the corresponding RPC method "UpdateParams" is properly implemented to handle governance proposal submissions.

x/auth/autocli.go (1)
  • 80-88: The addition of the UpdateParams RPC method with GovProposal set to true is a significant change. It allows users to submit governance proposals to update auth module parameters via the CLI. Ensure that the params argument is properly validated and that the JSON encoding is handled securely to prevent injection attacks. The Example field uses string interpolation to include the application name, which is a good practice for clarity and maintainability.
x/bank/autocli.go (3)
  • 3-10: Imports are correctly added for the new functionality.

  • 113-130: The new fields Use, Short, Example, PositionalArgs, and GovProposal are correctly added to the UpdateParams and SetSendEnabled RPC methods to support the new governance proposal feature. The use of fmt.Sprintf to generate the example commands is a good practice as it ensures consistency with the application name.

  • 126-127: The introduction of FlagOptions with use_default_for provides additional functionality for the command, allowing users to revert to default settings for a given denom. This is a thoughtful addition to the feature set.

Overall, the changes in this file align with the pull request's goal of enabling governance proposals through the AutoCLI and follow best practices for CLI command configuration.

x/crisis/autocli.go (3)
  • 1-9: The import statements have been updated to include necessary packages for the new functionality. Ensure that these packages are used in the code to avoid importing unused dependencies.

  • 24-35: The new UpdateParams RPC method has been added with appropriate fields such as Use, Short, Example, PositionalArgs, and GovProposal. Ensure that the Example field is correctly formatted and that the params placeholder in the example is intended to be replaced by actual parameters when used.

  • 30-30: The use of fmt.Sprintf to construct the example command is correct, but ensure that the version.AppName variable provides the correct application name for the command example.

client/v2/internal/prompt/validation.go (2)
  • 1-36: The new prompt package and its functions for input validation are a good addition for ensuring the integrity of user input. It's important to ensure that these functions are integrated and used wherever user input is required for the new AutoCLI governance proposal feature.

  • 30-35: The function ValidatePromptCoins uses sdk.ParseCoinsNormalized, which is appropriate for the validation of coin formats. Ensure that the sdk package's version used here supports the ParseCoinsNormalized function as expected.

x/distribution/autocli.go (6)
  • 4-10: Renaming the package from distirbuitonv1beta1 to distributionv1beta1 corrects a typo and improves readability.

  • 13-19: The AutoCLIOptions function has been updated to reflect the new RPC methods and their descriptions. Ensure that all new RPC methods are correctly implemented and that the corresponding server-side implementations are in place.

  • 79-85: The transaction (Tx) service commands have been updated with new RPC methods and descriptions. It is important to verify that these new methods are properly registered and handled in the transaction processing logic.

  • 130-135: The new UpdateParams RPC method for submitting governance proposals has been added. Ensure that the JSON encoding for the params argument is properly documented and validated, and that the governance proposal logic correctly processes these proposals.

  • 138-140: The CommunityPoolSpend RPC method has been marked as skipped due to deprecation. Confirm that this method is indeed deprecated and that any functionality it provided is covered by the new protocolpool module or equivalent.

  • 142-142: The EnhanceCustomCommand flag has been set to true. Ensure that the custom command enhancement logic is in place and that it does not introduce any unexpected behavior.

x/mint/autocli.go (4)
  • 1-9: The import statements are correctly organized and formatted according to Go conventions, with standard library imports followed by third-party packages.

  • 34-45: The new RPC command option for submitting a proposal to update mint module params is well-defined with clear usage instructions (Use), a concise description (Short), an example using fmt.Sprintf for dynamic application name insertion (Example), and the GovProposal field set to true to indicate this is a governance proposal. The PositionalArgs field is also correctly populated with a descriptor for the expected argument.

  • 38-40: Ensure that the params argument in the Example field is correctly formatted and represents a valid JSON object. The placeholder { params } should be replaced with an actual example of the JSON-encoded parameters to avoid confusion.

  • 40-40: Using fmt.Sprintf to construct the example command is a good practice as it dynamically includes the application name. However, ensure that version.AppName is correctly set and that the resulting command is tested for correctness.

x/gov/autocli.go Show resolved Hide resolved
client/v2/internal/prompt/validation.go Outdated Show resolved Hide resolved
Comment on lines 174 to 182
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_address"}, {ProtoField: "amount"}, {ProtoField: "creation_height"}},
},
{
RpcMethod: "UpdateParams",
Skip: true, // skipped because authority gated
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update staking module params. Note: params are JSON encoded",
Example: fmt.Sprintf(`%s tx staking update-params-proposal '{ params }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

The UpdateParams command has been updated to indicate it is a governance proposal. However, the example provided in line 180 is not a valid JSON structure. It would be beneficial for users to see a real-world example of the params structure in JSON format. Consider updating the example to reflect a complete and valid JSON object.

- fmt.Sprintf(`%s tx staking update-params-proposal '{ params }'`, version.AppName),
+ fmt.Sprintf(`%s tx staking update-params-proposal '{"param1":"value1", "param2":"value2"}'`, version.AppName),

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_address"}, {ProtoField: "amount"}, {ProtoField: "creation_height"}},
},
{
RpcMethod: "UpdateParams",
Skip: true, // skipped because authority gated
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update staking module params. Note: params are JSON encoded",
Example: fmt.Sprintf(`%s tx staking update-params-proposal '{ params }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_address"}, {ProtoField: "amount"}, {ProtoField: "creation_height"}},
},
{
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update staking module params. Note: params are JSON encoded",
Example: fmt.Sprintf(`%s tx staking update-params-proposal '{"param1":"value1", "param2":"value2"}'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,

Copy link
Member

@facundomedica facundomedica left a comment

Choose a reason for hiding this comment

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

uACK, a couple of nits only

client/v2/internal/prompt/validation.go Outdated Show resolved Hide resolved
x/distribution/autocli.go Outdated Show resolved Hide resolved
x/gov/autocli.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: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 59acfa5 and f4504e9.
Files selected for processing (11)
  • client/prompt_validation.go (1 hunks)
  • client/v2/internal/prompt/validation.go (1 hunks)
  • x/auth/autocli.go (1 hunks)
  • x/bank/autocli.go (2 hunks)
  • x/consensus/autocli.go (2 hunks)
  • x/crisis/autocli.go (2 hunks)
  • x/distribution/autocli.go (4 hunks)
  • x/gov/autocli.go (1 hunks)
  • x/mint/autocli.go (2 hunks)
  • x/slashing/autocli.go (1 hunks)
  • x/staking/autocli.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • client/prompt_validation.go
Additional comments: 16
x/crisis/autocli.go (3)
  • 1-9: The import statements are correctly added for the new dependencies. Ensure that these packages are used in the code to avoid importing unused packages.

  • 27-32: The new UpdateParams RPC method is added to the crisis module's AutoCLI options. The usage string, short description, and example are provided, which is good for clarity and user guidance. However, ensure that the params positional argument is correctly parsed and validated in the command implementation to prevent any issues with malformed input.

  • 30-30: The use of fmt.Sprintf to construct the example command is a good practice as it ensures that the example is always up-to-date with the current application name. However, verify that version.AppName is correctly set and that the example command is correctly formatted and tested.

x/staking/autocli.go (1)
  • 174-186: The addition of the UpdateParams command is a significant change that allows users to submit governance proposals to update staking module parameters. The usage example provided is helpful, but it should be noted that the params argument expects a JSON string. It might be beneficial to include a note about the format required for the params argument to prevent user errors. Additionally, ensure that the GovProposal field is properly handled in the command's implementation to differentiate it from regular transactions.
x/auth/autocli.go (1)
  • 80-88: The addition of the UpdateParams RPC method to the auth module's AutoCLIOptions is a significant change. It allows users to submit governance proposals to update module parameters via the CLI. The Example field provides a clear usage example, which is helpful for users to understand the expected input format. However, the comment on line 85 indicates that the entire params must be provided. It would be beneficial to clarify whether partial updates are supported and if not, to ensure that the CLI provides a clear error message when partial params are provided.

Additionally, the PositionalArgs descriptor on line 87 specifies that the params field is expected, but it's important to ensure that the CLI correctly parses and validates the JSON input to prevent any issues with malformed proposals.

Lastly, setting GovProposal to true on line 88 is a key change that should be highlighted in the documentation to inform users about the governance capabilities of this command.

x/bank/autocli.go (3)
  • 3-10: The import statements are correctly organized and necessary for the new functionality. The addition of "fmt" and "github.com/cosmos/cosmos-sdk/version" suggests that formatting and version information will be used in the new CLI commands.

  • 13-13: The comment above the AutoCLIOptions function provides a clear explanation of its purpose, which is to implement the autocli.HasAutoCLIConfig interface. This is a good practice for code readability and maintainability.

  • 110-130: The new CLI commands for governance proposals (update-params-proposal and set-send-enabled-proposal) are well-defined with usage examples and positional arguments. The use of fmt.Sprintf to include the application name in the example is a good practice for maintainability and ensures consistency across different deployments of the application.

However, ensure that the version.AppName variable is correctly set and accessible in this context. If this variable is not set or imported correctly, it could lead to runtime errors when trying to use these CLI commands.

Additionally, the FlagOptions for use-default-for in the set-send-enabled-proposal command is a good addition for usability, allowing users to revert to default settings for a given denom. Ensure that the corresponding logic to handle this flag is implemented and tested.

Lastly, the GovProposal field is set to true for both commands, which correctly flags them as governance proposals. This is a key part of the new feature and should be tested thoroughly to ensure that the proposals are created and submitted correctly.

x/distribution/autocli.go (5)
  • 4-10: The package alias distributionv1beta1 has been corrected to match the actual package name, which is a good practice for readability and to avoid confusion.

  • 127-142: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [13-140]

The AutoCLIOptions function has been updated to include new fields such as Short, Example, PositionalArgs, and GovProposal. These additions are likely to improve the user experience by providing more descriptive help messages, usage examples, and the ability to handle governance proposals directly from the CLI. However, ensure that all the examples provided in the Example fields are tested and work as expected.

  • 130-135: The UpdateParams RPC method has been added with a GovProposal field set to true, indicating that this command is intended for governance proposals. It is important to ensure that the params positional argument is correctly parsed and validated since the comment indicates that the entire params object must be provided. This could be a complex input for users to format correctly, so consider providing additional validation or parsing support if necessary.

  • 138-140: The CommunityPoolSpend RPC method is marked with Skip: true, indicating it has been deprecated in favor of protocolpool. It is crucial to communicate these deprecations clearly in the README.md and CHANGELOG.md to inform users of the changes and guide them towards the new commands.

  • 142-142: The EnhanceCustomCommand field is set to true, which suggests that there might be additional custom logic attached to the command processing. Verify that any custom command enhancements are well-documented and tested to ensure they do not introduce unexpected behavior.

x/mint/autocli.go (3)
  • 3-9: The import statements are correctly organized and necessary for the new functionality. The fmt package is used for formatting strings, and the github.com/cosmos/cosmos-sdk/version package is likely used to retrieve the application name for CLI usage examples.

  • 40-41: The use of version.AppName to dynamically generate the example command is a good practice, ensuring that the example remains accurate even if the application name changes. However, ensure that version.AppName is always set to a meaningful value to prevent confusing or incorrect examples.

  • 42-43: The PositionalArgs field is correctly used to specify that the params field is expected as a positional argument in the CLI command. The GovProposal flag is set to true, indicating that this command is for submitting governance proposals, which aligns with the pull request's goal to introduce governance proposal functionality.

Comment on lines 46 to 56
Example: fmt.Sprintf("%s tx slashing unjail --from [validator]", version.AppName),
},
{
RpcMethod: "UpdateParams",
Skip: true, // skipped because authority gated
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update slashing module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update gov module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query slashing params --output json`", version.AppName),
Example: fmt.Sprintf(`%s tx slashing update-params-proposal '{ "signed_blocks_window": "100", ... }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

The new UpdateParams command is correctly added with the GovProposal field set to true, indicating that it is a governance proposal. The usage, short description, long description, and example are provided, which is good for clarity and user guidance. However, ensure that the long description correctly references the slashing module instead of the gov module, as this might be a copy-paste error.

- Submit a proposal to update gov module params. Note: the entire params must be provided.
+ Submit a proposal to update slashing module params. Note: the entire params must be provided.

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
Example: fmt.Sprintf("%s tx slashing unjail --from [validator]", version.AppName),
},
{
RpcMethod: "UpdateParams",
Skip: true, // skipped because authority gated
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update slashing module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update gov module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query slashing params --output json`", version.AppName),
Example: fmt.Sprintf(`%s tx slashing update-params-proposal '{ "signed_blocks_window": "100", ... }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
},
Example: fmt.Sprintf("%s tx slashing unjail --from [validator]", version.AppName),
},
{
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update slashing module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update slashing module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query slashing params --output json`", version.AppName),
Example: fmt.Sprintf(`%s tx slashing update-params-proposal '{ "signed_blocks_window": "100", ... }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
},

Comment on lines 1 to 36
package prompt

import (
"fmt"
"net/url"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// ValidatePromptNotEmpty validates that the input is not empty.
func ValidatePromptNotEmpty(input string) error {
if input == "" {
return fmt.Errorf("input cannot be empty")
}

return nil
}

// ValidatePromptURL validates that the input is a valid URL.
func ValidatePromptURL(input string) error {
_, err := url.ParseRequestURI(input)
if err != nil {
return fmt.Errorf("invalid URL: %w", err)
}

return nil
}

// ValidatePromptCoins validates that the input is a valid sdk.Coins
func ValidatePromptCoins(input string) error {
if _, err := sdk.ParseCoinsNormalized(input); err != nil {
return fmt.Errorf("invalid coins: %w", err)
}

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The new validation functions introduced in the prompt package are well-defined and follow Go's idiomatic error handling. Each function provides a clear error message specific to the validation failure, which is good for debugging and user feedback. The use of %w in fmt.Errorf allows for error wrapping, which is a best practice for error handling in Go as it enables errors to be unwrapped and inspected if needed.

However, it's important to ensure that the error messages are consistent and user-friendly since they might be displayed to the end-user. For example, the message "invalid coins" in ValidatePromptCoins could be more descriptive, explaining what makes the coins invalid.

Additionally, consider adding unit tests for these functions to ensure they handle edge cases correctly, such as inputs with leading or trailing spaces, or unusual characters in URLs.

Use: "update-params-proposal [params]",
Short: "Submit a proposal to update gov module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update gov module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query gov params --output json`", version.AppName),
Example: fmt.Sprintf(`%s tx gov update-params-proposal '{ params }'`, version.AppName),
Copy link
Contributor

Choose a reason for hiding this comment

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

The example for the "update-params-proposal" command should be updated to provide a more realistic JSON structure for the params argument. This will help users understand the expected format without additional research. It seems this was previously noted and should be addressed.

- Example:        fmt.Sprintf(`%s tx gov update-params-proposal '{ params }'`, version.AppName),
+ Example:        fmt.Sprintf(`%s tx gov update-params-proposal '{"param_type": "value", ...}'`, version.AppName),

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
Example: fmt.Sprintf(`%s tx gov update-params-proposal '{ params }'`, version.AppName),
Example: fmt.Sprintf(`%s tx gov update-params-proposal '{"param_type": "value", ...}'`, version.AppName),

RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update staking module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update gov module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query staking params --output json`", version.AppName),
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a minor inconsistency in the Long description of the UpdateParams command. It mentions "gov module params" instead of "staking module params". This should be corrected to match the context of the command.

- Submit a proposal to update gov module params. Note: the entire params must be provided.
+ Submit a proposal to update staking module params. Note: the entire params must be provided.

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
Long: fmt.Sprintf("Submit a proposal to update gov module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query staking params --output json`", version.AppName),
Long: fmt.Sprintf("Submit a proposal to update staking module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query staking params --output json`", version.AppName),

Comment on lines 34 to 46
Service: mintv1beta1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "UpdateParams",
Skip: true, // skipped because authority gated
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update mint module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update gov module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query mint params --output json`", version.AppName),
Example: fmt.Sprintf(`%s tx mint update-params-proposal '{ "mint_denom": "stake", ... }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

The new UpdateParams RPC method is well-documented with usage, short and long descriptions, and an example. The use of fmt.Sprintf to include the application name in the help text is a good practice as it makes the help text dynamic and adaptable to changes in the application name. However, there is a minor inconsistency in the long description: it mentions "gov module params" instead of "mint module params". This should be corrected to avoid confusion.

- Submit a proposal to update gov module params. Note: the entire params must be provided.
+ Submit a proposal to update mint module params. Note: the entire params must be provided.

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
Service: mintv1beta1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "UpdateParams",
Skip: true, // skipped because authority gated
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update mint module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update gov module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query mint params --output json`", version.AppName),
Example: fmt.Sprintf(`%s tx mint update-params-proposal '{ "mint_denom": "stake", ... }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
},
},
},
Service: mintv1beta1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update mint module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update mint module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query mint params --output json`", version.AppName),
Example: fmt.Sprintf(`%s tx mint update-params-proposal '{ "mint_denom": "stake", ... }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
},
},
},

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f4504e9 and 17cbc97.
Files selected for processing (3)
  • x/mint/autocli.go (2 hunks)
  • x/slashing/autocli.go (1 hunks)
  • x/staking/autocli.go (1 hunks)
Additional comments: 3
x/slashing/autocli.go (3)
  • 46-46: The example provided for the unjail command is missing the --chain-id flag, which is typically required for transactions. Ensure that users are aware they need to specify the chain ID when using this command.

  • 52-52: The long description for the update-params-proposal command includes a command to view the current parameters. Ensure that the output of the query slashing params --output json command is in a format that can be directly used as input to the update-params-proposal command to avoid any confusion or additional transformation steps for the user.

  • 55-55: The GovProposal field is set to true to mark the command as a governance proposal. Ensure that the handleGovProposal function in the autocli package is properly handling this new field and that the governance proposal submission process is thoroughly tested.

Comment on lines +50 to +55
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update slashing module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update slashing module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query slashing params --output json`", version.AppName),
Example: fmt.Sprintf(`%s tx slashing update-params-proposal '{ "signed_blocks_window": "100", ... }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

The update-params-proposal command requires the entire set of parameters to be provided. This could be error-prone for users who may only want to update a single parameter. Consider providing functionality that allows for partial updates to parameters, where the user only needs to supply the parameters they wish to change, and the system merges these with the current parameters.

Comment on lines 174 to 186
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_address"}, {ProtoField: "amount"}, {ProtoField: "creation_height"}},
},
{
RpcMethod: "UpdateParams",
Skip: true, // skipped because authority gated
RpcMethod: "UpdateParams",
Use: "update-params-proposal [params]",
Short: "Submit a proposal to update staking module params. Note: the entire params must be provided.",
Long: fmt.Sprintf("Submit a proposal to update staking module params. Note: the entire params must be provided.\n See the fields to fill in by running `%s query staking params --output json`", version.AppName),
Example: fmt.Sprintf(`%s tx staking update-params-proposal '{ "unbonding_time": "504h0m0s", ... }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
},
},
EnhanceCustomCommand: true,
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 14, 2023

Choose a reason for hiding this comment

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

The addition of the UpdateParams command with GovProposal set to true is a significant change. It is important to ensure that the params positional argument is properly validated before being processed to prevent any malformed input from causing issues. Additionally, the documentation provided in the Long description is helpful, but it should also mention any restrictions or formats required for the params JSON object. This will help users understand how to structure their proposals correctly.

Moreover, the Example field provides a good starting point, but it might be beneficial to include a more complete example that shows a typical params object structure. This would give users a clearer idea of what a full proposal might look like.

Lastly, the EnhanceCustomCommand field set to true at the end of the Tx descriptor implies that there might be additional custom logic associated with these commands. It would be prudent to review any such custom logic to ensure it aligns with the new functionality and does not introduce any security or stability issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will be improved later, where fields will be directly flag options or positional arguments (#18310), then the json won't be necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

@julienrbrt Understood, I look forward to the enhancements detailed in issue #18310. This approach will indeed streamline the user experience by allowing direct input of parameters as flags or positional arguments, eliminating the need for JSON structuring. If there are any interim updates or documentation improvements needed before this change is implemented, please let me know how I can assist.

@julienrbrt
Copy link
Member Author

Now that I want to backport this in the next version of client/v2 I will get the issue of bumping the api module again the v0.50...

Short: "Submit a proposal to update auth module params. Note: the entire params must be provided.",
Example: fmt.Sprintf(`%s tx auth update-params-proposal '{ "max_memo_characters": 0, "tx_sig_limit": 0, "tx_size_cost_per_byte": 0, "sig_verify_cost_ed25519": 0, "sig_verify_cost_secp256k1": 0 }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
Copy link
Member

Choose a reason for hiding this comment

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

this is optional, if the authority is set to an multsig how would this change the flow of logic here?

Copy link
Member

Choose a reason for hiding this comment

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

is there a flag allowing users to set this to false?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can add a flag and skip the gov proposal. I initially didn't do it, as it already didn't existed, but we can easily support this yes.

Copy link
Member Author

@julienrbrt julienrbrt Nov 14, 2023

Choose a reason for hiding this comment

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

Majority of users will have their module authority be gov so that's why it's done like 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 17cbc97 and e329e20.
Files selected for processing (3)
  • client/v2/README.md (2 hunks)
  • client/v2/autocli/msg.go (5 hunks)
  • client/v2/internal/flags/flags.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • client/v2/README.md
  • client/v2/internal/flags/flags.go
Additional comments: 5
client/v2/autocli/msg.go (5)
  • 120-126: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [120-130]

The context is being set on the command, but it's not clear if this context is being used properly downstream. Ensure that the context set here is being utilized in all subsequent calls that require a context, especially since it's being overwritten with a new value containing the client.ClientContextKey.

  • 152-165: The code is using a custom address codec to convert the signer's address from bytes to a string. This is a critical operation and should be handled with care. Ensure that the address codec is thoroughly tested, especially for edge cases and invalid inputs.

  • 187-189: The proto.Merge function is used to merge the input message into a new dynamic message. This is necessary because the SDK only supports proto v1 messages, while AutoCLI uses proto v2 messages. Ensure that this conversion does not lose any information or introduce any inconsistencies.

  • 203-210: The command's usage is silenced, which is a common practice for subcommands to avoid cluttering the output. However, ensure that this does not hinder the user experience, especially when it comes to understanding how to use the command or troubleshooting errors.

  • 215-252: The handleGovProposal function is setting the authority field of the message to the gov module address and creating a gov proposal. This is a significant change in behavior and should be carefully reviewed to ensure that it aligns with the intended governance proposal flow. Additionally, the error messages should be clear and informative to aid in debugging.

Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Thanks Julien, just some minor drive-by comments.

client/prompt_validation.go Outdated Show resolved Hide resolved
client/v2/autocli/msg.go Outdated Show resolved Hide resolved
client/v2/autocli/msg.go Outdated 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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e329e20 and 75863fa.
Files selected for processing (3)
  • client/prompt_validation.go (1 hunks)
  • client/v2/autocli/msg.go (5 hunks)
  • client/v2/internal/prompt/validation.go (1 hunks)
Additional comments: 6
client/v2/internal/prompt/validation.go (1)
  • 1-36: The new prompt package and its functions for input validation are well-defined and follow good coding practices. The use of fmt.Errorf to wrap underlying errors with additional context is particularly good for debugging and user feedback. Ensure that these functions are being used wherever user input is accepted in the CLI to maintain consistency.
client/v2/autocli/msg.go (5)
  • 123-125: The context is being set on the command, but it's not clear if this context is being used properly downstream. Ensure that the context set here is being propagated and utilized in all subsequent calls that require a context.

  • 152-165: The code is checking if the address field is empty and then setting it to the signer's address. This is a good use of default values, but ensure that this behavior is documented and expected by the users of the function. If the address field is supposed to be set by the caller, this might override their input unexpectedly.

  • 187-189: The proto.Merge function is used to merge the input message into a new dynamic message. This is necessary because the SDK only supports proto v1 messages, while AutoCLI uses proto v2 messages. Ensure that this conversion does not lead to any data loss or transformation issues.

  • 203-210: The command is being configured to not show usage on error if it's a subcommand. This is a common pattern for CLI tools to avoid cluttering the output with usage text when the error is not related to command syntax. The addition of governance proposal flags is also a good practice to allow users to control the behavior of the command.

  • 215-253: The handleGovProposal function is setting the authority field to the governance module address and creating a governance proposal. This is a critical piece of functionality that should be thoroughly tested to ensure that it behaves correctly. The error handling and message setting seem appropriate, but it's important to ensure that the governance proposal is created with all the necessary information and that any errors are handled gracefully.

Comment on lines 47 to 53
return fmt.Errorf("invalid address: %w", err)
}

// ValidatePromptYesNo validates that the input is valid sdk.COins
// ValidatePromptCoins validates that the input contains valid sdk.Coins
func ValidatePromptCoins(input string) error {
if _, err := sdk.ParseCoinsNormalized(input); err != nil {
return fmt.Errorf("invalid coins: %w", err)
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 15, 2023

Choose a reason for hiding this comment

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

The change from sdk.COins to sdk.Coins corrects a typo in the function ValidatePromptCoins, ensuring that the function checks for valid sdk.Coins objects. This is a necessary fix for the function to work correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

lol. Changing a comment does not change the function behavior :D

Copy link
Contributor

Choose a reason for hiding this comment

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

@julienrbrt You're absolutely right, updating the comment itself doesn't alter the function's behavior. The correction was made to ensure that the comment accurately reflects what the function does, which is important for code readability and maintainability. If there's anything else that needs attention in the code or comments, please let me know!

@julienrbrt julienrbrt added this pull request to the merge queue Nov 15, 2023
Merged via the queue into main with commit 9c3386f Nov 15, 2023
76 of 79 checks passed
@julienrbrt julienrbrt deleted the julien/gov-autocli branch November 15, 2023 11:30
mergify bot pushed a commit that referenced this pull request Nov 15, 2023
(cherry picked from commit 9c3386f)

# Conflicts:
#	client/v2/CHANGELOG.md
#	client/v2/autocli/msg.go
#	client/v2/go.mod
#	client/v2/go.sum
#	go.mod
#	go.sum
#	simapp/go.mod
#	tests/go.mod
#	tests/starship/tests/go.mod
#	x/accounts/go.mod
#	x/auth/go.mod
#	x/auth/go.sum
#	x/authz/go.mod
#	x/bank/autocli.go
#	x/bank/go.mod
#	x/bank/go.sum
#	x/circuit/go.mod
#	x/circuit/go.sum
#	x/distribution/go.mod
#	x/distribution/go.sum
#	x/evidence/go.mod
#	x/evidence/go.sum
#	x/feegrant/go.mod
#	x/feegrant/go.sum
#	x/gov/go.mod
#	x/group/go.mod
#	x/group/go.sum
#	x/mint/go.mod
#	x/mint/go.sum
#	x/nft/go.mod
#	x/nft/go.sum
#	x/params/go.mod
#	x/params/go.sum
#	x/protocolpool/go.mod
#	x/protocolpool/go.sum
#	x/slashing/go.mod
#	x/slashing/go.sum
#	x/staking/go.mod
#	x/staking/go.sum
#	x/upgrade/client/cli/tx.go
#	x/upgrade/go.mod
#	x/upgrade/go.sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve support authority-gated/gov proposal commands in AutoCLI
4 participants