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 unnecessary home directory creation issues #1073

Merged
merged 3 commits into from
Feb 15, 2024
Merged

Fix unnecessary home directory creation issues #1073

merged 3 commits into from
Feb 15, 2024

Conversation

roy-dydx
Copy link
Contributor

Changelist

Test Plan

  • Tested query commands to ensure correct home directory was being used in default and non-default cases. Checked to make sure default one wasn't created when not intended.
  • Ran local net and inspected containers to make sure data directory isn't created in /dydxprotocol/.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link
Contributor

coderabbitai bot commented Feb 13, 2024

Walkthrough

The modifications primarily involve enhancing the setup for testing and configuration within the dYdX Protocol's command-line interface. By integrating a test utilities package and refining the application initialization process, the changes aim to streamline development workflows. Specifically, improvements include the use of a dedicated temporary directory for testing, adjustments in configuration reading mechanisms, and the simplification of command initialization by directly utilizing default node home paths.

Changes

File Path Change Summary
protocol/cmd/dydxprotocold/cmd/root.go - Added imports for simtestutil and app.
- Modified viper.New() initialization.
- Updated configuration reading method.
- Added tempDir function.
protocol/cmd/dydxprotocold/main.go - Removed tempDir() function.
- Used app.DefaultNodeHome directly in cmd.NewRootCmd().

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 55d2267 and 42c61e3.
Files ignored due to path filters (2)
  • protocol/go.mod is excluded by: !**/*.mod
  • protocol/go.sum is excluded by: !**/*.sum
Files selected for processing (2)
  • protocol/cmd/dydxprotocold/cmd/root.go (5 hunks)
  • protocol/cmd/dydxprotocold/main.go (2 hunks)
Additional comments: 5
protocol/cmd/dydxprotocold/main.go (1)
  • 17-17: Change aligns with PR objectives to streamline directory management.
protocol/cmd/dydxprotocold/cmd/root.go (4)
  • 31-31: Added import for simtestutil aligns with the use of simulation test utilities.
  • 42-42: Added import for app is necessary for accessing DefaultNodeHome.
  • 94-94: Modification to use simtestutil.NewAppOptionsWithFlagHome(tempDir()) is appropriate for using a temporary directory during initialization.
  • 165-165: Change to config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx) is correct for using default client configuration values.

Comment on lines 429 to 438
var tempDir = func() string {
dir, err := os.MkdirTemp("", "dydxprotocol")
if err != nil {
dir = app.DefaultNodeHome
}
defer os.RemoveAll(dir)

return dir
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The tempDir function correctly creates a temporary directory but does not handle the temporary directory's lifecycle properly. defer os.RemoveAll(dir) will remove the directory as soon as tempDir returns, which is likely not the intended behavior.

-	defer os.RemoveAll(dir)
+	// Note: The caller should ensure to clean up the temporary directory when it's no longer needed.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
var tempDir = func() string {
dir, err := os.MkdirTemp("", "dydxprotocol")
if err != nil {
dir = app.DefaultNodeHome
}
defer os.RemoveAll(dir)
return dir
}
var tempDir = func() string {
dir, err := os.MkdirTemp("", "dydxprotocol")
if err != nil {
dir = app.DefaultNodeHome
}
// Note: The caller should ensure to clean up the temporary directory when it's no longer needed.
return dir
}

Copy link
Contributor

@lcwik lcwik left a comment

Choose a reason for hiding this comment

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

There is an existing ticket about get command line tests for coverage of these edge cases since it is difficult to know what the initial client context and config should be since the Cosmos SDK documentation is lacking as to how those values are needed for Auto CLI opts. Is the additional tests you can add in a follow-up?

@@ -90,7 +91,7 @@ func NewRootCmdWithInterceptors(
dbm.NewMemDB(),
nil,
true,
viper.New(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be replaced with:

initAppOptions := viper.New()
initAppOptions.Set(flags.FlagHome, tempDir())
tempApp(..., initAppOptions)

Was hoping to keep away from test utilities in Cosmos SDK as part of the production code.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 42c61e3 and fc688dc.
Files selected for processing (1)
  • protocol/cmd/dydxprotocold/cmd/root.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/cmd/dydxprotocold/cmd/root.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d1fa330 and 1d83ea8.
Files ignored due to path filters (2)
  • protocol/go.mod is excluded by: !**/*.mod
  • protocol/go.sum is excluded by: !**/*.sum
Files selected for processing (2)
  • protocol/cmd/dydxprotocold/cmd/root.go (4 hunks)
  • protocol/cmd/dydxprotocold/main.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/cmd/dydxprotocold/cmd/root.go
  • protocol/cmd/dydxprotocold/main.go

@lcwik
Copy link
Contributor

lcwik commented Feb 15, 2024

There is a lint issue with an import of the same statement twice and tests are failing (one seems to be due to a flake)

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d1fa330 and d9a81c0.
Files ignored due to path filters (2)
  • protocol/go.mod is excluded by: !**/*.mod
  • protocol/go.sum is excluded by: !**/*.sum
Files selected for processing (2)
  • protocol/cmd/dydxprotocold/cmd/root.go (3 hunks)
  • protocol/cmd/dydxprotocold/main.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/cmd/dydxprotocold/cmd/root.go
  • protocol/cmd/dydxprotocold/main.go

@roy-dydx roy-dydx merged commit 71ce2c6 into main Feb 15, 2024
17 checks passed
@roy-dydx roy-dydx deleted the roy/fixfix branch February 15, 2024 15:12
@roy-dydx
Copy link
Contributor Author

@Mergifyio backport release/protocol/v4.x

mergify bot pushed a commit that referenced this pull request Feb 15, 2024
* Fix unnecessary home directory creation issues

* Address comment

* New fork commit with new cherry-picks

(cherry picked from commit 71ce2c6)

# Conflicts:
#	protocol/go.mod
#	protocol/go.sum
Copy link
Contributor

mergify bot commented Feb 15, 2024

backport release/protocol/v4.x

✅ Backports have been created

roy-dydx added a commit that referenced this pull request Feb 15, 2024
* Fix unnecessary home directory creation issues (#1073)

* Fix unnecessary home directory creation issues

* Address comment

* New fork commit with new cherry-picks

(cherry picked from commit 71ce2c6)

# Conflicts:
#	protocol/go.mod
#	protocol/go.sum

* fix conflict

---------

Co-authored-by: roy-dydx <[email protected]>
Co-authored-by: Roy Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants