diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index efc10712e..70cba820c 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -27,20 +27,20 @@ func TestGetBlockRentionHeight(t *testing.T) { expected int64 }{ "defaults": { - bapp: NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{}), + bapp: NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{}), maxAgeBlocks: 0, commitHeight: 499000, expected: 0, }, "pruning unbonding time only": { - bapp: NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{}, SetMinRetainBlocks(1)), + bapp: NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{}, SetMinRetainBlocks(1)), maxAgeBlocks: 362880, commitHeight: 499000, expected: 136120, }, "pruning iavl snapshot only": { bapp: NewBaseApp( - name, logger, db, nil, &testutil.TestAppOpts{}, + name, logger, db, nil, nil, &testutil.TestAppOpts{}, SetPruning(sdk.PruningOptions{KeepEvery: 10000}), SetMinRetainBlocks(1), ), @@ -50,7 +50,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "pruning state sync snapshot only": { bapp: NewBaseApp( - name, logger, db, nil, &testutil.TestAppOpts{}, + name, logger, db, nil, nil, &testutil.TestAppOpts{}, SetSnapshotInterval(50000), SetSnapshotKeepRecent(3), SetMinRetainBlocks(1), @@ -61,7 +61,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "pruning min retention only": { bapp: NewBaseApp( - name, logger, db, nil, &testutil.TestAppOpts{}, + name, logger, db, nil, nil, &testutil.TestAppOpts{}, SetMinRetainBlocks(400000), ), maxAgeBlocks: 0, @@ -70,7 +70,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "pruning all conditions": { bapp: NewBaseApp( - name, logger, db, nil, &testutil.TestAppOpts{}, + name, logger, db, nil, nil, &testutil.TestAppOpts{}, SetPruning(sdk.PruningOptions{KeepEvery: 10000}), SetMinRetainBlocks(400000), SetSnapshotInterval(50000), SetSnapshotKeepRecent(3), @@ -81,7 +81,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "no pruning due to no persisted state": { bapp: NewBaseApp( - name, logger, db, nil, &testutil.TestAppOpts{}, + name, logger, db, nil, nil, &testutil.TestAppOpts{}, SetPruning(sdk.PruningOptions{KeepEvery: 10000}), SetMinRetainBlocks(400000), SetSnapshotInterval(50000), SetSnapshotKeepRecent(3), @@ -92,7 +92,7 @@ func TestGetBlockRentionHeight(t *testing.T) { }, "disable pruning": { bapp: NewBaseApp( - name, logger, db, nil, &testutil.TestAppOpts{}, + name, logger, db, nil, nil, &testutil.TestAppOpts{}, SetPruning(sdk.PruningOptions{KeepEvery: 10000}), SetMinRetainBlocks(0), SetSnapshotInterval(50000), SetSnapshotKeepRecent(3), @@ -131,7 +131,7 @@ func TestBaseAppCreateQueryContext(t *testing.T) { logger := defaultLogger() db := dbm.NewMemDB() name := t.Name() - app := NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{}) + app := NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{}) app.FinalizeBlock(context.Background(), &abci.RequestFinalizeBlock{Height: 1}) app.SetDeliverStateToCommit() diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 6b85524f7..8bc1af704 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -152,7 +152,7 @@ type BaseApp struct { //nolint: maligned compactionInterval uint64 - tmConfig *tmcfg.Config + TmConfig *tmcfg.Config } type appStore struct { @@ -207,7 +207,7 @@ type snapshotData struct { // // NOTE: The db is used to store the version number for now. func NewBaseApp( - name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, appOpts servertypes.AppOptions, options ...func(*BaseApp), + name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, tmConfig *tmcfg.Config, appOpts servertypes.AppOptions, options ...func(*BaseApp), ) *BaseApp { cms := store.NewCommitMultiStore(db) archivalVersion := cast.ToInt64(appOpts.Get(FlagArchivalVersion)) @@ -239,6 +239,7 @@ func NewBaseApp( msgServiceRouter: NewMsgServiceRouter(), }, txDecoder: txDecoder, + TmConfig: tmConfig, } for _, option := range options { @@ -259,10 +260,6 @@ func NewBaseApp( return app } -func (app *BaseApp) SetTendermintConfig(cfg *tmcfg.Config) { - app.tmConfig = cfg -} - // Name returns the name of the BaseApp. func (app *BaseApp) Name() string { return app.name @@ -1112,7 +1109,7 @@ func (app *BaseApp) ReloadDB() error { if err := app.db.Close(); err != nil { return err } - db, err := sdk.NewLevelDB("application", app.tmConfig.DBDir()) + db, err := sdk.NewLevelDB("application", app.TmConfig.DBDir()) if err != nil { return err } diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index baa376b58..f72609290 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -36,7 +36,7 @@ func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp { db := dbm.NewMemDB() codec := codec.NewLegacyAmino() registerTestCodec(codec) - return NewBaseApp(name, logger, db, testTxDecoder(codec), &testutil.TestAppOpts{}, options...) + return NewBaseApp(name, logger, db, testTxDecoder(codec), nil, &testutil.TestAppOpts{}, options...) } func registerTestCodec(cdc *codec.LegacyAmino) { @@ -83,7 +83,7 @@ func TestLoadVersionPruning(t *testing.T) { pruningOpt := SetPruning(pruningOptions) db := dbm.NewMemDB() name := t.Name() - app := NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{}, pruningOpt) + app := NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{}, pruningOpt) // make a cap key and mount the store capKey := sdk.NewKVStoreKey("key1") @@ -122,7 +122,7 @@ func TestLoadVersionPruning(t *testing.T) { } // reload with LoadLatestVersion, check it loads last version - app = NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{}, pruningOpt) + app = NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{}, pruningOpt) app.MountStores(capKey) err = app.LoadLatestVersion() diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 7c1d7af2a..a6db9d3a6 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -67,7 +67,7 @@ func TestBaseApp_BlockGas(t *testing.T) { encCfg.InterfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}, ) - app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, "", 0, encCfg, &simapp.EmptyAppOptions{}, routerOpt) + app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, "", 0, nil, encCfg, &simapp.EmptyAppOptions{}, routerOpt) genState := simapp.NewDefaultGenesisState(encCfg.Marshaler) stateBytes, err := json.MarshalIndent(genState, "", " ") require.NoError(t, err) diff --git a/baseapp/deliver_tx_test.go b/baseapp/deliver_tx_test.go index 7a2a507b7..c9fdc767d 100644 --- a/baseapp/deliver_tx_test.go +++ b/baseapp/deliver_tx_test.go @@ -251,7 +251,7 @@ func TestBaseApp_EndBlock(t *testing.T) { } codec := codec.NewLegacyAmino() - app := NewBaseApp(name, logger, db, testTxDecoder(codec), &testutil.TestAppOpts{}) + app := NewBaseApp(name, logger, db, testTxDecoder(codec), nil, &testutil.TestAppOpts{}) app.SetParamStore(¶mStore{db: dbm.NewMemDB()}) app.InitChain(context.Background(), &abci.RequestInitChain{ ConsensusParams: cp, @@ -1062,7 +1062,7 @@ func TestInitChainer(t *testing.T) { db := dbm.NewMemDB() logger := defaultLogger() cc := codec.NewLegacyAmino() - app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}) + app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}) capKey := sdk.NewKVStoreKey("main") capKey2 := sdk.NewKVStoreKey("key2") app.MountStores(capKey, capKey2) @@ -1118,7 +1118,7 @@ func TestInitChainer(t *testing.T) { // reload app cc = codec.NewLegacyAmino() - app = NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}) + app = NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}) app.SetInitChainer(initChainer) app.MountStores(capKey, capKey2) err = app.LoadLatestVersion() // needed to make stores non-nil @@ -1146,7 +1146,7 @@ func TestInitChain_WithInitialHeight(t *testing.T) { db := dbm.NewMemDB() logger := defaultLogger() cc := codec.NewLegacyAmino() - app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}) + app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}) app.InitChain( context.Background(), &abci.RequestInitChain{ @@ -1163,7 +1163,7 @@ func TestBeginBlock_WithInitialHeight(t *testing.T) { db := dbm.NewMemDB() logger := defaultLogger() cc := codec.NewLegacyAmino() - app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}) + app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}) app.InitChain( context.Background(), &abci.RequestInitChain{ @@ -1539,7 +1539,7 @@ func TestOptionFunction(t *testing.T) { logger := defaultLogger() db := dbm.NewMemDB() cc := codec.NewLegacyAmino() - bap := NewBaseApp("starting name", logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, testChangeNameHelper("new name")) + bap := NewBaseApp("starting name", logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, testChangeNameHelper("new name")) require.Equal(t, bap.name, "new name", "BaseApp should have had name changed via option function") } @@ -1631,7 +1631,7 @@ func TestVersionSetterGetter(t *testing.T) { db := dbm.NewMemDB() name := t.Name() cc := codec.NewLegacyAmino() - app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, pruningOpt) + app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, pruningOpt) require.Equal(t, "", app.Version()) res, _ := app.Query(context.Background(), &abci.RequestQuery{Path: "app/version"}) @@ -1652,7 +1652,7 @@ func TestLoadVersionInvalid(t *testing.T) { db := dbm.NewMemDB() name := t.Name() cc := codec.NewLegacyAmino() - app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, pruningOpt) + app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, pruningOpt) err := app.LoadLatestVersion() require.Nil(t, err) @@ -1670,7 +1670,7 @@ func TestLoadVersionInvalid(t *testing.T) { // create a new app with the stores mounted under the same cap key cc = codec.NewLegacyAmino() - app = NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, pruningOpt) + app = NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, pruningOpt) // require we can load the latest version err = app.LoadVersion(1) @@ -1776,7 +1776,7 @@ func TestLoadVersion(t *testing.T) { db := dbm.NewMemDB() name := t.Name() cc := codec.NewLegacyAmino() - app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, pruningOpt) + app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, pruningOpt) // make a cap key and mount the store err := app.LoadLatestVersion() // needed to make stores non-nil @@ -1878,7 +1878,7 @@ func TestSetLoader(t *testing.T) { opts = append(opts, tc.setLoader) } cc := codec.NewLegacyAmino() - app := NewBaseApp(t.Name(), defaultLogger(), db, testTxDecoder(cc), &testutil.TestAppOpts{}, opts...) + app := NewBaseApp(t.Name(), defaultLogger(), db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, opts...) app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) err := app.LoadLatestVersion() require.Nil(t, err) diff --git a/baseapp/grpcrouter_test.go b/baseapp/grpcrouter_test.go index 54e4c12f5..238aaa15d 100644 --- a/baseapp/grpcrouter_test.go +++ b/baseapp/grpcrouter_test.go @@ -2,9 +2,10 @@ package baseapp_test import ( "context" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "testing" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -55,7 +56,7 @@ func TestRegisterQueryServiceTwice(t *testing.T) { // Setup baseapp. db := dbm.NewMemDB() encCfg := simapp.MakeTestEncodingConfig() - app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), &testutil.TestAppOpts{}) + app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), nil, &testutil.TestAppOpts{}) app.SetInterfaceRegistry(encCfg.InterfaceRegistry) testdata.RegisterInterfaces(encCfg.InterfaceRegistry) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index a10bbc2b6..6c504aba0 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -24,7 +24,7 @@ func TestRegisterMsgService(t *testing.T) { // Create an encoding config that doesn't register testdata Msg services. encCfg := simapp.MakeTestEncodingConfig() - app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), &testutil.TestAppOpts{}) + app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), nil, &testutil.TestAppOpts{}) app.SetInterfaceRegistry(encCfg.InterfaceRegistry) require.Panics(t, func() { testdata.RegisterMsgServer( @@ -47,7 +47,7 @@ func TestRegisterMsgServiceTwice(t *testing.T) { // Setup baseapp. db := dbm.NewMemDB() encCfg := simapp.MakeTestEncodingConfig() - app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), &testutil.TestAppOpts{}) + app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), nil, &testutil.TestAppOpts{}) app.SetInterfaceRegistry(encCfg.InterfaceRegistry) testdata.RegisterInterfaces(encCfg.InterfaceRegistry) @@ -73,7 +73,7 @@ func TestMsgService(t *testing.T) { encCfg := simapp.MakeTestEncodingConfig() testdata.RegisterInterfaces(encCfg.InterfaceRegistry) db := dbm.NewMemDB() - app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), &testutil.TestAppOpts{}) + app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), nil, &testutil.TestAppOpts{}) app.SetInterfaceRegistry(encCfg.InterfaceRegistry) testdata.RegisterMsgServer( app.MsgServiceRouter(), diff --git a/client/pruning/main.go b/client/pruning/main.go index 976ebf0a0..09c6316e2 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -63,7 +63,7 @@ func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command { } logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) - app := appCreator(logger, db, nil, vp) + app := appCreator(logger, db, nil, nil, vp) cms := app.CommitMultiStore() rootMultiStore, ok := cms.(*rootmulti.Store) diff --git a/server/config/config.go b/server/config/config.go index e81b23ac8..b800cdb37 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -80,8 +80,6 @@ type BaseConfig struct { // CompactionInterval sets (in seconds) the interval between forced levelDB // compaction. A value of 0 means no forced levelDB CompactionInterval uint64 `mapstructure:"compaction-interval"` - - LoadLatest bool `mapstructure:"load-latest"` } // APIConfig defines the API listener configuration. @@ -225,7 +223,6 @@ func DefaultConfig() *Config { IAVLCacheSize: 781250, // 50 MB IAVLDisableFastNode: true, CompactionInterval: 0, - LoadLatest: true, }, Telemetry: telemetry.Config{ Enabled: false, @@ -294,7 +291,6 @@ func GetConfig(v *viper.Viper) (Config, error) { IAVLCacheSize: v.GetUint64("iavl-cache-size"), IAVLDisableFastNode: v.GetBool("iavl-disable-fastnode"), CompactionInterval: v.GetUint64("compaction-interval"), - LoadLatest: v.GetBool("load-latest"), }, Telemetry: telemetry.Config{ ServiceName: v.GetString("telemetry.service-name"), @@ -349,12 +345,6 @@ func (c Config) ValidateBasic(tendermintConfig *tmcfg.Config) error { "cannot enable state sync snapshots with '%s' pruning setting", storetypes.PruningOptionEverything, ) } - if c.BaseConfig.LoadLatest && tendermintConfig.DBSync.Enable { - return sdkerrors.ErrAppConfig.Wrap("cannot load latest with DB sync enabled") - } - if !c.BaseConfig.LoadLatest && !tendermintConfig.DBSync.Enable { - return sdkerrors.ErrAppConfig.Wrap("shoulkd load latest with DB sync disabled") - } return nil } diff --git a/server/config/toml.go b/server/config/toml.go index f76c2e59e..695fcbeec 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -65,9 +65,6 @@ min-retain-blocks = {{ .BaseConfig.MinRetainBlocks }} # InterBlockCache enables inter-block caching. inter-block-cache = {{ .BaseConfig.InterBlockCache }} -# Whether to load the latest version of store immediately upon start -load-latest = {{ .BaseConfig.LoadLatest }} - # IndexEvents defines the set of events in the form {eventType}.{attributeKey}, # which informs Tendermint what to index. If empty, all events will be indexed. # diff --git a/server/export_test.go b/server/export_test.go index e14cf2ff7..c59ca9b2b 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -127,7 +127,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t logger := log.NewTestingLogger(t) db := dbm.NewMemDB() encCfg := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg, &simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, nil, encCfg, &simapp.EmptyAppOptions{}) serverCtx := server.NewDefaultContext() serverCtx.Config.RootDir = tempDir @@ -152,13 +152,13 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t var simApp *simapp.SimApp if height != -1 { - simApp = simapp.NewSimApp(logger, db, nil, false, map[int64]bool{}, "", 0, encCfg, &simapp.EmptyAppOptions{}) + simApp = simapp.NewSimApp(logger, db, nil, false, map[int64]bool{}, "", 0, nil, encCfg, &simapp.EmptyAppOptions{}) if err := simApp.LoadHeight(height); err != nil { return types.ExportedApp{}, err } } else { - simApp = simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, "", 0, encCfg, &simapp.EmptyAppOptions{}) + simApp = simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, "", 0, nil, encCfg, &simapp.EmptyAppOptions{}) } return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) diff --git a/server/mock/app.go b/server/mock/app.go index 5d05dc0c2..959bce012 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -13,8 +13,8 @@ import ( bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/testutil" storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -31,7 +31,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { capKeyMainStore := sdk.NewKVStoreKey("main") // Create BaseApp. - baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx, &testutil.TestAppOpts{}) + baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx, nil, &testutil.TestAppOpts{}) // Set mounts for BaseApp's MultiStore. baseApp.MountStores(capKeyMainStore) diff --git a/server/rollback.go b/server/rollback.go index d3d06861e..7d95e96dc 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -37,6 +37,7 @@ application. ctx.Logger, db, nil, + nil, ctx.Viper, ) diff --git a/server/start.go b/server/start.go index 3d6365bf8..1129a184d 100644 --- a/server/start.go +++ b/server/start.go @@ -55,7 +55,6 @@ const ( FlagTracing = "tracing" FlagProfile = "profile" FlagInvCheckPeriod = "inv-check-period" - FlagLoadLatest = "load-latest" FlagPruning = "pruning" FlagPruningKeepRecent = "pruning-keep-recent" @@ -241,7 +240,6 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks") cmd.Flags().Uint64(FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks") cmd.Flags().Uint64(FlagCompactionInterval, 0, "Time interval in between forced levelDB compaction. 0 means no forced compaction.") - cmd.Flags().Bool(FlagLoadLatest, true, "Whether to load latest version from store immediately after app creation") cmd.Flags().Bool(flagGRPCOnly, false, "Start the node in gRPC query only mode (no Tendermint process is started)") cmd.Flags().Bool(flagGRPCEnable, true, "Define if the gRPC server should be enabled") @@ -282,7 +280,7 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error { return err } - app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) + app := appCreator(ctx.Logger, db, traceWriter, nil, ctx.Viper) svr, err := server.NewServer(ctx.Logger.With("module", "abci-server"), addr, transport, app) if err != nil { @@ -359,8 +357,7 @@ func startInProcess( "This defaults to 0 in the current version, but will error in the next version " + "(SDK v0.45). Please explicitly put the desired minimum-gas-prices in your app.toml.") } - app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) - app.SetTendermintConfig(ctx.Config) + app := appCreator(ctx.Logger, db, traceWriter, ctx.Config, ctx.Viper) var ( tmNode service.Service diff --git a/server/types/app.go b/server/types/app.go index f397ee9b0..c95a8b3a2 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -9,7 +9,7 @@ import ( "github.com/gogo/protobuf/grpc" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - tmconfig "github.com/tendermint/tendermint/config" + tmcfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" @@ -58,15 +58,13 @@ type ( // CommitMultiStore Returns the multistore instance CommitMultiStore() sdk.CommitMultiStore - SetTendermintConfig(*tmconfig.Config) - // Close any open resources Close() error } // AppCreator is a function that allows us to lazily initialize an // application using various configurations. - AppCreator func(log.Logger, dbm.DB, io.Writer, AppOptions) Application + AppCreator func(log.Logger, dbm.DB, io.Writer, *tmcfg.Config, AppOptions) Application // ModuleInitFlags takes a start command and adds modules specific init flags. ModuleInitFlags func(startCmd *cobra.Command) diff --git a/simapp/app.go b/simapp/app.go index 27c0d8a9c..6fcd7e4f5 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -13,6 +13,7 @@ import ( "github.com/rakyll/statik/fs" "github.com/spf13/cast" abci "github.com/tendermint/tendermint/abci/types" + tmcfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -200,7 +201,7 @@ func init() { // NewSimApp returns a reference to an initialized SimApp. func NewSimApp( logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool, - homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, + homePath string, invCheckPeriod uint, tmConfig *tmcfg.Config, encodingConfig simappparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { @@ -208,7 +209,7 @@ func NewSimApp( legacyAmino := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry - bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), appOpts, baseAppOptions...) + bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), tmConfig, appOpts, baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) diff --git a/simapp/app_test.go b/simapp/app_test.go index 2bf130ace..8ac6e82ec 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -3,9 +3,10 @@ package simapp import ( "context" "encoding/json" - aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol" "testing" + aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -40,7 +41,7 @@ import ( func TestSimAppExportAndBlockedAddrs(t *testing.T) { encCfg := MakeTestEncodingConfig() db := dbm.NewMemDB() - app := NewSimApp(log.NewTestingLogger(t), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, &EmptyAppOptions{}) + app := NewSimApp(log.NewTestingLogger(t), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, nil, encCfg, &EmptyAppOptions{}) for acc := range maccPerms { require.True( @@ -64,7 +65,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { app.Commit(context.Background()) // Making a new app object with the db, so that initchain hasn't been called - app2 := NewSimApp(log.NewTestingLogger(t), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, &EmptyAppOptions{}) + app2 := NewSimApp(log.NewTestingLogger(t), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, nil, encCfg, &EmptyAppOptions{}) _, err = app2.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } @@ -78,10 +79,10 @@ func TestRunMigrations(t *testing.T) { db := dbm.NewMemDB() encCfg := MakeTestEncodingConfig() logger := log.NewTestingLogger(t) - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, &EmptyAppOptions{}) + app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, nil, encCfg, &EmptyAppOptions{}) // Create a new baseapp and configurator for the purpose of this test. - bApp := baseapp.NewBaseApp(appName, logger, db, encCfg.TxConfig.TxDecoder(), &testutil.TestAppOpts{}) + bApp := baseapp.NewBaseApp(appName, logger, db, encCfg.TxConfig.TxDecoder(), nil, &testutil.TestAppOpts{}) bApp.SetCommitMultiStoreTracer(nil) bApp.SetInterfaceRegistry(encCfg.InterfaceRegistry) app.BaseApp = bApp @@ -203,7 +204,7 @@ func TestInitGenesisOnMigration(t *testing.T) { db := dbm.NewMemDB() encCfg := MakeTestEncodingConfig() logger := log.NewTestingLogger(t) - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, &EmptyAppOptions{}) + app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, nil, encCfg, &EmptyAppOptions{}) ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) // Create a mock module. This module will serve as the new module we're @@ -246,7 +247,7 @@ func TestInitGenesisOnMigration(t *testing.T) { func TestUpgradeStateOnGenesis(t *testing.T) { encCfg := MakeTestEncodingConfig() db := dbm.NewMemDB() - app := NewSimApp(log.NewTestingLogger(t), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, &EmptyAppOptions{}) + app := NewSimApp(log.NewTestingLogger(t), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, nil, encCfg, &EmptyAppOptions{}) genesisState := NewDefaultGenesisState(encCfg.Marshaler) stateBytes, err := json.MarshalIndent(genesisState, "", " ") require.NoError(t, err) diff --git a/simapp/sim_bench_test.go b/simapp/sim_bench_test.go index 9cb6d85ff..5bae60988 100644 --- a/simapp/sim_bench_test.go +++ b/simapp/sim_bench_test.go @@ -32,7 +32,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { } }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), &EmptyAppOptions{}, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, nil, MakeTestEncodingConfig(), &EmptyAppOptions{}, interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( @@ -82,7 +82,7 @@ func BenchmarkInvariants(b *testing.B) { } }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), &EmptyAppOptions{}, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, nil, MakeTestEncodingConfig(), &EmptyAppOptions{}, interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( diff --git a/simapp/sim_test.go b/simapp/sim_test.go index c2e35732b..7c8670fbd 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -68,7 +68,7 @@ func TestFullAppSimulation(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, nil, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) // run randomized simulation @@ -106,7 +106,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, nil, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) // Run randomized simulation @@ -146,7 +146,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, nil, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "SimApp", newApp.Name()) var genesisState GenesisState @@ -202,7 +202,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, nil, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) // Run randomized simulation @@ -247,7 +247,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, nil, MakeTestEncodingConfig(), &EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "SimApp", newApp.Name()) newApp.InitChain(context.Background(), &abci.RequestInitChain{ @@ -298,7 +298,7 @@ func TestAppStateDeterminism(t *testing.T) { } db := dbm.NewMemDB() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), &EmptyAppOptions{}, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, nil, MakeTestEncodingConfig(), &EmptyAppOptions{}, interBlockCacheOpt()) fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index c68374ef6..441c8ede8 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cast" "github.com/spf13/cobra" tmmain "github.com/tendermint/tendermint/cmd/tendermint/commands" + tmcfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" "go.opentelemetry.io/otel/attribute" @@ -251,7 +252,7 @@ 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 { +func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, tmConfig *tmcfg.Config, appOpts servertypes.AppOptions) servertypes.Application { var cache sdk.MultiStorePersistentCache if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) { @@ -282,6 +283,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a logger, db, traceStore, true, skipUpgradeHeights, cast.ToString(appOpts.Get(flags.FlagHome)), cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), + tmConfig, a.encCfg, appOpts, baseapp.SetPruning(pruningOpts), @@ -314,13 +316,13 @@ func (a appCreator) appExport( } if height != -1 { - simApp = simapp.NewSimApp(logger, db, traceStore, false, map[int64]bool{}, homePath, uint(1), a.encCfg, appOpts) + simApp = simapp.NewSimApp(logger, db, traceStore, false, map[int64]bool{}, homePath, uint(1), nil, a.encCfg, appOpts) if err := simApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - simApp = simapp.NewSimApp(logger, db, traceStore, true, map[int64]bool{}, homePath, uint(1), a.encCfg, appOpts) + simApp = simapp.NewSimApp(logger, db, traceStore, true, map[int64]bool{}, homePath, uint(1), nil, a.encCfg, appOpts) } return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 62667c346..566df960b 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -56,7 +56,7 @@ var DefaultConsensusParams = &tmproto.ConsensusParams{ func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { db := dbm.NewMemDB() encCdc := MakeTestEncodingConfig() - app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, &EmptyAppOptions{}) + app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, nil, encCdc, &EmptyAppOptions{}) if withGenesis { return app, NewDefaultGenesisState(encCdc.Marshaler) } diff --git a/store/rootmulti/rollback_test.go b/store/rootmulti/rollback_test.go index 84f761a68..d55da6f2c 100644 --- a/store/rootmulti/rollback_test.go +++ b/store/rootmulti/rollback_test.go @@ -17,7 +17,7 @@ import ( func setup(withGenesis bool, invCheckPeriod uint, db dbm.DB) (*simapp.SimApp, simapp.GenesisState) { encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, invCheckPeriod, encCdc, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, invCheckPeriod, nil, encCdc, simapp.EmptyAppOptions{}) if withGenesis { return app, simapp.NewDefaultGenesisState(encCdc.Marshaler) } @@ -78,7 +78,7 @@ func TestRollback(t *testing.T) { // recreate app to have clean check state encCdc := simapp.MakeTestEncodingConfig() - app = simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + app = simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, nil, encCdc, simapp.EmptyAppOptions{}) store = app.NewContext(true, tmproto.Header{}).KVStore(app.GetKey("bank")) require.Equal(t, []byte("value5"), store.Get([]byte("key"))) diff --git a/testutil/network/network.go b/testutil/network/network.go index f46d441e2..ec216f997 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -59,6 +59,7 @@ func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor { return func(val Validator) servertypes.Application { return simapp.NewSimApp( val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0, + nil, encodingCfg, &simapp.EmptyAppOptions{}, baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), diff --git a/x/capability/genesis_test.go b/x/capability/genesis_test.go index 079d3da59..875ea9793 100644 --- a/x/capability/genesis_test.go +++ b/x/capability/genesis_test.go @@ -35,7 +35,7 @@ func (suite *CapabilityTestSuite) TestGenesis() { // and initialize app from exported genesis state above. db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - newApp := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, &simapp.EmptyAppOptions{}) + newApp := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, nil, encCdc, &simapp.EmptyAppOptions{}) newKeeper := keeper.NewKeeper(suite.cdc, newApp.GetKey(types.StoreKey), newApp.GetMemKey(types.MemStoreKey)) newSk1 := newKeeper.ScopeToModule(banktypes.ModuleName) diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index b82c559f6..071c32a28 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -69,7 +69,7 @@ func TestImportExportQueues(t *testing.T) { } db := dbm.NewMemDB() - app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, simapp.MakeTestEncodingConfig(), &simapp.EmptyAppOptions{}) + app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, nil, simapp.MakeTestEncodingConfig(), &simapp.EmptyAppOptions{}) app2.InitChain( context.Background(), &abci.RequestInitChain{ diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 5a9ca6e0f..d9af90d70 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -39,7 +39,7 @@ var s TestSuite func setupTest(height int64, skip map[int64]bool) TestSuite { db := dbm.NewMemDB() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, skip, simapp.DefaultNodeHome, 0, simapp.MakeTestEncodingConfig(), &simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, skip, simapp.DefaultNodeHome, 0, nil, simapp.MakeTestEncodingConfig(), &simapp.EmptyAppOptions{}) genesisState := simapp.NewDefaultGenesisState(app.AppCodec()) stateBytes, err := json.MarshalIndent(genesisState, "", " ") if err != nil { diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 13a28d8f0..3033d9a95 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -120,7 +120,7 @@ func TestSetLoader(t *testing.T) { // load the app with the existing db opts := []func(*baseapp.BaseApp){baseapp.SetPruning(store.PruneNothing)} - origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, &testutil.TestAppOpts{}, opts...) + origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, nil, &testutil.TestAppOpts{}, opts...) origapp.MountStores(sdk.NewKVStoreKey(tc.origStoreKey)) err := origapp.LoadLatestVersion() require.Nil(t, err) @@ -136,7 +136,7 @@ func TestSetLoader(t *testing.T) { } // load the new app with the original app db - app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, &testutil.TestAppOpts{}, opts...) + app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, nil, &testutil.TestAppOpts{}, opts...) app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) err = app.LoadLatestVersion() require.Nil(t, err)