Skip to content

Commit

Permalink
Fix unnecessary home directory creation issues (#1073)
Browse files Browse the repository at this point in the history
* Fix unnecessary home directory creation issues

* Address comment

* New fork commit with new cherry-picks
  • Loading branch information
roy-dydx authored Feb 15, 2024
1 parent d1fa330 commit 71ce2c6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
20 changes: 14 additions & 6 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ func NewRootCmdWithInterceptors(
appConfigInterceptor func(string, *DydxAppConfig) (string, *DydxAppConfig),
appInterceptor func(app *dydxapp.App) *dydxapp.App,
) *cobra.Command {
initAppOptions := viper.New()
initAppOptions.Set(flags.FlagHome, tempDir())
tempApp := dydxapp.New(
log.NewNopLogger(),
dbm.NewMemDB(),
nil,
true,
viper.New(),
initAppOptions,
)
defer func() {
if err := tempApp.Close(); err != nil {
Expand Down Expand Up @@ -161,14 +163,10 @@ func NewRootCmdWithInterceptors(
}

initRootCmd(tempApp, rootCmd, option, appInterceptor)
initClientCtx, err := config.ReadFromClientConfig(initClientCtx)
initClientCtx, err := config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx)
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 Expand Up @@ -428,3 +426,13 @@ func appExport(

return dydxApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
}

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

return dir
}
17 changes: 1 addition & 16 deletions protocol/cmd/dydxprotocold/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ func main() {
config.SetupConfig()

option := cmd.GetOptionWithCustomStartCmd()
// [ 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())
rootCmd := cmd.NewRootCmd(option, app.DefaultNodeHome)

cmd.AddTendermintSubcommands(rootCmd)
cmd.AddInitCmdPostRunE(rootCmd)
Expand All @@ -28,13 +23,3 @@ 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/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,14 @@ require (
)

replace (
cosmossdk.io/client/v2 => github.com/dydxprotocol/cosmos-sdk/client/v2 v2.0.0-beta.1.0.20240214225126-ba76b79cd4cf
// TODO(https://github.com/cosmos/rosetta/issues/76): Rosetta requires cosmossdk.io/core v0.12.0 erroneously but
// should use v0.11.0. The Cosmos build fails with types/context.go:65:29: undefined: comet.BlockInfo otherwise.
cosmossdk.io/core => cosmossdk.io/core v0.11.0
// Use dYdX fork of CometBFT
github.com/cometbft/cometbft => github.com/dydxprotocol/cometbft v0.38.3-0.20231204185009-5e6c4b6d67b8
// Use dYdX fork of Cosmos SDK
github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240206224621-ffeae5184c58
github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240214225126-ba76b79cd4cf
)

replace (
Expand Down
8 changes: 4 additions & 4 deletions protocol/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
cosmossdk.io/api v0.7.2 h1:BO3i5fvKMKvfaUiMkCznxViuBEfyWA/k6w2eAF6q1C4=
cosmossdk.io/api v0.7.2/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
cosmossdk.io/client/v2 v2.0.0-beta.1 h1:XkHh1lhrLYIT9zKl7cIOXUXg2hdhtjTPBUfqERNA1/Q=
cosmossdk.io/client/v2 v2.0.0-beta.1/go.mod h1:JEUSu9moNZQ4kU3ir1DKD5eU4bllmAexrGWjmb9k8qU=
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=
Expand Down Expand Up @@ -537,8 +535,10 @@ github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQx
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dydxprotocol/cometbft v0.38.3-0.20231204185009-5e6c4b6d67b8 h1:zmH6go7DRhFcQHoiN/rQ1INaAelp01VUPUTSqSDJsAU=
github.com/dydxprotocol/cometbft v0.38.3-0.20231204185009-5e6c4b6d67b8/go.mod h1:KQ8mOea6U2satQbGe2WjxBopa8mGgHatMKS9sQsJ6uY=
github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240206224621-ffeae5184c58 h1:3nW+id7dbHUv+RJB2pecjKtA0WWQr3oit4KrxBJ0+kw=
github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240206224621-ffeae5184c58/go.mod h1:y+5fRLbztsvx6GHBVXPlgM51ZpuNd8M7y4YEAQNnTPU=
github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240214225126-ba76b79cd4cf h1:buHamAV21CWNE8IVKe/v6RPzQaLM9t3ZkTijGFaS4c4=
github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240214225126-ba76b79cd4cf/go.mod h1:y+5fRLbztsvx6GHBVXPlgM51ZpuNd8M7y4YEAQNnTPU=
github.com/dydxprotocol/cosmos-sdk/client/v2 v2.0.0-beta.1.0.20240214225126-ba76b79cd4cf h1:1S0YnPWIM1uacL73Jx9mZYK0T3uj1qoL2TqwlRtyDpw=
github.com/dydxprotocol/cosmos-sdk/client/v2 v2.0.0-beta.1.0.20240214225126-ba76b79cd4cf/go.mod h1:Fi+Bqmvo+7wImB5+31CsBheyjBkvQxx8QRQY1acPVDU=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-resiliency v1.3.0 h1:RRL0nge+cWGlxXbUzJ7yMcq6w2XBEr19dCN6HECGaT0=
github.com/eapache/go-resiliency v1.3.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
Expand Down

0 comments on commit 71ce2c6

Please sign in to comment.