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

Make app runnable without creating default home dir #1062

Merged
merged 2 commits into from
Feb 9, 2024
Merged

Conversation

roy-dydx
Copy link
Contributor

@roy-dydx roy-dydx commented Feb 9, 2024

Changelist

  • Create a temp dir instead as a quick hack.

Test Plan

  • Run localnet, inspect the containers and see that no default home dir was created during any step.
  • Run a command ./build/dydxprotocold query subaccounts show-subaccount dydx1q628jg3e8vzy6xcns6fxls7k7kplqgxr0gy87t 0 --home ~/.dydxprotocol2, with existing custom home dir, ensure it works properly and doesn't create default home dir.
    • Now run it without custom home dir, ensure it creates default home dir and uses it
    • Now run it with custom home dir again, ensure it's still using the custom home dir

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

coderabbitai bot commented Feb 9, 2024

Walkthrough

The recent modifications involve simplifying the handling of the home directory within the project's command-line interface. The approach towards setting the home directory has shifted from utilizing a predefined parameter to dynamically creating a temporary directory. This change is aimed at enhancing flexibility and possibly improving the application's handling of user data or configurations by relying on temporary directories for operations.

Changes

File(s) Change Summary
protocol/cmd/dydxprotocold/cmd/root.go Removed homeDir parameter from NewRootCmd; added tempDir for temporary directory management; updated NewRootCmdWithInterceptors to use tempDir.
protocol/cmd/dydxprotocold/main.go Modified main() to call NewRootCmd without the app.DefaultNodeHome argument.
protocol/testing/containertest/node.go Removed import of github.com/dydxprotocol/v4-chain/protocol/app; updated NewRootCmd usage in Node struct method.

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

@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 6249e97 and 009547c.
Files selected for processing (2)
  • protocol/cmd/dydxprotocold/cmd/root.go (4 hunks)
  • protocol/cmd/dydxprotocold/main.go (1 hunks)
Additional comments: 2
protocol/cmd/dydxprotocold/main.go (1)
  • 17-17: The removal of app.DefaultNodeHome from the svrcmd.Execute call aligns with the PR's objective but ensure all related functionalities are tested to confirm no side effects.
protocol/cmd/dydxprotocold/cmd/root.go (1)
  • 106-106: Using tempDir() to set the home directory is consistent with the PR's objectives. Ensure the temporary directory's lifecycle is managed appropriately throughout the application's runtime.

Comment on lines 423 to 436

var tempDir = func() string {
dir, err := os.MkdirTemp("", "dydxprotocol")
if err != nil {
dir = dydxapp.DefaultNodeHome
}
defer os.RemoveAll(dir)

return dir
}
Copy link

Choose a reason for hiding this comment

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

The tempDir function creates and immediately removes the temporary directory, which could lead to runtime issues. Consider removing defer os.RemoveAll(dir) to ensure the directory persists for the application's lifetime.

-	defer os.RemoveAll(dir)

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 = dydxapp.DefaultNodeHome
}
defer os.RemoveAll(dir)
return dir
}
var tempDir = func() string {
dir, err := os.MkdirTemp("", "dydxprotocol")
if err != nil {
dir = dydxapp.DefaultNodeHome
}
return dir
}

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6249e97 and e0ad073.
Files selected for processing (2)
  • protocol/cmd/dydxprotocold/cmd/root.go (5 hunks)
  • protocol/cmd/dydxprotocold/main.go (1 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 force-pushed the roy/home branch 2 times, most recently from a8f1218 to 23307d3 Compare February 9, 2024 14:33
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6249e97 and 23307d3.
Files selected for processing (2)
  • protocol/cmd/dydxprotocold/cmd/root.go (1 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 force-pushed the roy/home branch 2 times, most recently from aa3bc31 to 999ef5f Compare February 9, 2024 14:59
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6249e97 and d6b28ea.
Files selected for processing (3)
  • protocol/cmd/dydxprotocold/cmd/root.go (3 hunks)
  • protocol/cmd/dydxprotocold/main.go (1 hunks)
  • protocol/testing/containertest/node.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
Additional comments: 1
protocol/testing/containertest/node.go (1)
  • 107-107: The NewRootCmd function is now called with a new parameter option, which is obtained from cmd.GetOptionWithCustomStartCmd(). Ensure that this change aligns with the PR's objective to prevent the creation of a default home directory and that it correctly implements the temporary directory workaround. Verify that the option parameter is properly configured to support this behavior.

if err != nil {
dir = app.DefaultNodeHome
}
defer os.RemoveAll(dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

won't defer delete dir when function is returning and this would clear the DefaultNodeHome from any existing state if creating a temp dir creation is not possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I just copied this straight from cosmos. But it doesn't matter because the directories are recreated created in ReadFromClientConfig.

@@ -165,6 +165,7 @@ func NewRootCmdWithInterceptors(
if err != nil {
panic(err)
}
initClientCtx.HomeDir = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason why it is set here instead of above on line 109?

If so can you document why with a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we set this before ReadFromClientConfig, the config will be created in cwd instead.

@roy-dydx roy-dydx merged commit 2657b35 into main Feb 9, 2024
10 checks passed
@roy-dydx roy-dydx deleted the roy/home branch February 9, 2024 17:35
mergify bot pushed a commit that referenced this pull request Feb 9, 2024
* Make app runnable without creating default home dir

* Add comments

(cherry picked from commit 2657b35)
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6249e97 and 2e530b8.
Files selected for processing (3)
  • protocol/cmd/dydxprotocold/cmd/root.go (1 hunks)
  • protocol/cmd/dydxprotocold/main.go (2 hunks)
  • protocol/testing/containertest/node.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • protocol/cmd/dydxprotocold/cmd/root.go
  • protocol/cmd/dydxprotocold/main.go
  • protocol/testing/containertest/node.go

roy-dydx added a commit that referenced this pull request Feb 9, 2024
* Make app runnable without creating default home dir

* Add comments

(cherry picked from commit 2657b35)

Co-authored-by: roy-dydx <133032749+roy-dydx@users.noreply.github.com>
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.

None yet

3 participants