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(cosmovisor): Add prepare-upgrade cmd #21972

Merged
merged 10 commits into from
Oct 1, 2024

Conversation

lucaslopezf
Copy link
Contributor

@lucaslopezf lucaslopezf commented Sep 29, 2024

Description

Closes: #10910


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, you can find examples of the prefixes below:
  • confirmed ! in 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
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced the prepare-upgrade command to automate upgrade preparation, including downloading and verifying upgrade binaries.
    • Added the cosmovisor show-upgrade-info command to display relevant upgrade information.
  • Improvements

    • Enhanced init and config commands to support custom configuration file paths.
    • Updated documentation to include details about new commands and their functionalities.
    • Added support for specifying the gRPC address through an environment variable.
  • Bug Fixes

    • Resolved permission issues with the add-upgrade command and improved output parsing.

Copy link
Contributor

coderabbitai bot commented Sep 29, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce new commands and enhancements to the cosmovisor tool, specifically the prepare-upgrade and show-upgrade-info commands. The prepare-upgrade command automates the preparation for software upgrades by downloading and verifying upgrade binaries, while the show-upgrade-info command displays relevant upgrade details. Additionally, modifications to existing commands improve configuration handling and usability.

Changes

File Change Summary
tools/cosmovisor/CHANGELOG.md Updated to include new features, improvements, and bug fixes; added prepare-upgrade and show-upgrade-info commands.
tools/cosmovisor/README.md Added documentation for the prepare-upgrade command, including usage and logging details.
tools/cosmovisor/cmd/cosmovisor/prepare_upgrade.go Introduced prepare-upgrade command to download and verify upgrade binaries, with logging functionality.
tools/cosmovisor/args.go Added GRPCAddress field to Config struct and environment variable for gRPC address configuration.

Assessment against linked issues

Objective Addressed Explanation
Prepare for the next upgrade by downloading binaries and verifying checksums (#10910)
Print upgrade name and upgrade time (#10910)

Possibly related PRs

Suggested labels

C:x/upgrade, Type: CI

Suggested reviewers

  • tac0turtle
  • julienrbrt
  • cool-develope
  • facundomedica
  • sontrinh16

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.

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 C:Cosmovisor Issues and PR related to Cosmovisor label Sep 29, 2024
@tac0turtle
Copy link
Member

looks good, sorry misread the pr. didnt mean to approve

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

🧹 Outside diff range and nitpick comments (4)
tools/cosmovisor/cmd/cosmovisor/root.go (1)

23-23: LGTM! Consider grouping related commands.

The addition of NewPrepareUpgradeCmd() aligns well with the PR objectives and follows the existing naming convention. Good job!

For improved readability and maintenance, consider grouping related commands together. For instance, you could place NewPrepareUpgradeCmd() next to other upgrade-related commands like NewAddUpgradeCmd() and NewShowUpgradeInfoCmd().

 		NewVersionCmd(),
 		NewAddUpgradeCmd(),
 		NewShowUpgradeInfoCmd(),
-		NewPrepareUpgradeCmd(),
+		NewPrepareUpgradeCmd(),
tools/cosmovisor/CHANGELOG.md (1)

39-42: LGTM! Consider grouping related features.

The new entries in the "Unreleased" section are well-formatted and provide clear information about the changes. Great job!

Consider grouping the two "Features" sections together for better readability. You can move the "Improvements" section between the two "Features" entries up, so all features are listed consecutively.

tools/cosmovisor/README.md (1)

21-21: Adjust indentation in table of contents

The new entry "Preparing for an Upgrade" should be indented to match the level of other entries in this section.

Please update the indentation as follows:

-    * [Preparing for an Upgrade](#preparing-for-an-upgrade)
+      * [Preparing for an Upgrade](#preparing-for-an-upgrade)
🧰 Tools
🪛 Markdownlint

21-21: Expected: 8; Actual: 4
Unordered list indentation

(MD007, ul-indent)

tools/cosmovisor/cmd/cosmovisor/prepare_upgrade.go (1)

17-19: Consider improving the formatting of the long description

The Long description contains a multiline string. For better readability and to adhere to Go formatting conventions, consider adjusting the string formatting to maintain consistent indentation and line breaks.

Apply this diff to adjust the formatting:

 Long: `Prepare for the next upgrade by downloading and verifying the upgrade binary.
 This command will download the binary specified in the upgrade-info.json file,
 verify its checksum, and place it in the appropriate directory for Cosmovisor to use.`,
+Long: `Prepare for the next upgrade by downloading and verifying the upgrade binary.

+This command will download the binary specified in the upgrade-info.json file,
+verify its checksum, and place it in the appropriate directory for Cosmovisor to use.`,
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d5f24de and db7a212.

📒 Files selected for processing (4)
  • tools/cosmovisor/CHANGELOG.md (2 hunks)
  • tools/cosmovisor/README.md (2 hunks)
  • tools/cosmovisor/cmd/cosmovisor/prepare_upgrade.go (1 hunks)
  • tools/cosmovisor/cmd/cosmovisor/root.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
tools/cosmovisor/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

tools/cosmovisor/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

tools/cosmovisor/cmd/cosmovisor/prepare_upgrade.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

tools/cosmovisor/cmd/cosmovisor/root.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🪛 Markdownlint
tools/cosmovisor/README.md

21-21: Expected: 8; Actual: 4
Unordered list indentation

(MD007, ul-indent)

🔇 Additional comments (3)
tools/cosmovisor/README.md (1)

267-295: LGTM: New section on preparing for an upgrade

The new section "Preparing for an Upgrade" is well-written and provides clear instructions on using the prepare-upgrade command. The example output is helpful for users to understand what to expect when running the command.

tools/cosmovisor/cmd/cosmovisor/prepare_upgrade.go (2)

13-25: Command initialization follows best practices

The NewPrepareUpgradeCmd function correctly sets up the new prepare-upgrade command using the Cobra library. It includes appropriate usage (Use), short and long descriptions (Short, Long), assigns the correct handler (RunE), and specifies that no arguments are expected (Args).


27-66: Function prepareUpgradeHandler is well-structured and handles errors appropriately

The prepareUpgradeHandler function effectively manages the preparation steps for the upgrade, including configuration loading, upgrade information retrieval, parsing, and downloading the upgrade binary. Error handling is consistent and follows idiomatic Go practices, with errors wrapped using %w for better context.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

We cannot just read the upgrade-info. As said above, it won't be available.
We need to query the chain for the upgrade plan.

tools/cosmovisor/README.md Show resolved Hide resolved
tools/cosmovisor/cmd/cosmovisor/prepare_upgrade.go Outdated Show resolved Hide resolved
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

utACK! Some renaming and nits needed but nice work!

tools/cosmovisor/args.go Outdated Show resolved Hide resolved
tools/cosmovisor/args.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.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
tools/cosmovisor/args.go (1)

Line range hint 1-590: Update DetailString method to include GRPCAddress

The DetailString method should be updated to include the new GRPCAddress field in its output. This will ensure that all configuration details are properly displayed when requested.

Consider adding the following line to the configEntries slice in the DetailString method:

{EnvGRPCAddress, cfg.GRPCAddress},
tools/cosmovisor/README.md (1)

267-298: Enhance the "Preparing for an Upgrade" section.

The new section provides valuable information about the prepare-upgrade command. Consider the following improvements:

  1. Adjust the indentation of list items to be consistent with the rest of the document (8 spaces instead of 4).
  2. Add syntax highlighting to the example output for better readability.
  3. Make the note about manual downloads more prominent, perhaps by using a blockquote or admonition syntax.

Here's an example of how you could apply these changes:

 ### Preparing for an Upgrade

 To prepare for an upgrade, use the `prepare-upgrade` command:

 ```shell
 cosmovisor prepare-upgrade

This command performs the following actions:

-1. Retrieves upgrade information directly from the blockchain about the next scheduled upgrade.
-2. Downloads the new binary specified in the upgrade plan.
-3. Verifies the binary's checksum (if required by configuration).
-4. Places the new binary in the appropriate directory for Cosmovisor to use during the upgrade.

  •    1. Retrieves upgrade information directly from the blockchain about the next scheduled upgrade.
    
  •    2. Downloads the new binary specified in the upgrade plan.
    
  •    3. Verifies the binary's checksum (if required by configuration).
    
  •    4. Places the new binary in the appropriate directory for Cosmovisor to use during the upgrade.
    

The prepare-upgrade command provides detailed logging throughout the process, including:

-* The name and height of the upcoming upgrade
-* The URL from which the new binary is being downloaded
-* Confirmation of successful download and verification
-* The path where the new binary has been placed

  •    * The name and height of the upcoming upgrade
    
  •    * The URL from which the new binary is being downloaded
    
  •    * Confirmation of successful download and verification
    
  •    * The path where the new binary has been placed
    

Example output:

-bash +log
INFO Preparing for upgrade name=v1.0.0 height=1000000
INFO Downloading upgrade binary url=https://example.com/binary/v1.0.0?checksum=sha256:339911508de5e20b573ce902c500ee670589073485216bee8b045e853f24bce8
INFO Upgrade preparation complete name=v1.0.0 height=1000000


-*Note: The current way of downloading manually and placing the binary at the right place would still work.*
+> **Note:** The current way of downloading manually and placing the binary at the right place would still work.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~287-~287: Possible missing preposition found.
Context: ... successful download and verification * The path where the new binary has been plac...

(AI_HYDRA_LEO_MISSING_OF)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between db7a212 and c7672f9.

📒 Files selected for processing (4)
  • tools/cosmovisor/README.md (2 hunks)
  • tools/cosmovisor/args.go (3 hunks)
  • tools/cosmovisor/cmd/cosmovisor/prepare_upgrade.go (1 hunks)
  • tools/cosmovisor/go.mod (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/cosmovisor/cmd/cosmovisor/prepare_upgrade.go
🧰 Additional context used
📓 Path-based instructions (2)
tools/cosmovisor/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

tools/cosmovisor/args.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🪛 Markdownlint
tools/cosmovisor/README.md

21-21: Expected: 8; Actual: 4
Unordered list indentation

(MD007, ul-indent)

🪛 LanguageTool
tools/cosmovisor/README.md

[uncategorized] ~287-~287: Possible missing preposition found.
Context: ... successful download and verification * The path where the new binary has been plac...

(AI_HYDRA_LEO_MISSING_OF)

🔇 Additional comments (5)
tools/cosmovisor/go.mod (1)

13-13: Verify the necessity and implications of adding gRPC as a direct dependency.

The addition of google.golang.org/grpc v1.67.0 as a direct dependency suggests that the Cosmovisor tool now explicitly requires gRPC functionality. This change aligns with the PR objective of adding a new prepare-upgrade command, which may involve network communication.

However, please consider the following points:

  1. Ensure that this direct dependency is necessary for the new prepare-upgrade command. If it's only used in a small part of the new functionality, consider if it can remain an indirect dependency.

  2. Verify that version 1.67.0 is the most appropriate version for your needs. It's generally good practice to use the latest stable version unless there are specific reasons not to.

  3. Check for any potential conflicts or incompatibilities with other dependencies that might be using gRPC indirectly.

  4. Consider the impact on the module's size and compilation time. Adding gRPC as a direct dependency might increase both.

To ensure this change doesn't introduce any unforeseen issues, please run the following commands:

If these checks pass without issues, the change can be considered safe.

tools/cosmovisor/args.go (3)

36-36: LGTM: New environment variable constant added

The addition of EnvGRPCAddress constant follows the existing pattern and naming convention for environment variables in this file.


67-67: LGTM: New GRPCAddress field added to Config struct

The GRPCAddress field is correctly added to the Config struct with appropriate toml and mapstructure tags, consistent with other fields in the struct.


287-290: LGTM: GRPCAddress configuration added

The GetConfigFromEnv function has been correctly updated to handle the new GRPCAddress configuration. It reads from the environment variable and provides a sensible default value of "localhost:9090" if not set.

tools/cosmovisor/README.md (1)

21-21: LGTM: Table of contents updated correctly.

The new section "Preparing for an Upgrade" has been properly added to the table of contents, maintaining consistency with the document structure.

🧰 Tools
🪛 Markdownlint

21-21: Expected: 8; Actual: 4
Unordered list indentation

(MD007, ul-indent)

tools/cosmovisor/args.go Show resolved Hide resolved
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Nice job 👏🏾, tACK.

@julienrbrt julienrbrt added this pull request to the merge queue Oct 1, 2024
Merged via the queue into main with commit 3f9c9a0 Oct 1, 2024
73 of 75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Cosmovisor Issues and PR related to Cosmovisor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cosmovisor fetch-upgrade command
4 participants