Skip to content

Commit

Permalink
Make app runnable without creating default home dir (#1062) (#1063)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mergify[bot] and roy-dydx committed Feb 9, 2024
1 parent c7bcbf6 commit 49dc3b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions protocol/cmd/dydxprotocold/cmd/root.go
Expand Up @@ -165,6 +165,10 @@ func NewRootCmdWithInterceptors(
if err != nil {
panic(err)
}
// [ Home Dir Temp Fix ] (also see protocol/cmd/dydxprotocold/main.go)
// Unset the temp home dir. This must be done after `ReadFromClientConfig`, otherwise it will
// create a temp dir in cwd.
initClientCtx.HomeDir = ""
if err := autoCliOpts(tempApp, initClientCtx).EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}
Expand Down
17 changes: 16 additions & 1 deletion protocol/cmd/dydxprotocold/main.go
Expand Up @@ -14,7 +14,12 @@ func main() {
config.SetupConfig()

option := cmd.GetOptionWithCustomStartCmd()
rootCmd := cmd.NewRootCmd(option, app.DefaultNodeHome)
// [ Home Dir Temp Fix ] (also see protocol/cmd/dydxprotocold/cmd/root.go)
// We pass in a tempdir as a temporary hack until fixed in cosmos.
// If not, and we pass in a custom home dir, it will try read or create the default home dir
// before using the custom home dir.
// See https://github.com/cosmos/cosmos-sdk/issues/18868.
rootCmd := cmd.NewRootCmd(option, tempDir())

cmd.AddTendermintSubcommands(rootCmd)
cmd.AddInitCmdPostRunE(rootCmd)
Expand All @@ -23,3 +28,13 @@ func main() {
os.Exit(1)
}
}

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

return dir
}
3 changes: 2 additions & 1 deletion protocol/testing/containertest/node.go
Expand Up @@ -3,9 +3,10 @@ package containertest
import (
"context"
"fmt"
"github.com/dydxprotocol/v4-chain/protocol/app"
"time"

"github.com/dydxprotocol/v4-chain/protocol/app"

comethttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand Down

0 comments on commit 49dc3b9

Please sign in to comment.