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

WIP feat(tools/cosmovisor): create current symlink as relative #21891

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

Conversation

troian
Copy link
Contributor

@troian troian commented Sep 24, 2024

if cosmovisor used within docker
daemon workdir can be mounted as volume which leads to current symlink no working on the host machine

Description

Closes: #XXXX


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 a relative current symlink in the cosmovisor module.
    • Enhanced client context with new address codec methods.
  • Improvements
    • Simplified keyring interfaces to use []byte for addresses.
    • Streamlined symlink handling and error management in configuration methods.
    • Updated command structure to reflect initialization functionality.
  • Bug Fixes
    • Improved error handling in the run function for directory changes.

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Important

Review skipped

Ignore keyword(s) in the title.

⛔ Ignored keywords (2)
  • WIP
  • DO NOT MERGE

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The pull request introduces several enhancements to the tools/cosmovisor module, including the addition of a relative current symlink, improved error handling, and new methods in the client context for address codecs. Keyring interfaces have been simplified to use []byte for addresses. Additionally, modifications were made to the command structure, particularly renaming commands and streamlining the handling of symbolic links and paths in various methods.

Changes

File Change Summary
CHANGELOG.md Updated to document new feature of relative current symlink and improvements in error handling and client context methods.
tools/cosmovisor/args.go Simplified symbolic link handling in SymLinkToGenesis, improved error handling in CurrentBin, and streamlined SetCurrentUpgrade method.
tools/cosmovisor/cmd/cosmovisor/init.go Renamed NewIntCmd to NewInitCmd, reflecting the new purpose of initializing the cosmovisor daemon home directory.
tools/cosmovisor/cmd/cosmovisor/init_test.go Updated BufferedPipe methods to use pointer receivers, changed return types of NewBufferedPipe and StartNewBufferedPipe to pointers.
tools/cosmovisor/cmd/cosmovisor/root.go Replaced NewIntCmd() with NewInitCmd() in the root command structure.
tools/cosmovisor/cmd/cosmovisor/run.go Added functionality to change the current working directory to facilitate relative symlinks, with error handling for the directory change.

Possibly related PRs

Suggested labels

C:CLI, C:Hubl

Suggested reviewers

  • kocubinski
  • sontrinh16
  • testinginprod
  • aaronc
  • tac0turtle

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 24, 2024
@troian troian force-pushed the cosmovisor-relative-symlink branch 2 times, most recently from d5caf27 to 1d4b3d3 Compare September 24, 2024 21:19
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: 3

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

135-156: Approve changes with suggestions for code cleanup

The updates to the CurrentBin method improve symlink handling and error checking. The use of os.Lstat instead of os.Stat is more appropriate for symlink verification.

Consider the following improvements:

  1. Remove the commented-out code (lines 140-143) to maintain code cleanliness.
  2. Add a comment explaining why os.Lstat is used instead of os.Stat for better code documentation.

Here's a suggested diff for these changes:

 	info, err := os.Lstat(cur)
 	if err != nil || (info.Mode()&os.ModeSymlink == 0) {
-		// err = os.Remove(cur)
-		// if err != nil {
-		// 	return "", err
-		// }
+		// If not a symlink, create a symlink to genesis
 		// Create symlink to the genesis
 		return cfg.SymLinkToGenesis()
 	}

+	// Use os.Lstat to get information about the symlink itself, not the file it points to
 	_, err = os.Readlink(cur)
 	if err != nil {
 		// Create symlink to the genesis
 		return cfg.SymLinkToGenesis()
 	}

These changes will improve code readability and maintainability.

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

217-217: Consider removing the empty line for consistency.

While the added empty line doesn't affect functionality, it's not consistent with the surrounding code style. Consider removing it to maintain a uniform code structure.

- 

242-242: Consider removing the empty line for consistency.

Similar to the previous comment, this added empty line doesn't affect functionality but isn't consistent with the surrounding code style. Consider removing it to maintain a uniform code structure.

- 
CHANGELOG.md (5)

Line range hint 1-98: Ensure all unreleased changes are properly documented

The unreleased changes section provides a good overview of the upcoming features, improvements, and bug fixes. However, consider the following suggestions to enhance the clarity and usefulness of the changelog:

  1. Add a brief summary at the beginning of the unreleased section to highlight the most significant changes.
  2. Consider grouping related changes together, especially for cross-cutting concerns like performance improvements or API changes.
  3. Ensure that each entry provides enough context for users who may not be familiar with the internal workings of the project.
  4. For bug fixes, consider adding information about the impact of the bug and how it affects users.

Line range hint 100-124: Enhance feature descriptions for better user understanding

The Features section provides a good overview of new additions to the SDK. To improve its usefulness:

  1. Consider adding brief explanations of the impact or benefits of each feature for end-users or developers.
  2. Ensure consistency in the level of detail provided for each feature. Some entries are very detailed, while others are quite brief.
  3. For features that introduce new concepts or significant changes, consider adding links to relevant documentation or examples.

Line range hint 126-170: Clarify the impact of improvements for users and developers

The Improvements section provides a good overview of enhancements to the SDK. To make it more useful:

  1. For each improvement, consider adding a brief note on how it benefits users or developers. This helps readers understand the significance of the change.
  2. Ensure consistency in the level of technical detail provided across entries. Some are quite technical, while others are more general.
  3. For improvements that change existing behavior, clearly indicate any potential impact on backwards compatibility or required actions from users.
  4. Consider grouping related improvements together to provide a clearer picture of overall enhancements in specific areas of the SDK.

Line range hint 172-185: Enhance bug fix descriptions for better context

The Bug Fixes section provides valuable information about resolved issues. To improve its usefulness:

  1. For each bug fix, consider adding a brief description of how the bug might have affected users. This helps readers understand the importance of the fix.
  2. Ensure consistency in providing links to related issues or pull requests for all entries.
  3. Where applicable, mention any potential impact on performance or behavior that users should be aware of after applying the fix.
  4. Consider grouping related bug fixes together, especially if they address different aspects of the same underlying issue.

Line range hint 1-185: Overall improvement suggestions for the CHANGELOG

The CHANGELOG.md file provides a comprehensive overview of the changes, improvements, and bug fixes in the Cosmos SDK. To further enhance its usefulness:

  1. Consider adding a "Breaking Changes" section at the top to highlight any changes that may require action from users or potentially break existing implementations.
  2. Maintain consistency in the level of detail and style across all entries.
  3. Where possible, provide links to relevant documentation, examples, or discussions for significant changes or new features.
  4. Consider adding a "Deprecations" section to clearly communicate any features or APIs that are being phased out.
  5. For each release, consider adding a brief summary of the most significant changes or overarching themes to give readers a quick overview.

These improvements will help users and developers quickly understand the changes and their potential impact when updating to new versions of the SDK.

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f6d7a92 and 1d4b3d3.

Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • tools/cosmovisor/args.go (3 hunks)
  • tools/cosmovisor/cmd/cosmovisor/init.go (2 hunks)
  • tools/cosmovisor/cmd/cosmovisor/init_test.go (9 hunks)
  • tools/cosmovisor/cmd/cosmovisor/root.go (1 hunks)
  • tools/cosmovisor/cmd/cosmovisor/run.go (2 hunks)
Additional context used
Path-based instructions (6)
CHANGELOG.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.

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

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

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

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

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

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

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

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

Additional comments not posted (10)
tools/cosmovisor/cmd/cosmovisor/run.go (1)

43-47: LGTM! Consider verifying subsequent operations.

The new code block successfully implements the PR objective by changing the working directory to allow for relative symlinks. The error handling is appropriate, and the comment clearly explains the purpose.

To ensure this change doesn't negatively impact subsequent operations, please run the following verification:

This will help identify any potential issues with file operations or path manipulations that might be affected by the directory change.

Verification successful

Verified: Subsequent operations are compatible with the directory change.

No file operations or path manipulations were detected after changing the working directory, ensuring that the directory change does not negatively impact subsequent functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that subsequent operations in the run function are compatible with the directory change.

# Test: Search for file operations or path manipulations after the directory change.
rg --type go -A 10 -B 2 'os.Chdir\(cfg.Root\(\)\)' tools/cosmovisor/cmd/cosmovisor/run.go

Length of output: 466

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

17-17: Improved function naming: NewIntCmd to NewInitCmd

The change from NewIntCmd to NewInitCmd is a good improvement. It more accurately describes the function's purpose of initializing a cosmovisor daemon home directory, enhancing code readability and maintainability.

tools/cosmovisor/args.go (1)

382-399: ⚠️ Potential issue

Approve changes with a suggestion for path construction

The updates to the SetCurrentUpgrade method improve symlink handling by using relative paths, which enhances portability. However, there's a potential issue with the upgrade info file path construction.

The path construction for the upgrade info file (line 399) now includes cfg.Root(), which might lead to an incorrect path. Consider removing cfg.Root() from this path construction, as the upgrade variable already contains the relative path.

Here's a suggested fix:

-	f, err := os.Create(filepath.Join(cfg.Root(), upgrade, upgradetypes.UpgradeInfoFilename))
+	f, err := os.Create(filepath.Join(upgrade, upgradetypes.UpgradeInfoFilename))

This change ensures that the upgrade info file is created in the correct location relative to the current working directory.

To verify the correct path construction, you can run the following script:

#!/bin/bash
# Description: Verify the upgrade info file path construction

# Test: Check the structure of the upgrades directory
ls -R upgrades

This script will help ensure that the upgrade info file is being created in the correct location within the upgrades directory structure.

tools/cosmovisor/cmd/cosmovisor/init_test.go (7)

141-142: LGTM: Correct interface implementation assertions.

The added assertions correctly ensure that BufferedPipe implements both io.Reader and io.Writer interfaces using pointer receivers. This is a good practice for type checking and documentation.


187-187: LGTM: Consistent return type for StartNewBufferedPipe.

The function signature change to return a pointer to BufferedPipe is consistent with the changes made to NewBufferedPipe, maintaining API consistency.


252-252: LGTM: Correct use of pointer receivers for Read and Write methods.

The change to use pointer receivers for the Read and Write methods is correct and consistent with the earlier interface assertions. This improves efficiency and allows direct modification of the BufferedPipe instance.

Also applies to: 257-257


279-279: LGTM: Consistent return of BufferedPipe pointer.

This change is consistent with the earlier modifications to NewBufferedPipe, now correctly returning the pointer without using the address-of operator.


454-454: LGTM: Improved error message specificity.

The updated error message provides more specific information about the failure, which is helpful for debugging and understanding the issue.


696-698: LGTM: Proper resource management with deferred file closing.

The addition of a deferred file closing function is a good practice to ensure that resources are properly released, even in the event of an error.


170-171: LGTM: Consistent return type for NewBufferedPipe.

The function signature change to return a pointer to BufferedPipe is consistent with the earlier interface assertions and is a good practice for larger structs.

Let's verify that this change is consistently applied throughout the codebase:

Verification successful

Verified: All usages of NewBufferedPipe handle it as a pointer, ensuring consistency throughout the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for NewBufferedPipe function calls and ensure they're handled as pointers
rg --type go 'NewBufferedPipe\(' -A 3 -B 1

Length of output: 1742

@@ -14,7 +14,7 @@ func NewRootCmd() *cobra.Command {
}

rootCmd.AddCommand(
NewIntCmd(),
NewInitCmd(),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Documentation updates required.

Please update the following documentation files to reflect the change from NewIntCmd() to NewInitCmd():

  • client/v2/CHANGELOG.md
  • client/v2/README.md
  • docs/architecture/adr-058-auto-generated-cli.md
  • docs/learn/advanced/07-cli.md
  • tools/cosmovisor/CHANGELOG.md
  • tools/cosmovisor/README.md
  • tools/cosmovisor/RELEASE_NOTES.md
Analysis chain

LGTM. Verify related updates and update changelog.

The change from NewIntCmd() to NewInitCmd() aligns with the PR objectives and appears to be a logical modification to the CLI structure. This change likely introduces an initialization command, which is consistent with the goal of creating a relative symlink for the current directory.

To ensure completeness, please:

  1. Verify that related documentation (e.g., CLI help texts, user guides) has been updated to reflect this change.
  2. Confirm that appropriate tests have been added or updated for the new InitCmd.
  3. Update the changelog to mention this CLI command change.

Run the following script to check for related files that might need updates:

This will help identify files that might need to be updated due to the command change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find files that might need updates due to the command change

# Search for files mentioning the old command
echo "Files potentially referencing the old 'int' command:"
rg --type go --type md "NewIntCmd|int\s+command" -l

# Search for test files related to commands
echo "Test files related to commands:"
fd -e go test_.*cmd

# Search for documentation files
echo "Documentation files that might need updates:"
fd -e md -e txt | rg "cli|command|cosmovisor"

Length of output: 630

tools/cosmovisor/cmd/cosmovisor/init.go Outdated Show resolved Hide resolved
Comment on lines 114 to 119
// workdir is set to cosmovisor directory so relative
// symlinks are getting resolved correctly
if err := os.Symlink(genesisDir, currentLink); err != nil {
return "", err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Working directory is not set to the cosmovisor directory

The shell script indicates that the current working directory is /home/jailuser/git instead of the expected cosmovisor directory. This misconfiguration can lead to incorrect resolution of relative symlinks as described.

Analysis chain

Approve changes with a suggestion for additional safeguards

The simplification of the symlink creation process improves code readability. However, the reliance on the correct working directory setting could potentially lead to issues.

Consider adding a check to ensure the working directory is set correctly before creating the symlink. This could help prevent potential errors if the method is called from an unexpected context.

To verify the current working directory setting, you can run the following script:

This script will help ensure that the working directory assumption is valid.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the current working directory setting

# Test: Check if the current working directory is set to the cosmovisor directory
pwd
ls -la

Length of output: 4476

@troian troian changed the title feat(tools/cosmovisor): create current symlink as relative WIP feat(tools/cosmovisor): create current symlink as relative Sep 24, 2024
@troian troian force-pushed the cosmovisor-relative-symlink branch 2 times, most recently from a3eed59 to bb72f63 Compare September 25, 2024 01:01
@tac0turtle tac0turtle marked this pull request as draft September 25, 2024 10:37
@tac0turtle
Copy link
Member

converting to draft until WIP is removed

troian added a commit to akash-network/cosmos-sdk that referenced this pull request Sep 25, 2024
required by cosmos#21891
allows cosmovisor tests to natively run on following os/arch pairs
linux/amd64, linux/arm64
darwin/amd64, darwin/arm64

Signed-off-by: Artur Troian <troian.ap@gmail.com>
if cosmovisor used within docker
daemon workdir can be mounted as volume which leads
to current symlink no working on the host machine

Signed-off-by: Artur Troian <troian.ap@gmail.com>
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.

2 participants