Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove store type aliases #10295

Merged
merged 23 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* [\#10295](https://github.com/cosmos/cosmos-sdk/pull/10295) Remove store type aliases from /types
* [\#9695](https://github.com/cosmos/cosmos-sdk/pull/9695) Migrate keys from `Info` -> `Record`
* Add new `codec.Codec` argument in:
* `keyring.NewInMemory`
Expand Down
31 changes: 16 additions & 15 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/snapshots"
"github.com/cosmos/cosmos-sdk/store"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
)
Expand Down Expand Up @@ -185,20 +186,20 @@ func (app *BaseApp) Trace() bool {

// MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp
// multistore.
func (app *BaseApp) MountStores(keys ...sdk.StoreKey) {
func (app *BaseApp) MountStores(keys ...storetypes.StoreKey) {
for _, key := range keys {
switch key.(type) {
case *sdk.KVStoreKey:
case *storetypes.KVStoreKey:
if !app.fauxMerkleMode {
app.MountStore(key, sdk.StoreTypeIAVL)
app.MountStore(key, storetypes.StoreTypeIAVL)
} else {
// StoreTypeDB doesn't do anything upon commit, and it doesn't
// retain history, but it's useful for faster simulation.
app.MountStore(key, sdk.StoreTypeDB)
app.MountStore(key, storetypes.StoreTypeDB)
}

case *sdk.TransientStoreKey:
app.MountStore(key, sdk.StoreTypeTransient)
case *storetypes.TransientStoreKey:
app.MountStore(key, storetypes.StoreTypeTransient)

default:
panic("Unrecognized store key type " + reflect.TypeOf(key).Name())
Expand All @@ -208,37 +209,37 @@ func (app *BaseApp) MountStores(keys ...sdk.StoreKey) {

// MountKVStores mounts all IAVL or DB stores to the provided keys in the
// BaseApp multistore.
func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey) {
func (app *BaseApp) MountKVStores(keys map[string]*storetypes.KVStoreKey) {
for _, key := range keys {
if !app.fauxMerkleMode {
app.MountStore(key, sdk.StoreTypeIAVL)
app.MountStore(key, storetypes.StoreTypeIAVL)
} else {
// StoreTypeDB doesn't do anything upon commit, and it doesn't
// retain history, but it's useful for faster simulation.
app.MountStore(key, sdk.StoreTypeDB)
app.MountStore(key, storetypes.StoreTypeDB)
}
}
}

// MountTransientStores mounts all transient stores to the provided keys in
// the BaseApp multistore.
func (app *BaseApp) MountTransientStores(keys map[string]*sdk.TransientStoreKey) {
func (app *BaseApp) MountTransientStores(keys map[string]*storetypes.TransientStoreKey) {
for _, key := range keys {
app.MountStore(key, sdk.StoreTypeTransient)
app.MountStore(key, storetypes.StoreTypeTransient)
}
}

// MountMemoryStores mounts all in-memory KVStores with the BaseApp's internal
// commit multi-store.
func (app *BaseApp) MountMemoryStores(keys map[string]*sdk.MemoryStoreKey) {
func (app *BaseApp) MountMemoryStores(keys map[string]*storetypes.MemoryStoreKey) {
for _, memKey := range keys {
app.MountStore(memKey, sdk.StoreTypeMemory)
app.MountStore(memKey, storetypes.StoreTypeMemory)
}
}

// MountStore mounts a store to the provided key in the BaseApp multistore,
// using the default DB.
func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) {
func (app *BaseApp) MountStore(key storetypes.StoreKey, typ storetypes.StoreType) {
app.cms.MountStoreWithDB(key, typ, nil)
}

Expand Down Expand Up @@ -270,7 +271,7 @@ func (app *BaseApp) LoadVersion(version int64) error {
}

// LastCommitID returns the last CommitID of the multistore.
func (app *BaseApp) LastCommitID() sdk.CommitID {
func (app *BaseApp) LastCommitID() storetypes.CommitID {
return app.cms.LastCommitID()
}

Expand Down
44 changes: 22 additions & 22 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/cosmos/cosmos-sdk/snapshots"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
store "github.com/cosmos/cosmos-sdk/store/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestMountStores(t *testing.T) {
// Test that LoadLatestVersion actually does.
func TestLoadVersion(t *testing.T) {
logger := defaultLogger()
pruningOpt := baseapp.SetPruning(store.PruneNothing)
pruningOpt := baseapp.SetPruning(storetypes.PruneNothing)
db := dbm.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)
Expand All @@ -243,7 +243,7 @@ func TestLoadVersion(t *testing.T) {
err := app.LoadLatestVersion() // needed to make stores non-nil
require.Nil(t, err)

emptyCommitID := sdk.CommitID{}
emptyCommitID := storetypes.CommitID{}

// fresh store has zero/empty last commit
lastHeight := app.LastBlockHeight()
Expand All @@ -255,13 +255,13 @@ func TestLoadVersion(t *testing.T) {
header := tmproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
res := app.Commit()
commitID1 := sdk.CommitID{Version: 1, Hash: res.Data}
commitID1 := storetypes.CommitID{Version: 1, Hash: res.Data}

// execute a block, collect commit ID
header = tmproto.Header{Height: 2}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
res = app.Commit()
commitID2 := sdk.CommitID{Version: 2, Hash: res.Data}
commitID2 := storetypes.CommitID{Version: 2, Hash: res.Data}

// reload with LoadLatestVersion
app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)
Expand All @@ -287,15 +287,15 @@ func useDefaultLoader(app *baseapp.BaseApp) {

func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
rs := rootmulti.NewStore(db)
rs.SetPruning(store.PruneNothing)
rs.SetPruning(storetypes.PruneNothing)
key := sdk.NewKVStoreKey(storeKey)
rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil)
rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil)
err := rs.LoadLatestVersion()
require.Nil(t, err)
require.Equal(t, int64(0), rs.LastCommitID().Version)

// write some data in substore
kv, _ := rs.GetStore(key).(store.KVStore)
kv, _ := rs.GetStore(key).(storetypes.KVStore)
require.NotNil(t, kv)
kv.Set(k, v)
commitID := rs.Commit()
Expand All @@ -304,15 +304,15 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {

func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) {
rs := rootmulti.NewStore(db)
rs.SetPruning(store.PruneDefault)
rs.SetPruning(storetypes.PruneDefault)
key := sdk.NewKVStoreKey(storeKey)
rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil)
rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil)
err := rs.LoadLatestVersion()
require.Nil(t, err)
require.Equal(t, ver, rs.LastCommitID().Version)

// query data in substore
kv, _ := rs.GetStore(key).(store.KVStore)
kv, _ := rs.GetStore(key).(storetypes.KVStore)
require.NotNil(t, kv)
require.Equal(t, v, kv.Get(k))
}
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestSetLoader(t *testing.T) {
initStore(t, db, tc.origStoreKey, k, v)

// load the app with the existing db
opts := []func(*baseapp.BaseApp){baseapp.SetPruning(store.PruneNothing)}
opts := []func(*baseapp.BaseApp){baseapp.SetPruning(storetypes.PruneNothing)}
if tc.setLoader != nil {
opts = append(opts, tc.setLoader)
}
Expand All @@ -370,7 +370,7 @@ func TestSetLoader(t *testing.T) {

func TestVersionSetterGetter(t *testing.T) {
logger := defaultLogger()
pruningOpt := baseapp.SetPruning(store.PruneDefault)
pruningOpt := baseapp.SetPruning(storetypes.PruneDefault)
db := dbm.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)
Expand All @@ -390,7 +390,7 @@ func TestVersionSetterGetter(t *testing.T) {

func TestLoadVersionInvalid(t *testing.T) {
logger := log.NewNopLogger()
pruningOpt := baseapp.SetPruning(store.PruneNothing)
pruningOpt := baseapp.SetPruning(storetypes.PruneNothing)
db := dbm.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)
Expand All @@ -405,7 +405,7 @@ func TestLoadVersionInvalid(t *testing.T) {
header := tmproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
res := app.Commit()
commitID1 := sdk.CommitID{Version: 1, Hash: res.Data}
commitID1 := storetypes.CommitID{Version: 1, Hash: res.Data}

// create a new app with the stores mounted under the same cap key
app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)
Expand All @@ -422,7 +422,7 @@ func TestLoadVersionInvalid(t *testing.T) {

func TestLoadVersionPruning(t *testing.T) {
logger := log.NewNopLogger()
pruningOptions := store.PruningOptions{
pruningOptions := storetypes.PruningOptions{
KeepRecent: 2,
KeepEvery: 3,
Interval: 1,
Expand All @@ -439,22 +439,22 @@ func TestLoadVersionPruning(t *testing.T) {
err := app.LoadLatestVersion() // needed to make stores non-nil
require.Nil(t, err)

emptyCommitID := sdk.CommitID{}
emptyCommitID := storetypes.CommitID{}

// fresh store has zero/empty last commit
lastHeight := app.LastBlockHeight()
lastID := app.LastCommitID()
require.Equal(t, int64(0), lastHeight)
require.Equal(t, emptyCommitID, lastID)

var lastCommitID sdk.CommitID
var lastCommitID storetypes.CommitID

// Commit seven blocks, of which 7 (latest) is kept in addition to 6, 5
// (keep recent) and 3 (keep every).
for i := int64(1); i <= 7; i++ {
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: i}})
res := app.Commit()
lastCommitID = sdk.CommitID{Version: i, Hash: res.Data}
lastCommitID = storetypes.CommitID{Version: i, Hash: res.Data}
}

for _, v := range []int64{1, 2, 4} {
Expand All @@ -476,7 +476,7 @@ func TestLoadVersionPruning(t *testing.T) {
testLoadVersionHelper(t, app, int64(7), lastCommitID)
}

func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight int64, expectedID sdk.CommitID) {
func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight int64, expectedID storetypes.CommitID) {
lastHeight := app.LastBlockHeight()
lastID := app.LastCommitID()
require.Equal(t, expectedHeight, lastHeight)
Expand Down Expand Up @@ -845,7 +845,7 @@ func testTxDecoder(cdc *codec.LegacyAmino) sdk.TxDecoder {
}
}

func customHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) handlerFun {
func customHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte) handlerFun {
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
store := ctx.KVStore(capKey)
txTest := tx.(txTest)
Expand Down Expand Up @@ -876,7 +876,7 @@ func counterEvent(evType string, msgCount int64) sdk.Events {
}
}

func handlerMsgCounter(t *testing.T, capKey sdk.StoreKey, deliverKey []byte) sdk.Handler {
func handlerMsgCounter(t *testing.T, capKey storetypes.StoreKey, deliverKey []byte) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())
store := ctx.KVStore(capKey)
Expand Down
8 changes: 4 additions & 4 deletions server/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"fmt"
"path/filepath"

"github.com/tendermint/tendermint/types"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/types"

bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/x/auth/middleware"
Expand Down Expand Up @@ -72,7 +72,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) {

// KVStoreHandler is a simple handler that takes kvstoreTx and writes
// them to the db
func KVStoreHandler(storeKey sdk.StoreKey) sdk.Handler {
func KVStoreHandler(storeKey storetypes.StoreKey) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
dTx, ok := msg.(kvstoreTx)
if !ok {
Expand Down Expand Up @@ -105,7 +105,7 @@ type GenesisJSON struct {

// InitChainer returns a function that can initialize the chain
// with key/value pairs
func InitChainer(key sdk.StoreKey) func(sdk.Context, abci.RequestInitChain) abci.ResponseInitChain {
func InitChainer(key storetypes.StoreKey) func(sdk.Context, abci.RequestInitChain) abci.ResponseInitChain {
return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
stateJSON := req.AppStateBytes

Expand Down
Loading