diff --git a/baseapp/abci.go b/baseapp/abci.go index 273a35deb58..d29c7902263 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -44,7 +44,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC if req.InitialHeight > 1 { app.initialHeight = req.InitialHeight initHeader = tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} - err := app.store.SetInitialVersion(uint64(req.InitialHeight)) + err := app.cms.SetInitialVersion(uint64(req.InitialHeight)) if err != nil { panic(err) } @@ -114,7 +114,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC // Info implements the ABCI interface. func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo { - lastCommitID := app.store.LastCommitID() + lastCommitID := app.cms.LastCommitID() return abci.ResponseInfo{ Data: app.name, @@ -146,8 +146,8 @@ func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery { // BeginBlock implements the ABCI application interface. func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) { - if app.store.TracingEnabled() { - app.store.SetTracingContext(sdk.TraceContext( + if app.cms.TracingEnabled() { + app.cms.SetTracingContext(sdk.TraceContext( map[string]interface{}{"blockHeight": req.Header.Height}, )) } @@ -313,9 +313,9 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) { // Write the DeliverTx state into branched storage and commit the MultiStore. // The write to the DeliverTx state writes all state transitions to the root - // MultiStore (app.store) so when Commit() is called it persists those values. + // MultiStore (app.cms) so when Commit() is called it persists those values. app.deliverState.ms.Write() - commitID := app.store.Commit() + commitID := app.cms.Commit() app.logger.Info("commit synced", "commit", fmt.Sprintf("%X", commitID)) // Reset the Check state to the latest committed. @@ -624,7 +624,7 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e ) } - version, err := app.store.GetVersion(height) + version, err := app.cms.GetVersion(height) if err != nil { return sdk.Context{}, sdkerrors.Wrapf( @@ -778,12 +778,12 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res func handleQueryStore(app *BaseApp, path []string, req abci.RequestQuery) abci.ResponseQuery { // "/store" prefix for store queries - queryable, ok := app.store.(sdk.Queryable) + queryable, ok := app.cms.(sdk.Queryable) if !ok { return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "multistore doesn't support queries"), app.trace) } - req.Path = "/" + strings.Join(path[1:], "/") // = /store/main/key -> /main/key + req.Path = "/" + strings.Join(path[1:], "/") if req.Height <= 1 && req.Prove { return sdkerrors.QueryResult( diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index eef3eb6a530..d1077fe2ca7 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -67,7 +67,7 @@ type BaseApp struct { // nolint: maligned name string // application name from abci.Info db dbm.Connection storeOpts []StoreOption // options to configure root store - store sdk.CommitMultiStore // Main (uncached) state + cms sdk.CommitMultiStore // Main (uncached) state router sdk.Router // handle any kind of legacy message queryRouter sdk.QueryRouter // router for redirecting query calls grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls @@ -241,7 +241,7 @@ func (app *BaseApp) loadStore() error { return err } } - app.store, err = multi.NewV1MultiStoreAsV2(app.db, config) + app.cms, err = multi.NewV1MultiStoreAsV2(app.db, config) if err != nil { return fmt.Errorf("failed to load store: %w", err) } @@ -257,17 +257,17 @@ func (app *BaseApp) SetMsgServiceRouter(msgServiceRouter *MsgServiceRouter) { } func (app *BaseApp) CloseStore() error { - return app.store.Close() + return app.cms.Close() } // LastCommitID returns the last CommitID of the multistore. func (app *BaseApp) LastCommitID() stypes.CommitID { - return app.store.LastCommitID() + return app.cms.LastCommitID() } // LastBlockHeight returns the last committed block height. func (app *BaseApp) LastBlockHeight() int64 { - return app.store.LastCommitID().Version + return app.cms.LastCommitID().Version } // Init initializes the app. It seals the app, preventing any @@ -282,7 +282,7 @@ func (app *BaseApp) Init() error { // needed for the export command which inits from store but never calls initchain app.setCheckState(tmproto.Header{}) app.Seal() - return app.store.GetPruning().Validate() + return app.cms.GetPruning().Validate() } func (app *BaseApp) setMinGasPrices(gasPrices sdk.DecCoins) { @@ -338,7 +338,7 @@ func (app *BaseApp) IsSealed() bool { return app.sealed } // provided header, and minimum gas prices set. It is set on InitChain and reset // on Commit. func (app *BaseApp) setCheckState(header tmproto.Header) { - ms := app.store.CacheWrap() + ms := app.cms.CacheWrap() app.checkState = &state{ ms: ms, ctx: sdk.NewContext(ms, header, true, app.logger).WithMinGasPrices(app.minGasPrices), @@ -350,7 +350,7 @@ func (app *BaseApp) setCheckState(header tmproto.Header) { // and provided header. It is set on InitChain and BeginBlock and set to nil on // Commit. func (app *BaseApp) setDeliverState(header tmproto.Header) { - ms := app.store.CacheWrap() + ms := app.cms.CacheWrap() app.deliverState = &state{ ms: ms, ctx: sdk.NewContext(ms, header, false, app.logger), diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index c830ef3ac04..474e84e5046 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -21,7 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" dbm "github.com/cosmos/cosmos-sdk/db" - "github.com/cosmos/cosmos-sdk/db/memdb" pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types" "github.com/cosmos/cosmos-sdk/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" @@ -59,7 +58,7 @@ func defaultLogger() log.Logger { func newBaseApp(name string, options ...AppOption) *BaseApp { logger := defaultLogger() - db := memdb.NewDB() + db := dbm.NewMemDB() codec := codec.NewLegacyAmino() registerTestCodec(codec) return NewBaseApp(name, logger, db, testTxDecoder(codec), options...) @@ -91,7 +90,7 @@ func setupBaseApp(t *testing.T, options ...AppOption) *BaseApp { app := newBaseApp(t.Name(), options...) require.Equal(t, t.Name(), app.Name()) - app.SetParamStore(mock.NewParamStore(memdb.NewDB())) + app.SetParamStore(mock.NewParamStore(dbm.NewMemDB())) // stores are mounted err := app.Init() @@ -106,13 +105,13 @@ func setupBaseAppWithSnapshots(t *testing.T, config *setupConfig) (*BaseApp, err routerOpt := func(bapp *BaseApp) { bapp.Router().AddRoute(sdk.NewRoute(routeMsgKeyValue, func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { kv := msg.(*msgKeyValue) - bapp.store.GetKVStore(capKey2).Set(kv.Key, kv.Value) + bapp.cms.GetKVStore(capKey2).Set(kv.Key, kv.Value) return &sdk.Result{}, nil })) } snapshotTimeout := 1 * time.Minute - snapshotStore, err := snapshots.NewStore(memdb.NewDB(), testutil.GetTempDir(t)) + snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t)) require.NoError(t, err) app := setupBaseApp(t, @@ -168,9 +167,9 @@ func TestMountStores(t *testing.T) { app := setupBaseApp(t) // check both stores - store1 := app.store.GetKVStore(capKey1) + store1 := app.cms.GetKVStore(capKey1) require.NotNil(t, store1) - store2 := app.store.GetKVStore(capKey2) + store2 := app.cms.GetKVStore(capKey2) require.NotNil(t, store2) } @@ -178,7 +177,7 @@ func TestMountStores(t *testing.T) { func TestLoadVersion(t *testing.T) { logger := defaultLogger() pruningOpt := SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) - db := memdb.NewDB() + db := dbm.NewMemDB() name := t.Name() app := NewBaseApp(name, logger, db, nil, pruningOpt) @@ -250,7 +249,7 @@ func checkStore(t *testing.T, db dbm.Connection, ver int64, storeKey string, k, func TestVersionSetterGetter(t *testing.T) { logger := defaultLogger() pruningOpt := SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault)) - db := memdb.NewDB() + db := dbm.NewMemDB() name := t.Name() app := NewBaseApp(name, logger, db, nil, pruningOpt) require.Equal(t, "", app.Version()) @@ -272,7 +271,7 @@ func TestLoadVersionPruning(t *testing.T) { pruningOpt := SetPruning(pruningOptions) capKey := sdk.NewKVStoreKey("key1") schemaOpt := SetSubstores(capKey) - db := memdb.NewDB() + db := dbm.NewMemDB() name := t.Name() app := NewBaseApp(name, logger, db, nil, pruningOpt) @@ -300,12 +299,14 @@ func TestLoadVersionPruning(t *testing.T) { // TODO: behavior change - // CacheMultiStoreWithVersion returned no error on missing version (?) for _, v := range []int64{1, 2, 4} { - _, err = app.store.GetVersion(v) + s, err := app.cms.GetVersion(v) + require.NotNil(t, s) require.NoError(t, err, "version=%v", v) } for _, v := range []int64{3, 5, 6, 7} { - _, err = app.store.GetVersion(v) + s, err := app.cms.GetVersion(v) + require.NotNil(t, s) require.NoError(t, err, "version=%v", v) } require.NoError(t, app.CloseStore()) @@ -327,7 +328,7 @@ func testLoadVersionHelper(t *testing.T, app *BaseApp, expectedHeight int64, exp func TestOptionFunction(t *testing.T) { logger := defaultLogger() - db := memdb.NewDB() + db := dbm.NewMemDB() bap := NewBaseApp("starting name", logger, db, nil, testChangeNameHelper("new name")) require.Equal(t, "new name", bap.Name(), "BaseApp should have had name changed via option function") } @@ -416,7 +417,7 @@ func TestInitChainer(t *testing.T) { name := t.Name() // keep the db and logger ourselves so // we can reload the same app later - db := memdb.NewDB() + db := dbm.NewMemDB() logger := defaultLogger() capKey := sdk.NewKVStoreKey("main") capKey2 := sdk.NewKVStoreKey("key2") @@ -497,7 +498,7 @@ func TestInitChainer(t *testing.T) { func TestInitChain_WithInitialHeight(t *testing.T) { name := t.Name() - db := memdb.NewDB() + db := dbm.NewMemDB() logger := defaultLogger() app := NewBaseApp(name, logger, db, nil) @@ -513,7 +514,7 @@ func TestInitChain_WithInitialHeight(t *testing.T) { func TestBeginBlock_WithInitialHeight(t *testing.T) { name := t.Name() - db := memdb.NewDB() + db := dbm.NewMemDB() logger := defaultLogger() app := NewBaseApp(name, logger, db, nil) @@ -1963,7 +1964,7 @@ func TestWithRouter(t *testing.T) { } func TestBaseApp_EndBlock(t *testing.T) { - db := memdb.NewDB() + db := dbm.NewMemDB() name := t.Name() logger := defaultLogger() @@ -1974,7 +1975,7 @@ func TestBaseApp_EndBlock(t *testing.T) { } app := NewBaseApp(name, logger, db, nil) - app.SetParamStore(mock.NewParamStore(memdb.NewDB())) + app.SetParamStore(mock.NewParamStore(dbm.NewMemDB())) app.InitChain(abci.RequestInitChain{ ConsensusParams: cp, }) @@ -1995,11 +1996,11 @@ func TestBaseApp_EndBlock(t *testing.T) { } func TestBaseApp_Init(t *testing.T) { - db := memdb.NewDB() + db := dbm.NewMemDB() name := t.Name() logger := defaultLogger() - snapshotStore, err := snapshots.NewStore(memdb.NewDB(), testutil.GetTempDir(t)) + snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t)) require.NoError(t, err) testCases := map[string]struct { @@ -2140,7 +2141,7 @@ func TestBaseApp_Init(t *testing.T) { } // Check that settings were set correctly - actualPruning := tc.bapp.store.GetPruning() + actualPruning := tc.bapp.cms.GetPruning() require.Equal(t, tc.expectedPruning, actualPruning) if tc.expectedSnapshot.Interval == snapshottypes.SnapshotIntervalOff { diff --git a/baseapp/options.go b/baseapp/options.go index f6c3498fd97..bbbaf16ea5e 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -232,8 +232,8 @@ func (app *BaseApp) SetSnapshot(snapshotStore *snapshots.Store, opts snapshottyp app.snapshotManager = nil return } - app.store.SetSnapshotInterval(opts.Interval) - app.snapshotManager = snapshots.NewManager(snapshotStore, opts, app.store, nil, app.logger) + app.cms.SetSnapshotInterval(opts.Interval) + app.snapshotManager = snapshots.NewManager(snapshotStore, opts, app.cms, nil, app.logger) } // SetInterfaceRegistry sets the InterfaceRegistry. @@ -247,7 +247,7 @@ func (app *BaseApp) SetInterfaceRegistry(registry types.InterfaceRegistry) { func (app *BaseApp) SetStreamingService(s StreamingService) { // add the listeners for each StoreKey for key, lis := range s.Listeners() { - app.store.AddListeners(key, lis) + app.cms.AddListeners(key, lis) } // register the StreamingService within the BaseApp // BaseApp will pass BeginBlock, DeliverTx, and EndBlock requests and responses to the streaming services to update their ABCI context diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index 08180075ce6..49081943a2b 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -47,12 +47,12 @@ func (app *BaseApp) NewContext(isCheckTx bool, header tmproto.Header) sdk.Contex } func (app *BaseApp) NewUncachedContext(isCheckTx bool, header tmproto.Header) sdk.Context { - return sdk.NewContext(app.store, header, isCheckTx, app.logger) + return sdk.NewContext(app.cms, header, isCheckTx, app.logger) } // NewContextAt creates a context using a (read-only) store at a given block height. func (app *BaseApp) NewContextAt(isCheckTx bool, header tmproto.Header, height int64) (sdk.Context, error) { - view, err := app.store.GetVersion(height) + view, err := app.cms.GetVersion(height) if err != nil { return sdk.Context{}, err } diff --git a/db/types/types.go b/db/types/types.go index 8d024c175ea..39e48eab0ed 100644 --- a/db/types/types.go +++ b/db/types/types.go @@ -50,7 +50,6 @@ type Connection interface { // SaveNextVersion saves the current contents of the database and returns the next version ID, // which will be `Versions().Last()+1`. // Returns an error if any open Writer transactions exist. - // TODO: rename to something more descriptive? SaveNextVersion() (uint64, error) // SaveVersion attempts to save database at a specific version ID, which must be greater than or diff --git a/internal/db/tmdb_adapter.go b/internal/db/tmdb_adapter.go index f5e1805f968..0bece64cf67 100644 --- a/internal/db/tmdb_adapter.go +++ b/internal/db/tmdb_adapter.go @@ -8,7 +8,7 @@ package db import ( "errors" - dbm "github.com/cosmos/cosmos-sdk/db" + dbm "github.com/cosmos/cosmos-sdk/db/types" tmdb "github.com/tendermint/tm-db" ) diff --git a/server/export_test.go b/server/export_test.go index 21c800de63c..133a1b16718 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -21,7 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" dbm "github.com/cosmos/cosmos-sdk/db" - "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" @@ -128,7 +127,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t } logger, _ := log.NewDefaultLogger("plain", "info", false) - db := memdb.NewDB() + db := dbm.NewMemDB() encCfg := simapp.MakeTestEncodingConfig() app := simapp.NewSimApp(logger, db, nil, encCfg, simtestutil.NewAppOptionsWithFlagHome(tempDir)) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 879f65b3f7a..1d02fd7c109 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -353,7 +353,7 @@ func TestAppStateDeterminism(t *testing.T) { require.NoError(t, err) if config.Commit { - PrintStats(db) //TODO + PrintStats(db) } appHash := app.LastCommitID().Hash diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index aa1ed0624cd..a316f2b1a17 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -21,7 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/rpc" dbm "github.com/cosmos/cosmos-sdk/db" - "github.com/cosmos/cosmos-sdk/db/badgerdb" "github.com/cosmos/cosmos-sdk/server" serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -269,7 +268,7 @@ func (a appCreator) newApp( } snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") - snapshotDB, err := badgerdb.NewDB(filepath.Join(snapshotDir, "metadata")) + snapshotDB, err := dbm.NewDB("metadata", dbm.BadgerDBBackend, snapshotDir) if err != nil { panic(err) } diff --git a/store/v2alpha1/multi/compat.go b/store/v2alpha1/multi/compat.go index 7047e69b7c4..07f0088a7d5 100644 --- a/store/v2alpha1/multi/compat.go +++ b/store/v2alpha1/multi/compat.go @@ -104,8 +104,7 @@ func (st *compatStore) LoadVersionAndUpgrade(ver int64, upgrades *v1.StoreUpgrad } func (st *compatStore) LoadVersion(ver int64) error { - // TODO - // cache a viewStore representing "current" version? + // TODO: could cache a viewStore representing "current" version panic("unsupported: LoadVersion") } diff --git a/store/v2alpha1/multi/store.go b/store/v2alpha1/multi/store.go index f14cfb29dd9..d69c5d2e46c 100644 --- a/store/v2alpha1/multi/store.go +++ b/store/v2alpha1/multi/store.go @@ -68,7 +68,7 @@ type StoreParams struct { // Contains the store schema and methods to modify it SchemaBuilder storeKeys - // Inter-block persistent cache to use. TODO: not implemented + // Inter-block persistent cache to use. TODO: not used/impl'd PersistentCache types.MultiStorePersistentCache // Any pending upgrades to apply on loading. Upgrades *types.StoreUpgrades @@ -940,7 +940,7 @@ func (reg *SchemaBuilder) registerName(key string, typ types.StoreType) error { if has { return fmt.Errorf("name already exists: %v", key) } - // TODO auth vs authz ? + // // Prefix conflict check: disabled; obviated by varint encoding // if i > 0 && strings.HasPrefix(key, reg.reserved[i-1]) { // return fmt.Errorf("name conflict: '%v' exists, cannot add '%v'", reg.reserved[i-1], key) // } diff --git a/store/v2alpha1/multi/store_test.go b/store/v2alpha1/multi/store_test.go index 662d5872cac..51b2570a088 100644 --- a/store/v2alpha1/multi/store_test.go +++ b/store/v2alpha1/multi/store_test.go @@ -79,13 +79,14 @@ func TestStoreParams(t *testing.T) { require.Error(t, opts.RegisterSubstore(skey_1, types.StoreTypeTransient)) require.NoError(t, opts.RegisterSubstore(skey_mem1, types.StoreTypeMemory)) require.NoError(t, opts.RegisterSubstore(skey_tran1, types.StoreTypeTransient)) - // Ensure that no prefix conflicts are allowed + // Unambiguous prefixes are valid require.NoError(t, opts.RegisterSubstore(skey_1, types.StoreTypePersistent)) require.NoError(t, opts.RegisterSubstore(skey_2, types.StoreTypePersistent)) require.NoError(t, opts.RegisterSubstore(skey_3b, types.StoreTypePersistent)) - require.Error(t, opts.RegisterSubstore(skey_1b, types.StoreTypePersistent)) - require.Error(t, opts.RegisterSubstore(skey_2b, types.StoreTypePersistent)) - require.Error(t, opts.RegisterSubstore(skey_3, types.StoreTypePersistent)) + // Prefix conflicts are allowed + // require.Error(t, opts.RegisterSubstore(skey_1b, types.StoreTypePersistent)) + // require.Error(t, opts.RegisterSubstore(skey_2b, types.StoreTypePersistent)) + // require.Error(t, opts.RegisterSubstore(skey_3, types.StoreTypePersistent)) } func TestMultiStoreBasic(t *testing.T) { diff --git a/store/v2alpha1/types.go b/store/v2alpha1/types.go index c0a67bb762e..fed95acb088 100644 --- a/store/v2alpha1/types.go +++ b/store/v2alpha1/types.go @@ -104,5 +104,5 @@ type CacheMultiStore interface { } // MultiStorePersistentCache provides inter-block (persistent) caching capabilities for a CommitMultiStore. -// TODO: placeholder. Implement and redefine this +// TODO: placeholder, not implemented yet, nor used in store type MultiStorePersistentCache = v1.MultiStorePersistentCache diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index a54d20b5f58..2b6d7d6b923 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -14,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" dbm "github.com/cosmos/cosmos-sdk/db" - "github.com/cosmos/cosmos-sdk/db/memdb" pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types" "github.com/cosmos/cosmos-sdk/server" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -119,7 +118,7 @@ func TestSetLoader(t *testing.T) { require.NoError(t, loadConfig.RegisterSubstore(tc.loadStoreKey, storetypes.StoreTypePersistent)) // prepare a db with some data - db := memdb.NewDB() + db := dbm.NewMemDB() initStore(t, db, origConfig, tc.origStoreKey, k, v) // load the app with the existing db