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: let the create-validator command retrieve the loaded configuration. #2128

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

dezzeus
Copy link
Contributor

@dezzeus dezzeus commented Nov 5, 2024

Upon CLI bootstrapping, a PersistentPreRunE handler is added to the command in order to, among other things, load the configuration in a viper instance and store it into the command's context with a ViperContextKey key.

The create-validator command was using the wrong, but homonymous, ViperContextKey for retrieving the viper configuration from the command context.

As a result, the command implementation was not able to find some configuration values which were silently used as empty strings that, eventually, would halt the execution with unexpected errors.

This commit replaces the source package of the ViperContextKey key from github.com/cosmos/cosmos-sdk/client
to github.com/berachain/beacon-kit/mod/cli/pkg/context

This should also fix the issue #2122 .

Summary by CodeRabbit

  • New Features
    • Improved command for validator deposits with enhanced context management.
  • Bug Fixes
    • Enhanced error handling for input conversions during deposit message creation.

Upon CLI bootstrapping, a PersistentPreRunE handler is added to the command
in order to, among other things, load the configuration in a viper instance and
store it into the command's context with a ViperContextKey key.

The create-validator command was using the wrong, but homonymous,
ViperContextKey for retrieving the viper configuration from the command
context.

As a result, the command implementation was not able to find some configuration
values which were silently used as empty strings that, eventually, would halt
the execution with unexpected errors.

This commit replaces the source package of the ViperContextKey key
from github.com/cosmos/cosmos-sdk/client
to github.com/berachain/beacon-kit/mod/cli/pkg/context
@dezzeus dezzeus requested a review from itsdevbear as a code owner November 5, 2024 17:44
Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes in this pull request focus on the create.go file within the mod/cli/pkg/commands/deposit package. The primary modification involves replacing the dependency on the client from the Cosmos SDK with the clicontext package. This affects how application options are retrieved in the getBLSSigner function, while the overall structure and functionality of the NewCreateValidator function and command execution logic remain largely unchanged.

Changes

File Path Change Summary
mod/cli/pkg/commands/deposit/create.go - Added import for clicontext.
- Updated getBLSSigner to source AppOpts from clicontext.
- No structural changes to NewCreateValidator.

Possibly related PRs

  • chore(cli): non breaking change #1655: This PR also modifies the create.go file, updating import statements and changing how AppOpts is sourced, which is directly related to the changes made in the main PR.
  • fix(cli): Re-add create validator #2004: This PR involves the create.go file and discusses the NewCreateValidator function, which is relevant as it pertains to the command for creating validator deposits.
  • fix(cli): deposit cli args #2006: This PR adds a new command-line flag for a private key in the create.go file, which is directly related to the enhancements made in the main PR regarding command execution and user input handling.

Suggested labels

skill issue

Suggested reviewers

  • itsdevbear
  • ocnc

🐇 In the code we hop and play,
With clicontext leading the way.
The getBLSSigner now finds its tune,
As we dance with imports, morning to noon.
Validator commands, still strong and bright,
In our rabbit hole, everything feels right! 🌟


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

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 23.48%. Comparing base (50503f5) to head (8a0cd92).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
mod/cli/pkg/commands/deposit/create.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2128   +/-   ##
=======================================
  Coverage   23.48%   23.48%           
=======================================
  Files         357      357           
  Lines       16064    16064           
  Branches       12       12           
=======================================
  Hits         3772     3772           
  Misses      12121    12121           
  Partials      171      171           
Files with missing lines Coverage Δ
mod/cli/pkg/commands/deposit/create.go 0.00% <0.00%> (ø)

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66bad3e and 2e88ab1.

📒 Files selected for processing (1)
  • mod/cli/pkg/commands/deposit/create.go (2 hunks)
🔇 Additional comments (2)
mod/cli/pkg/commands/deposit/create.go (2)

27-27: LGTM: Import change aligns with PR objectives.

The switch to the project's own context package (clicontext) is the correct approach to fix the configuration retrieval issue.


Line range hint 39-163: Verify command behavior remains unchanged.

The core command functionality is preserved, which is correct. However, let's verify that the command still works with the new context implementation.

✅ Verification successful

Based on the verification results, I can now provide the final response:

Command implementation is correctly context-independent

The create-validator command implementation is properly isolated from context dependencies:

  • The command uses cobra's native command structure without relying on external context
  • No direct dependencies on cosmos-sdk client context are present
  • The command only depends on local configuration through cobra flags and the chainSpec parameter
  • BLS signer implementation is self-contained and works with local flag values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the create-validator command is properly integrated with the new context
# Expected: The command should be registered and use the new context package

# Check if the command is properly registered and its configuration
rg -A 2 "create-validator.*RunE:" 

# Verify there are no remaining references to the old cosmos-sdk client context
rg "github.com/cosmos/cosmos-sdk/client.*ContextKey"

Length of output: 90


Script:

#!/bin/bash
# Let's try a broader search to understand the command registration and context usage

# Check for create-validator command registration
rg -l "create-validator"

# Check imports in the create.go file to verify context dependencies
rg --type go -l "import \(" -A 20 "mod/cli/pkg/commands/deposit/create.go"

# Look for any cosmos-sdk context usage
rg -l "cosmos-sdk/client"

# Check for any context-related types or interfaces being used
ast-grep --pattern 'type $_ interface {
  $$$
  Context($$$) $$$
  $$$
}'

Length of output: 1102


Script:

#!/bin/bash
# Let's examine the create validator command implementation more closely

# Check the actual implementation of create validator command
rg -A 5 "func createValidatorCmd" mod/cli/pkg/commands/deposit/create.go

# Check if there are any context-related parameters or usage in the file
rg "context\.|Context" mod/cli/pkg/commands/deposit/create.go

# Check for any dependencies on client context in the deposit package
rg -l "client\.Context|ClientContext" mod/cli/pkg/commands/deposit/

# Look for any BLS signer implementation to verify context independence
ast-grep --pattern 'func getBLSSigner($$$) {
  $$$
}'

Length of output: 525

Comment on lines 166 to 169
components.BlsSignerInput{
AppOpts: client.GetViperFromCmd(cmd),
AppOpts: clicontext.GetViperFromCmd(cmd),
PrivKey: legacyKey,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

LGTM: Configuration retrieval fix implemented correctly.

The switch to clicontext.GetViperFromCmd properly fixes the configuration access issue. However, consider adding tests to verify the configuration retrieval behavior.

Would you like me to help create test cases for the configuration retrieval functionality? This would help ensure the fix remains robust against future changes.

Copy link
Collaborator

@chuck-bear chuck-bear left a comment

Choose a reason for hiding this comment

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

LGTM

@abi87 abi87 enabled auto-merge (squash) November 5, 2024 20:57
@abi87 abi87 merged commit dc8cc9e into main Nov 5, 2024
16 checks passed
@abi87 abi87 deleted the fix-create-validator-cmd branch November 5, 2024 21:44
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.

3 participants