diff --git a/CHANGELOG.md b/CHANGELOG.md index a1e787f90e35..698eb3fb832d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (deps) Bump Tendermint version to [v0.34.24](https://github.com/tendermint/tendermint/releases/tag/v0.34.24). * [#13651](https://github.com/cosmos/cosmos-sdk/pull/13651) Update `server/config/config.GetConfig` function. +* [#13781](https://github.com/cosmos/cosmos-sdk/pull/13781) Remove `client/keys.KeysCdc`. +* [#14175](https://github.com/cosmos/cosmos-sdk/pull/14175) Add `server.DefaultBaseappOptions(appopts)` function to reduce boiler plate in root.go. ### State Machine Breaking diff --git a/server/util.go b/server/util.go index ed1523412d67..6de4fd835bb8 100644 --- a/server/util.go +++ b/server/util.go @@ -27,18 +27,13 @@ import ( tmlog "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" - corectx "cosmossdk.io/core/context" - corestore "cosmossdk.io/core/store" - "cosmossdk.io/log" - "cosmossdk.io/store" - "cosmossdk.io/store/snapshots" - snapshottypes "cosmossdk.io/store/snapshots/types" - storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/config" "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/snapshots" + snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" + "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/cosmos/cosmos-sdk/version" @@ -477,7 +472,7 @@ func openTraceWriter(traceWriterFile string) (w io.WriteCloser, err error) { // DefaultBaseappOptions returns the default baseapp options provided by the Cosmos SDK func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { - var cache storetypes.MultiStorePersistentCache + var cache sdk.MultiStorePersistentCache if cast.ToBool(appOpts.Get(FlagInterBlockCache)) { cache = store.NewCommitKVStoreCacheManager() @@ -488,23 +483,12 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { panic(err) } - homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) - chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) - if chainID == "" { - // fallback to genesis chain-id - reader, err := os.Open(filepath.Join(homeDir, "config", "genesis.json")) - if err != nil { - panic(err) - } - defer reader.Close() - - chainID, err = genutiltypes.ParseChainIDFromGenesis(reader) - if err != nil { - panic(fmt.Errorf("failed to parse chain-id from genesis file: %w", err)) - } + snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") + snapshotDB, err := dbm.NewDB("metadata", GetAppDBBackend(appOpts), snapshotDir) + if err != nil { + panic(err) } - - snapshotStore, err := GetSnapshotStore(appOpts) + snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) if err != nil { panic(err) } @@ -514,15 +498,6 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { cast.ToUint32(appOpts.Get(FlagStateSyncSnapshotKeepRecent)), ) - defaultMempool := baseapp.SetMempool(mempool.NoOpMempool{}) - if maxTxs := cast.ToInt(appOpts.Get(FlagMempoolMaxTxs)); maxTxs >= 0 { - defaultMempool = baseapp.SetMempool( - mempool.NewSenderNonceMempool( - mempool.SenderNonceMaxTxOpt(maxTxs), - ), - ) - } - return []func(*baseapp.BaseApp){ baseapp.SetPruning(pruningOpts), baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(FlagMinGasPrices))), @@ -535,27 +510,5 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { baseapp.SetSnapshot(snapshotStore, snapshotOptions), baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(FlagIAVLCacheSize))), baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(FlagDisableIAVLFastNode))), - defaultMempool, - baseapp.SetChainID(chainID), - baseapp.SetQueryGasLimit(cast.ToUint64(appOpts.Get(FlagQueryGasLimit))), } } - -func GetSnapshotStore(appOpts types.AppOptions) (*snapshots.Store, error) { - homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) - snapshotDir := filepath.Join(homeDir, "data", "snapshots") - if err := os.MkdirAll(snapshotDir, 0o744); err != nil { - return nil, fmt.Errorf("failed to create snapshots directory: %w", err) - } - - snapshotDB, err := dbm.NewDB("metadata", GetAppDBBackend(appOpts), snapshotDir) - if err != nil { - return nil, err - } - snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) - if err != nil { - return nil, err - } - - return snapshotStore, nil -} diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 68ba6cb024cf..d6e557af5f60 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -5,13 +5,9 @@ package cmd import ( "os" - "github.com/spf13/cobra" + "github.com/spf13/cast" - coretesting "cosmossdk.io/core/testing" - "cosmossdk.io/log" - "cosmossdk.io/simapp" - "cosmossdk.io/simapp/params" - txsigning "cosmossdk.io/x/tx/signing" + "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -21,7 +17,12 @@ import ( "github.com/cosmos/cosmos-sdk/client/pruning" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/server" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + serverconfig "github.com/cosmos/cosmos-sdk/server/config" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/simapp/params" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -266,42 +267,20 @@ type appCreator struct { // newApp is an appCreator func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application { - var cache sdk.MultiStorePersistentCache - - if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) { - cache = store.NewCommitKVStoreCacheManager() - } + baseappOptions := server.DefaultBaseappOptions(appOpts) skipUpgradeHeights := make(map[int64]bool) for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { skipUpgradeHeights[int64(h)] = true } - // autocli opts - customClientTemplate, customClientConfig := initClientConfig() - var err error - initClientCtx, err = config.CreateClientConfig(initClientCtx, customClientTemplate, customClientConfig) - if err != nil { - panic(err) - } - return simapp.NewSimApp( logger, db, traceStore, true, skipUpgradeHeights, cast.ToString(appOpts.Get(flags.FlagHome)), cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encCfg, appOpts, - baseapp.SetPruning(pruningOpts), - baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), - baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))), - baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))), - baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))), - baseapp.SetInterBlockCache(cache), - baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))), - baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))), - baseapp.SetSnapshot(snapshotStore, snapshotOptions), - baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))), - baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(server.FlagIAVLFastNode))), + baseappOptions..., ) }