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 (backport #1062) #1063

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading