Skip to content

Commit

Permalink
PR clean up
Browse files Browse the repository at this point in the history
rm superfluous app.cms rename

memdb imports

[wip]substore prefix conflict
  • Loading branch information
roysc committed Jul 21, 2022
1 parent eaa83be commit c1e800c
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 61 deletions.
18 changes: 9 additions & 9 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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},
))
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 8 additions & 8 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
43 changes: 22 additions & 21 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand Down Expand Up @@ -168,17 +167,17 @@ 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)
}

// Test that we can make commits and then reload old versions.
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)

Expand Down Expand Up @@ -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())
Expand All @@ -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)

Expand Down Expand Up @@ -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())
Expand All @@ -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")
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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()

Expand All @@ -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,
})
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions baseapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion db/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/db/tmdb_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
3 changes: 1 addition & 2 deletions server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit c1e800c

Please sign in to comment.