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

improvements(cli): Enable specifying default key type for adding keys #53

Merged
merged 6 commits into from
Oct 9, 2024

Conversation

MalteHerrmann
Copy link
Collaborator

@MalteHerrmann MalteHerrmann commented Oct 9, 2024

This PR adds the option to specify which key type to use by default when adding new keys using the appd keys add command.
Previously, this was defaulting to use eth_secp256k1 but this only applied to Evmos and other EVM-focussed chains. Now that we're integrating Cosmos-first chains too, we should open this up to select secp256k1 by default if desired.

Additionally, there was an error message improved and some TODOs added which I will be addressing on a follow up PR.
Again, additionally, a --remote-debugging flag is now accepted by the local_node.sh script to build and run a binary that can have a debugger attached to it via DAP.

Summary by CodeRabbit

  • New Features

    • Enhanced key management with support for specifying a default key type and behavior for adding keys.
    • Introduced a --remote-debugging flag for improved script execution and debugging capabilities.
  • Bug Fixes

    • Improved error handling and feedback for key overwrite confirmations.
  • Documentation

    • Expanded comments for clarity on new parameters and their purposes.
    • Updated changelog to reflect improvements in key management.

@MalteHerrmann MalteHerrmann requested a review from a team as a code owner October 9, 2024 09:05
@MalteHerrmann MalteHerrmann requested review from hanchon and Vvaradinov and removed request for a team October 9, 2024 09:05
Copy link

coderabbitai bot commented Oct 9, 2024

Walkthrough

The changes introduced in this pull request include modifications to several files to enhance functionality and improve user interaction. The KeyCommands function in client/keys.go now accepts additional parameters for specifying the key type and whether to use Ethereum-compatible keys by default. The RunAddCmd function in client/keys/add.go has improved error handling. In example_chain/osd/cmd/root.go, the application initialization has been refined to include the new parameters for key handling. The README and local node script have been updated to support a new --remote-debugging flag, and the changelog has been updated to reflect these improvements.

Changes

File Change Summary
client/keys.go Updated KeyCommands to accept defaultKeyType and defaultToEthKeys parameters.
client/keys/add.go Enhanced error handling and messages in RunAddCmd.
example_chain/osd/cmd/root.go Updated initRootCmd to include new parameters in the KeyCommands function call.
example_chain/README.md Added --remote-debugging flag for local node script execution.
example_chain/local_node.sh Updated to include --remote-debugging flag and refined local node setup logic.
CHANGELOG.md Added entry for improvements regarding default key type and behavior in CLI.

🐰 "In the code, new paths we pave,
With keys and nodes, our scripts behave.
From tendermint to commands anew,
A hop, a skip, for testing we flew!
With every change, our project grows,
In rabbit's dance, excitement flows!" 🐇✨


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.

@github-actions github-actions bot added the CLI label Oct 9, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
server/util.go (1)

TODO for 'comet subcommands' is not tracked in any issues or PRs.

  • Consider creating an issue to formally track the implementation of using comet subcommands and aliasing them to Tendermint.
🔗 Analysis chain

Line range hint 33-48: Improved command structure for Tendermint-related operations.

The addition of a tendermintCmd group enhances the organization of Tendermint-related subcommands, improving the overall CLI structure and user experience.

Consider updating documentation to reflect the new command structure.

To ensure a smooth transition for users, it would be beneficial to update any relevant documentation or user guides to reflect this new command grouping.

Clarify the timeline for the TODO item.

The TODO comment suggests a future update to use comet subcommands. It would be helpful to clarify the timeline or priority for this change, especially if it might impact the current implementation.

To check for any existing issues or discussions related to this TODO, you can run:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for related issues or discussions
gh issue list --search "comet subcommands"
gh pr list --search "comet subcommands"

Length of output: 86


Script:

#!/bin/bash
# Search for all occurrences of "comet subcommands" in the codebase, including comments
rg --ignore-case "comet subcommands"

# Alternatively, use ast-grep to find TODO comments related to "comet subcommands"
ast-grep --lang go --pattern $'// TODO: *comet subcommands*$'

Length of output: 207

client/keys.go (2)

22-28: LGTM! Consider creating an issue for the TODO.

The added comments and function signature change align well with the PR objectives. They provide clear context for the new defaultKeyType parameter and its recommended usage.

Regarding the TODO comment about adjusting Tendermint mentions to CometBFT, would you like me to create a GitHub issue to track this task?


59-67: LGTM! Consider extracting the key type string to a constant.

The implementation correctly sets the default key type based on the defaultKeyType parameter. The error handling for the Set operation is appropriate.

For improved readability and maintainability, consider extracting the "eth_secp256k1" string to a named constant at the package level. This would make it easier to update if needed and reduce the risk of typos. For example:

const (
    EthSecp256k1KeyType = "eth_secp256k1"
)

// Then use it in the function:
if defaultKeyType == EthSecp256k1KeyType {
    // ...
}
🧰 Tools
🪛 Gitleaks

60-60: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 02a9121 and 0f35b1b.

⛔ Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • client/keys.go (2 hunks)
  • client/keys/add.go (1 hunks)
  • example_chain/local_node.sh (1 hunks)
  • example_chain/osd/cmd/root.go (2 hunks)
  • server/util.go (1 hunks)
🧰 Additional context used
🪛 Gitleaks
client/keys.go

60-60: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (3)
server/util.go (1)

Line range hint 33-48: Summary: Improved CLI structure with minimal impact on existing functionality.

The changes introduced in this file effectively reorganize Tendermint-related commands into a more structured group. This improvement aligns well with the PR's objective of enhancing CLI functionality. The modification is focused and doesn't introduce any breaking changes to the existing codebase, making it a low-risk, high-value update.

client/keys/add.go (1)

100-100: Improved error message for key overwrite confirmation.

This change enhances the error handling by providing a more informative error message when a user aborts the key overwrite confirmation. The new message includes the name of the key being overwritten, which improves clarity and assists in debugging or user interaction scenarios.

This improvement aligns well with the PR objectives of enhancing usability for developers. It provides clearer feedback during the key management process, particularly when dealing with existing keys.

example_chain/osd/cmd/root.go (1)

27-27: Import cosmoshd is correctly added

The addition of the import statement for cosmoshd is appropriate, as it is used to specify the default key type Secp256k1Type later in the code.

example_chain/local_node.sh Outdated Show resolved Hide resolved
example_chain/osd/cmd/root.go Outdated Show resolved Hide resolved
client/keys.go Outdated Show resolved Hide resolved
client/keys.go Outdated Show resolved Hide resolved
client/keys.go Outdated Show resolved Hide resolved
example_chain/local_node.sh Outdated Show resolved Hide resolved
Copy link

@0xstepit 0xstepit left a comment

Choose a reason for hiding this comment

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

Great job @MalteHerrmann!

@MalteHerrmann MalteHerrmann enabled auto-merge (squash) October 9, 2024 11:51
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
example_chain/README.md (1)

37-37: LGTM! Consider adding more details about remote debugging.

The addition of the --remote-debugging flag is a valuable enhancement to the local node script. It provides developers with the option to build a binary suitable for remote debugging, which can be crucial for troubleshooting and development purposes.

Consider adding a brief explanation or link to documentation about how to use this flag for remote debugging. This could help developers who are not familiar with the process.

example_chain/local_node.sh (2)

68-73: LGTM: Installation process updated for remote debugging

The installation process has been correctly updated to use different build options when the --remote-debugging flag is set. This change enhances the debugging capabilities of the local node setup.

Consider adding a comment explaining the purpose of the nooptimization,nostrip options for future maintainers:

 if [[ $BUILD_FOR_DEBUG == true ]]; then
+    # Disable optimizations and preserve debug symbols for remote debugging
     make install COSMOS_BUILD_OPTIONS=nooptimization,nostrip
 else
     make install
 fi

Line range hint 202-204: LGTM: Proposal periods adjusted for local testing

The modification of proposal periods in the genesis file is a good addition for local testing. It allows for faster proposal processes, which is beneficial in a development environment.

Consider adding a comment explaining why these values are changed and that they should not be used in production:

+# Adjust proposal periods for faster local testing. Do not use these values in production.
 sed -i.bak 's/"max_deposit_period": "172800s"/"max_deposit_period": "30s"/g' "$GENESIS"
 sed -i.bak 's/"voting_period": "172800s"/"voting_period": "30s"/g' "$GENESIS"
 sed -i.bak 's/"expedited_voting_period": "86400s"/"expedited_voting_period": "15s"/g' "$GENESIS"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 69f8ef0 and 5ebd291.

📒 Files selected for processing (2)
  • example_chain/README.md (1 hunks)
  • example_chain/local_node.sh (3 hunks)
🧰 Additional context used
🔇 Additional comments (3)
example_chain/local_node.sh (3)

35-35: LGTM: New remote debugging flag implemented correctly

The addition of the BUILD_FOR_DEBUG variable and the --remote-debugging flag case in the argument parsing loop is well-implemented. This change aligns with the PR objective of improving debugging capabilities for the local node setup.

Also applies to: 55-59


Line range hint 154-158: LGTM: Genesis file modifications for token denominations

The added jq commands correctly modify the genesis file to set various token denominations to "aevmos". This ensures consistency across different modules (staking, governance, EVM, and minting) within the Evmos ecosystem.


Line range hint 1-256: Overall LGTM: Valuable improvements to local node setup

This update to the local_node.sh script introduces several valuable improvements:

  1. Addition of a --remote-debugging flag for enhanced debugging capabilities.
  2. Modification of the build process to support remote debugging when needed.
  3. Adjustment of genesis parameters, including token denominations and proposal periods, to better suit local testing environments.

These changes align well with the PR objectives and will significantly improve the developer experience when working with local Evmos nodes. The script maintains good practices in bash scripting and provides clear options for different use cases.

@MalteHerrmann MalteHerrmann merged commit 78d16bd into main Oct 9, 2024
22 of 24 checks passed
@MalteHerrmann MalteHerrmann deleted the enable-key-type-default-choice branch October 9, 2024 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants