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: Add node flag to WASM queries (build-address) #2194

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GunanshuJoshi
Copy link

@GunanshuJoshi GunanshuJoshi commented Oct 21, 2024

Description

This PR adds a new --node flag to support custom endpoints for node connections while making Wasm queries specifically build-address. This update ensures that the provenanced q wasm build-address command works correctly with custom node configurations.

Issue:

While creating the predictable contract address I encountered the following error:

unknown flag: --node

This occurred when running the following command:

provenanced query wasm build-address <code-hash> <creator-address> <salt> --node https://rpc.test.provenance.io:443

It seems the flag is not being recognized properly. I suspect there might be an issue with either the flag registration in the command definition (root.go) or how the CLI parser processes the command.

The main file updated is:

  • cmd/provenanced/cmd/root.go

closes: n/a
I haven't created any particular issue for this change. However, this was discussed on Discord, where it was agreed that the node flag should function correctly.
Reference: Discord conversation.


Checklist

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
    (I haven't created any issue for this minor fix.)
  • Wrote unit and integration tests (see Testing Guidelines).
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant GoDoc comments (GoDoc Documentation).
  • Added relevant changelog entries under .changelog/unreleased (see Adding Changes).
  • Re-reviewed Files changed in the Github PR explorer.
  • Reviewed Codecov report in the comment section below once CI passes.

Summary by CodeRabbit

  • New Features

    • Introduced new command flags for custom denomination and message fee floor price.
    • Added a flag to specify the node connection for enhanced configurability.
  • Improvements

    • Enhanced error handling for better user experience.
    • Updated command initialization to prevent misleading usage information.
    • Improved telemetry configuration for better flexibility.
  • Miscellaneous Adjustments

    • Removed shorthand options for conflicting flags and ensured correct command aliasing.

@GunanshuJoshi GunanshuJoshi requested a review from a team as a code owner October 21, 2024 16:41
Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

Walkthrough

The changes in this pull request focus on enhancing the command-line interface of the cmd/provenanced/cmd/root.go file. Key updates include the addition of new command flags for custom denomination and message fee floor price, improvements to error handling, and refinements in command initialization. The logic for telemetry configuration has been encapsulated for better flexibility, and minor adjustments have been made to flag handling and command aliases. Overall, these modifications aim to improve usability and robustness in command-line operations.

Changes

File Path Change Summary
cmd/provenanced/cmd/root.go - Added persistent flags: config.CustomDenomFlag, config.CustomMsgFeeFloorPriceFlag, and flags.FlagNode.
- Improved error handling in newApp function.
- Updated initRootCmd to manage command initialization and error handling.
- Enhanced overwriteFlagDefaults for flag value precedence.
- Encapsulated telemetry configuration in getTelemetryGlobalLabels.
- Removed shorthand options for conflicting flags and adjusted command aliases.
- Updated method signatures for NewRootCmd, Execute, queryCommand, and txCommand.

Poem

In the land of code where rabbits play,
New flags and features come out to stay.
With error handling fine-tuned just right,
Our command-line hops into the night!
So gather 'round, let’s cheer and sing,
For robust commands and the joy they bring! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0bf059c and 8e5cc8e.

📒 Files selected for processing (1)
  • cmd/provenanced/cmd/root.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
cmd/provenanced/cmd/root.go (1)

225-225: Verify Proper Handling of the --node Flag in Query Subcommands

Ensure that all query subcommands correctly utilize the --node flag to connect to the specified node endpoint. This includes verifying that the custom node address is properly passed to any underlying clients or services used by these subcommands.

Run the following script to find usages of the client.GetNodeContext function in query commands, which should respect the --node flag:

@@ -222,6 +222,7 @@ func queryCommand() *cobra.Command {
)

cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
cmd.PersistentFlags().String(flags.FlagNode, "","The node to connect to (IP:Port)")
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 21, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider Adding the --node Flag to the Root Command for Consistency

While adding the --node flag to the queryCommand enhances configurability for query operations, users may also benefit from specifying custom nodes for other commands, such as transactions or status checks. To provide a consistent user experience across all commands, consider adding the --node flag to the root command. This ensures that the custom node endpoint is available globally and aligns with common CLI practices.

Apply this diff to add the --node flag to the root command in the Execute function:

 func Execute(rootCmd *cobra.Command) error {
     // existing code...
     rootCmd.PersistentFlags().BoolP(config.EnvTypeFlag, "t", false, "Indicates this command should use the testnet configuration (default: false [mainnet])")
     rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic)")
     rootCmd.PersistentFlags().String(flags.FlagLogFormat, cmtconfig.LogFormatPlain, "The logging format (json|plain)")
+    rootCmd.PersistentFlags().String(flags.FlagNode, "", "The node to connect to (IP:Port)")

     // existing code...
     executor := cmtcli.PrepareBaseCmd(rootCmd, "", app.DefaultNodeHome)
     return executor.ExecuteContext(ctx)
 }

Committable suggestion was skipped due to low confidence.

Copy link
Member

@iramiller iramiller Oct 21, 2024

Choose a reason for hiding this comment

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

This is not the correct way to approach this. Each command will add the appropriate flags using the collection found with flags.AddTxFlagsToCmd(cmd) if they are required. They should not be individually added as indicated here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@iramiller, thank you for the clarification. You're absolutely correct that flags should be added to each command using flags.AddTxFlagsToCmd(cmd) instead of individually adding them. I'll keep this in mind for future reviews.

(_/)
(•‿•)?


✏️ Learnings added
Learnt from: iramiller
PR: provenance-io/provenance#2194
File: cmd/provenanced/cmd/root.go:225-225
Timestamp: 2024-10-21T17:12:02.195Z
Learning: When adding flags in `cmd/provenanced/cmd/root.go`, use `flags.AddTxFlagsToCmd(cmd)` for each command to add the appropriate flags, instead of individually adding flags to the root command.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@@ -222,6 +222,7 @@ func queryCommand() *cobra.Command {
)

cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
cmd.PersistentFlags().String(flags.FlagNode, "","The node to connect to (IP:Port)")
Copy link
Member

Choose a reason for hiding this comment

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

Generally speaking each command will have flags.AddQueryFlagsToCmd(cmd) added (as appropriate). As one example the server.QueryBlockCmd() already registers the required flag.

@SpicyLemon
Copy link
Contributor

SpicyLemon commented Oct 21, 2024

The query wasm build-address command does not add the standard AddQueryFlagsToCmd to it because it doesn't actually attempt to communicate with a node; it just runs some local calculations to output the desired result. So there's no need to provide a --node flag to it because it doesn't use a node; there's nothing in the command's code (defined in the wasmd library) that looks for the flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants