Skip to content

Commit

Permalink
Merge branch 'master' into roysc/adr-040-db-rocks
Browse files Browse the repository at this point in the history
  • Loading branch information
roysc authored Oct 5, 2021
2 parents 9cbf319 + 9094794 commit 97f0c90
Show file tree
Hide file tree
Showing 106 changed files with 2,979 additions and 1,123 deletions.
2 changes: 2 additions & 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 Expand Up @@ -121,6 +122,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (types) [\#10021](https://github.com/cosmos/cosmos-sdk/pull/10021) Speedup coins.AmountOf(), by removing many intermittent regex calls.
* (rosetta) [\#10001](https://github.com/cosmos/cosmos-sdk/issues/10001) Add documentation for rosetta-cli dockerfile and rename folder for the rosetta-ci dockerfile
* [\#9699](https://github.com/cosmos/cosmos-sdk/pull/9699) Add `:`, `.`, `-`, and `_` as allowed characters in the default denom regular expression.
* (genesis) [\#9697](https://github.com/cosmos/cosmos-sdk/pull/9697) Ensure `InitGenesis` returns with non-empty validator set.
* [\#10262](https://github.com/cosmos/cosmos-sdk/pull/10262) Remove unnecessary logging in `x/feegrant` simulation.

### Bug Fixes
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
Loading

0 comments on commit 97f0c90

Please sign in to comment.