From 3d16229e885522f43c43b3b1b7fdd932d53dd722 Mon Sep 17 00:00:00 2001 From: Marko Date: Tue, 6 Dec 2022 14:28:18 +0000 Subject: [PATCH 1/3] refactor: provide a helper for baseapp options (#14175) * provide a helper for baseapp options * rename * changelog entry * fix spelling (cherry picked from commit 1b6192fec0ed1b13f1714be97a77ac79a75d6ee1) # Conflicts: # CHANGELOG.md # server/mock/app_test.go # simapp/simd/cmd/root.go --- CHANGELOG.md | 9 ++++++ server/mock/app_test.go | 8 ++++++ server/util.go | 50 +++++++++++++++++++++++++++++++++ simapp/simd/cmd/root.go | 61 +++++++++++++++++++++-------------------- 4 files changed, 98 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7424698b161c..1f21950fb0e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,15 @@ 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. +<<<<<<< HEAD +======= +* [#13781](https://github.com/cosmos/cosmos-sdk/pull/13781) Remove `client/keys.KeysCdc`. +* [#13802](https://github.com/cosmos/cosmos-sdk/pull/13802) Add --output-document flag to the export CLI command to allow writing genesis state to a file. +* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) `types/module.Manager` now supports the +`cosmossdk.io/core/appmodule.AppModule` API via the new `NewManagerFromMap` constructor. +* [#14019](https://github.com/cosmos/cosmos-sdk/issues/14019) Remove the interface casting to allow other implementations of a `CommitMultiStore`. +* [#14175](https://github.com/cosmos/cosmos-sdk/pull/14175) Add `server.DefaultBaseappOptions(appopts)` function to reduce boiler plate in root.go. +>>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) ### State Machine Breaking diff --git a/server/mock/app_test.go b/server/mock/app_test.go index 94362c887068..8b9e5b8025e2 100644 --- a/server/mock/app_test.go +++ b/server/mock/app_test.go @@ -1,7 +1,15 @@ package mock import ( +<<<<<<< HEAD "testing" +======= + "math/rand" + "testing" + "time" + + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" +>>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" diff --git a/server/util.go b/server/util.go index d9e4f930ba1f..b2c77223f107 100644 --- a/server/util.go +++ b/server/util.go @@ -25,10 +25,15 @@ import ( tmlog "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" + "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/store" + "github.com/cosmos/cosmos-sdk/store/snapshots" + snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/cosmos/cosmos-sdk/version" ) @@ -412,3 +417,48 @@ func openTraceWriter(traceWriterFile string) (w io.Writer, err error) { 0o666, ) } + +// DefaultBaseappOptions returns the default baseapp options provided by the Cosmos SDK +func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { + var cache sdk.MultiStorePersistentCache + + if cast.ToBool(appOpts.Get(FlagInterBlockCache)) { + cache = store.NewCommitKVStoreCacheManager() + } + + pruningOpts, err := GetPruningOptionsFromFlags(appOpts) + if err != nil { + panic(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 := snapshots.NewStore(snapshotDB, snapshotDir) + if err != nil { + panic(err) + } + + snapshotOptions := snapshottypes.NewSnapshotOptions( + cast.ToUint64(appOpts.Get(FlagStateSyncSnapshotInterval)), + cast.ToUint32(appOpts.Get(FlagStateSyncSnapshotKeepRecent)), + ) + + return []func(*baseapp.BaseApp){ + baseapp.SetPruning(pruningOpts), + baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(FlagMinGasPrices))), + baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(FlagHaltHeight))), + baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(FlagHaltTime))), + baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(FlagMinRetainBlocks))), + baseapp.SetInterBlockCache(cache), + baseapp.SetTrace(cast.ToBool(appOpts.Get(FlagTrace))), + baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(FlagIndexEvents))), + baseapp.SetSnapshot(snapshotStore, snapshotOptions), + baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(FlagIAVLCacheSize))), + baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(FlagDisableIAVLFastNode))), + baseapp.SetMempool(mempool.NewSenderNonceMempool( + mempool.SenderNonceMaxTxOpt(cast.ToInt(appOpts.Get(FlagMempoolMaxTxs))))), + } +} diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 8e6a4667b8a5..19feccba867a 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -4,16 +4,26 @@ import ( "errors" "io" "os" - "path/filepath" +<<<<<<< HEAD "github.com/spf13/cast" +======= + rosettaCmd "cosmossdk.io/tools/rosetta/cmd" + +>>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) "github.com/spf13/cobra" tmcfg "github.com/tendermint/tendermint/config" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" +<<<<<<< HEAD "github.com/cosmos/cosmos-sdk/baseapp" +======= + "cosmossdk.io/simapp" + "cosmossdk.io/simapp/params" + +>>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" @@ -24,11 +34,15 @@ import ( "github.com/cosmos/cosmos-sdk/server" serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" +<<<<<<< HEAD "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/cosmos/cosmos-sdk/store" +======= + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" +>>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) sdk "github.com/cosmos/cosmos-sdk/types" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -242,6 +256,7 @@ func txCommand() *cobra.Command { return cmd } +<<<<<<< HEAD type appCreator struct { encCfg params.EncodingConfig } @@ -249,35 +264,17 @@ 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() - } - - skipUpgradeHeights := make(map[int64]bool) - for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { - skipUpgradeHeights[int64(h)] = true - } - - pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts) - if err != nil { - panic(err) - } - - snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") - snapshotDB, err := dbm.NewDB("metadata", server.GetAppDBBackend(appOpts), snapshotDir) - if err != nil { - panic(err) - } - snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) - if err != nil { - panic(err) - } - - snapshotOptions := snapshottypes.NewSnapshotOptions( - cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval)), - cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent)), - ) +======= +// newApp creates the application +func newApp( + logger log.Logger, + db dbm.DB, + traceStore io.Writer, + appOpts servertypes.AppOptions, +) servertypes.Application { +>>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) + + baseappOptions := server.DefaultBaseappOptions(appOpts) return simapp.NewSimApp( logger, db, traceStore, true, skipUpgradeHeights, @@ -285,6 +282,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encCfg, appOpts, +<<<<<<< HEAD baseapp.SetPruning(pruningOpts), baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))), @@ -296,6 +294,9 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a baseapp.SetSnapshot(snapshotStore, snapshotOptions), baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))), baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(server.FlagDisableIAVLFastNode))), +======= + baseappOptions..., +>>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) ) } From a66d810d2bf8ba303f1e97fadc5670ce72538c2d Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 6 Dec 2022 16:22:59 +0100 Subject: [PATCH 2/3] conflicts --- CHANGELOG.md | 7 ------ server/mock/app_test.go | 8 ------- server/util.go | 7 ++---- simapp/simd/cmd/root.go | 50 ++++++----------------------------------- 4 files changed, 9 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f21950fb0e7..76597cf17705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,15 +41,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. -<<<<<<< HEAD -======= * [#13781](https://github.com/cosmos/cosmos-sdk/pull/13781) Remove `client/keys.KeysCdc`. -* [#13802](https://github.com/cosmos/cosmos-sdk/pull/13802) Add --output-document flag to the export CLI command to allow writing genesis state to a file. -* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) `types/module.Manager` now supports the -`cosmossdk.io/core/appmodule.AppModule` API via the new `NewManagerFromMap` constructor. -* [#14019](https://github.com/cosmos/cosmos-sdk/issues/14019) Remove the interface casting to allow other implementations of a `CommitMultiStore`. * [#14175](https://github.com/cosmos/cosmos-sdk/pull/14175) Add `server.DefaultBaseappOptions(appopts)` function to reduce boiler plate in root.go. ->>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) ### State Machine Breaking diff --git a/server/mock/app_test.go b/server/mock/app_test.go index 8b9e5b8025e2..94362c887068 100644 --- a/server/mock/app_test.go +++ b/server/mock/app_test.go @@ -1,15 +1,7 @@ package mock import ( -<<<<<<< HEAD "testing" -======= - "math/rand" - "testing" - "time" - - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ->>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" diff --git a/server/util.go b/server/util.go index b2c77223f107..e211bd245844 100644 --- a/server/util.go +++ b/server/util.go @@ -29,11 +29,10 @@ import ( "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" - "github.com/cosmos/cosmos-sdk/store/snapshots" - snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/cosmos/cosmos-sdk/version" ) @@ -458,7 +457,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))), - baseapp.SetMempool(mempool.NewSenderNonceMempool( - mempool.SenderNonceMaxTxOpt(cast.ToInt(appOpts.Get(FlagMempoolMaxTxs))))), } } diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 19feccba867a..0d7a79d81eb1 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -5,25 +5,14 @@ import ( "io" "os" -<<<<<<< HEAD "github.com/spf13/cast" -======= - rosettaCmd "cosmossdk.io/tools/rosetta/cmd" ->>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) "github.com/spf13/cobra" tmcfg "github.com/tendermint/tendermint/config" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" -<<<<<<< HEAD - "github.com/cosmos/cosmos-sdk/baseapp" -======= - "cosmossdk.io/simapp" - "cosmossdk.io/simapp/params" - ->>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" @@ -34,15 +23,10 @@ import ( "github.com/cosmos/cosmos-sdk/server" serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" -<<<<<<< HEAD + "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp/params" - "github.com/cosmos/cosmos-sdk/snapshots" - snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" - "github.com/cosmos/cosmos-sdk/store" -======= - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" ->>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) + sdk "github.com/cosmos/cosmos-sdk/types" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -256,47 +240,27 @@ func txCommand() *cobra.Command { return cmd } -<<<<<<< HEAD type appCreator struct { encCfg params.EncodingConfig } // 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 -======= -// newApp creates the application -func newApp( - logger log.Logger, - db dbm.DB, - traceStore io.Writer, - appOpts servertypes.AppOptions, -) servertypes.Application { ->>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) baseappOptions := server.DefaultBaseappOptions(appOpts) + skipUpgradeHeights := make(map[int64]bool) + for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { + skipUpgradeHeights[int64(h)] = true + } + return simapp.NewSimApp( logger, db, traceStore, true, skipUpgradeHeights, cast.ToString(appOpts.Get(flags.FlagHome)), cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encCfg, appOpts, -<<<<<<< HEAD - 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.FlagDisableIAVLFastNode))), -======= baseappOptions..., ->>>>>>> 1b6192fec (refactor: provide a helper for baseapp options (#14175)) ) } From f1235973732c0988bea9eaa658247aa031e5bfc4 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 6 Dec 2022 16:53:46 +0100 Subject: [PATCH 3/3] lint --- simapp/simd/cmd/root.go | 1 - 1 file changed, 1 deletion(-) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 0d7a79d81eb1..d8b71c6df53a 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -246,7 +246,6 @@ 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 { - baseappOptions := server.DefaultBaseappOptions(appOpts) skipUpgradeHeights := make(map[int64]bool)