From 2571114e98a23c602d83e3cad12e3d674a5a2a99 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 15 Feb 2024 15:18:20 -0500 Subject: [PATCH] Fix unnecessary home directory creation issues (backport #1073) (#1075) * 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 71ce2c6fac4070a6c8c520d249f4bfd85e0e36a4) # Conflicts: # protocol/go.mod # protocol/go.sum * fix conflict --------- Co-authored-by: roy-dydx <133032749+roy-dydx@users.noreply.github.com> Co-authored-by: Roy Li --- protocol/cmd/dydxprotocold/cmd/root.go | 20 ++++++++++++++------ protocol/cmd/dydxprotocold/main.go | 17 +---------------- protocol/go.mod | 3 ++- protocol/go.sum | 8 ++++---- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/protocol/cmd/dydxprotocold/cmd/root.go b/protocol/cmd/dydxprotocold/cmd/root.go index 368ac90b9b..a8e843f858 100644 --- a/protocol/cmd/dydxprotocold/cmd/root.go +++ b/protocol/cmd/dydxprotocold/cmd/root.go @@ -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 { @@ -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) } @@ -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 +} diff --git a/protocol/cmd/dydxprotocold/main.go b/protocol/cmd/dydxprotocold/main.go index 2ccb4cd382..a17b70d60d 100644 --- a/protocol/cmd/dydxprotocold/main.go +++ b/protocol/cmd/dydxprotocold/main.go @@ -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) @@ -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 -} diff --git a/protocol/go.mod b/protocol/go.mod index fb947140fa..00759b9a15 100644 --- a/protocol/go.mod +++ b/protocol/go.mod @@ -405,13 +405,14 @@ require ( ) replace ( + cosmossdk.io/client/v2 => github.com/dydxprotocol/cosmos-sdk/client/v2 v2.0.0-beta.1.0.20240214225014-c0bde14212a7 // 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.20240206213020-ef2fbbac2693 + github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240214225014-c0bde14212a7 ) replace ( diff --git a/protocol/go.sum b/protocol/go.sum index 7a0055c271..93ce40f5dd 100644 --- a/protocol/go.sum +++ b/protocol/go.sum @@ -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= @@ -527,8 +525,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.20240206213020-ef2fbbac2693 h1:FdOhkelNwqyXMP6JFJzi+d9A0cxGJEiieDIkDYtcCa4= -github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240206213020-ef2fbbac2693/go.mod h1:y+5fRLbztsvx6GHBVXPlgM51ZpuNd8M7y4YEAQNnTPU= +github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240214225014-c0bde14212a7 h1:g3dt0DIEZONvrfKZojvEwUB2j7THUG/5JxY2oqXxQcA= +github.com/dydxprotocol/cosmos-sdk v0.50.4-0.20240214225014-c0bde14212a7/go.mod h1:y+5fRLbztsvx6GHBVXPlgM51ZpuNd8M7y4YEAQNnTPU= +github.com/dydxprotocol/cosmos-sdk/client/v2 v2.0.0-beta.1.0.20240214225014-c0bde14212a7 h1:lTVwvpc4mHShiFDnPG/m06hKtHJYbKM4HFUR3T3vNHg= +github.com/dydxprotocol/cosmos-sdk/client/v2 v2.0.0-beta.1.0.20240214225014-c0bde14212a7/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=