feat: parse home flag earlier (#20771)
This commit is contained in:
@@ -35,6 +35,7 @@ Always refer to the [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/mai
|
||||
* [#20409](https://github.com/cosmos/cosmos-sdk/pull/20409) Add `tx` as `SkipStoreKeys` in `app_config.go`.
|
||||
* [#20485](https://github.com/cosmos/cosmos-sdk/pull/20485) The signature of `x/upgrade/types.UpgradeHandler` has changed to accept `appmodule.VersionMap` from `module.VersionMap`. These types are interchangeable, but usages of `UpradeKeeper.SetUpgradeHandler` may need to adjust their usages to match the new signature.
|
||||
* [#20740](https://github.com/cosmos/cosmos-sdk/pull/20740) Update `genutilcli.Commands` to use the genutil modules from the module manager.
|
||||
* [#20771](https://github.com/cosmos/cosmos-sdk/pull/20771) Use client/v2 `GetNodeHomeDirectory` helper in `app.go` and use the `DefaultNodeHome` constant everywhere in the app.
|
||||
|
||||
<!-- TODO: move changelog.md elements to here -->
|
||||
|
||||
|
||||
+4
-4
@@ -18,6 +18,7 @@ import (
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
|
||||
"cosmossdk.io/client/v2/autocli"
|
||||
clienthelpers "cosmossdk.io/client/v2/helpers"
|
||||
"cosmossdk.io/core/log"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"cosmossdk.io/x/accounts"
|
||||
@@ -183,12 +184,11 @@ type SimApp struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
var err error
|
||||
DefaultNodeHome, err = clienthelpers.GetNodeHomeDirectory(".simapp")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
DefaultNodeHome = filepath.Join(userHomeDir, ".simapp")
|
||||
}
|
||||
|
||||
// NewSimApp returns a reference to an initialized SimApp.
|
||||
@@ -536,7 +536,7 @@ func NewSimApp(
|
||||
app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules)
|
||||
|
||||
// create, start, and load the unordered tx manager
|
||||
utxDataDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data")
|
||||
utxDataDir := filepath.Join(homePath, "data")
|
||||
app.UnorderedTxManager = unorderedtx.NewManager(utxDataDir)
|
||||
app.UnorderedTxManager.Start()
|
||||
|
||||
|
||||
+3
-4
@@ -6,12 +6,12 @@ import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
clienthelpers "cosmossdk.io/client/v2/helpers"
|
||||
"cosmossdk.io/core/legacy"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
@@ -100,12 +100,11 @@ type SimApp struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
var err error
|
||||
DefaultNodeHome, err = clienthelpers.GetNodeHomeDirectory(".simapp")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
DefaultNodeHome = filepath.Join(userHomeDir, ".simapp")
|
||||
}
|
||||
|
||||
// AppConfig returns the default app config.
|
||||
|
||||
@@ -3,7 +3,6 @@ package cmd
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -18,7 +17,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/debug"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/client/pruning"
|
||||
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||
@@ -143,13 +141,6 @@ func appExport(
|
||||
appOpts servertypes.AppOptions,
|
||||
modulesToExport []string,
|
||||
) (servertypes.ExportedApp, error) {
|
||||
// this check is necessary as we use the flag in x/upgrade.
|
||||
// we can exit more gracefully by checking the flag here.
|
||||
homePath, ok := appOpts.Get(flags.FlagHome).(string)
|
||||
if !ok || homePath == "" {
|
||||
return servertypes.ExportedApp{}, errors.New("application home not set")
|
||||
}
|
||||
|
||||
viperAppOpts, ok := appOpts.(*viper.Viper)
|
||||
if !ok {
|
||||
return servertypes.ExportedApp{}, errors.New("appOpts is not viper.Viper")
|
||||
@@ -172,13 +163,3 @@ func appExport(
|
||||
|
||||
return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
|
||||
}
|
||||
|
||||
var tempDir = func() string {
|
||||
dir, err := os.MkdirTemp("", "simapp")
|
||||
if err != nil {
|
||||
dir = simapp.DefaultNodeHome
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
func NewRootCmd() *cobra.Command {
|
||||
// we "pre"-instantiate the application for getting the injected/configured encoding configuration
|
||||
// note, this is not necessary when using app wiring, as depinject can be directly used (see root_v2.go)
|
||||
tempApp := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(tempDir()))
|
||||
tempApp := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome))
|
||||
encodingConfig := params.EncodingConfig{
|
||||
InterfaceRegistry: tempApp.InterfaceRegistry(),
|
||||
Codec: tempApp.AppCodec(),
|
||||
@@ -114,7 +114,7 @@ func NewRootCmd() *cobra.Command {
|
||||
// autocli opts
|
||||
customClientTemplate, customClientConfig := initClientConfig()
|
||||
var err error
|
||||
initClientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx, customClientTemplate, customClientConfig)
|
||||
initClientCtx, err = config.CreateClientConfig(initClientCtx, customClientTemplate, customClientConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
)
|
||||
|
||||
@@ -38,10 +37,7 @@ func NewRootCmd() *cobra.Command {
|
||||
|
||||
if err := depinject.Inject(
|
||||
depinject.Configs(simapp.AppConfig(),
|
||||
depinject.Supply(
|
||||
log.NewNopLogger(),
|
||||
simtestutil.NewAppOptionsWithFlagHome(tempDir()),
|
||||
),
|
||||
depinject.Supply(log.NewNopLogger()),
|
||||
depinject.Provide(
|
||||
ProvideClientContext,
|
||||
),
|
||||
@@ -128,7 +124,7 @@ func ProvideClientContext(
|
||||
|
||||
// Read the config to overwrite the default values with the values from the config file
|
||||
customClientTemplate, customClientConfig := initClientConfig()
|
||||
clientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig(clientCtx, customClientTemplate, customClientConfig)
|
||||
clientCtx, err = config.CreateClientConfig(clientCtx, customClientTemplate, customClientConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
+8
-10
@@ -2,16 +2,17 @@ package simapp
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
clienthelpers "cosmossdk.io/client/v2/helpers"
|
||||
coreapp "cosmossdk.io/core/app"
|
||||
"cosmossdk.io/core/legacy"
|
||||
"cosmossdk.io/core/log"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/runtime/v2"
|
||||
serverv2 "cosmossdk.io/server/v2"
|
||||
"cosmossdk.io/store/v2"
|
||||
"cosmossdk.io/store/v2/commitment/iavl"
|
||||
"cosmossdk.io/store/v2/db"
|
||||
@@ -36,10 +37,8 @@ import (
|
||||
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
||||
"github.com/cosmos/cosmos-sdk/std"
|
||||
)
|
||||
|
||||
@@ -77,12 +76,11 @@ type SimApp struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
var err error
|
||||
DefaultNodeHome, err = clienthelpers.GetNodeHomeDirectory(".simappv2")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
DefaultNodeHome = filepath.Join(userHomeDir, ".simappv2")
|
||||
}
|
||||
|
||||
// AppConfig returns the default app config.
|
||||
@@ -97,8 +95,8 @@ func NewSimApp(
|
||||
logger log.Logger,
|
||||
viper *viper.Viper,
|
||||
) *SimApp {
|
||||
homeDir := viper.Get(flags.FlagHome).(string) // TODO
|
||||
scRawDb, err := db.NewGoLevelDB("application", filepath.Join(homeDir, "data"), nil)
|
||||
viper.Set(serverv2.FlagHome, DefaultNodeHome) // TODO possibly set earlier when viper is created
|
||||
scRawDb, err := db.NewGoLevelDB("application", filepath.Join(DefaultNodeHome, "data"), nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -113,7 +111,7 @@ func NewSimApp(
|
||||
logger,
|
||||
&root.FactoryOptions{
|
||||
Logger: logger,
|
||||
RootDir: homeDir,
|
||||
RootDir: DefaultNodeHome,
|
||||
SSType: 0,
|
||||
SCType: 0,
|
||||
SCPruneOptions: &store.PruneOptions{
|
||||
@@ -126,7 +124,7 @@ func NewSimApp(
|
||||
},
|
||||
SCRawDB: scRawDb,
|
||||
},
|
||||
servertypes.AppOptions(viper),
|
||||
viper,
|
||||
|
||||
// ADVANCED CONFIGURATION
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/debug"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
@@ -49,12 +48,8 @@ func (t *temporaryTxDecoder) DecodeJSON(bz []byte) (transaction.Tx, error) {
|
||||
return t.txConfig.TxJSONDecoder()(bz)
|
||||
}
|
||||
|
||||
func newApp(
|
||||
logger log.Logger,
|
||||
viper *viper.Viper,
|
||||
) serverv2.AppI[transaction.Tx] {
|
||||
sa := simapp.NewSimApp(logger, viper)
|
||||
return sa
|
||||
func newApp(logger log.Logger, viper *viper.Viper) serverv2.AppI[transaction.Tx] {
|
||||
return simapp.NewSimApp(logger, viper)
|
||||
}
|
||||
|
||||
func initRootCmd(
|
||||
@@ -184,12 +179,6 @@ func appExport(
|
||||
viper *viper.Viper,
|
||||
modulesToExport []string,
|
||||
) (servertypes.ExportedApp, error) {
|
||||
// this check is necessary as we use the flag in x/upgrade.
|
||||
// we can exit more gracefully by checking the flag here.
|
||||
homePath, ok := viper.Get(flags.FlagHome).(string)
|
||||
if !ok || homePath == "" {
|
||||
return servertypes.ExportedApp{}, errors.New("application home not set")
|
||||
}
|
||||
// overwrite the FlagInvCheckPeriod
|
||||
viper.Set(server.FlagInvCheckPeriod, 1)
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ func ProvideClientContext(
|
||||
|
||||
// Read the config to overwrite the default values with the values from the config file
|
||||
customClientTemplate, customClientConfig := initClientConfig()
|
||||
clientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig(clientCtx, customClientTemplate, customClientConfig)
|
||||
clientCtx, err = config.CreateClientConfig(clientCtx, customClientTemplate, customClientConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user