Skip to content

Commit

Permalink
refactor: migrate calls from alias file to appropriate store/types (#…
Browse files Browse the repository at this point in the history
…14455)

Co-authored-by: Marko <[email protected]>
Closes #14406
  • Loading branch information
noelukwa authored Jan 10, 2023
1 parent a4d4d30 commit c822836
Show file tree
Hide file tree
Showing 193 changed files with 893 additions and 1,035 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Store pacakge no longer has a dependency on baseapp.
* (store) [#14438](https://github.com/cosmos/cosmos-sdk/pull/14438) Pass logger from baseapp to store.
* (store) [#14439](https://github.com/cosmos/cosmos-sdk/pull/14439) Remove global metric gatherer from store.
* By default store has a no op metric gatherer, the application developer must set another metric gatherer or us the provided one in `store/metrics`.
* By default store has a no op metric gatherer, the application developer must set another metric gatherer or us the provided one in `store/metrics`.
* [#14406](https://github.com/cosmos/cosmos-sdk/issues/14406) Migrate usage of types/store.go to store/types/..

### State Machine Breaking

Expand Down
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ The SDK is in the process of removing all `gogoproto` annotations.
The `gogoproto.goproto_stringer = false` annotation has been removed from most proto files. This means that the `String()` method is being generated for types that previously had this annotation. The generated `String()` method uses `proto.CompactTextString` for _stringifying_ structs.
[Verify](https://github.com/cosmos/cosmos-sdk/pull/13850#issuecomment-1328889651) the usage of the modified `String()` methods and double-check that they are not used in state-machine code.

### Types

#### Store

References to `types/store.go` which contained aliases for store types have been remapped to point to appropriate store/types, hence the `types/store.go` file is no longer needed and has been removed.

### SimApp

#### Module Assertions
Expand Down
17 changes: 9 additions & 8 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
}

// add block gas meter for any genesis transactions (allow infinite gas)
app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter())
app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter())

res = app.initChainer(app.deliverState.ctx, req)

Expand Down Expand Up @@ -149,7 +150,7 @@ 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.cms.TracingEnabled() {
app.cms.SetTracingContext(sdk.TraceContext(
app.cms.SetTracingContext(storetypes.TraceContext(
map[string]interface{}{"blockHeight": req.Header.Height},
))
}
Expand All @@ -172,11 +173,11 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
}

// add block gas meter
var gasMeter sdk.GasMeter
var gasMeter storetypes.GasMeter
if maxGas := app.GetMaximumBlockGas(app.deliverState.ctx); maxGas > 0 {
gasMeter = sdk.NewGasMeter(maxGas)
gasMeter = storetypes.NewGasMeter(maxGas)
} else {
gasMeter = sdk.NewInfiniteGasMeter()
gasMeter = storetypes.NewInfiniteGasMeter()
}

// NOTE: header hash is not set in NewContext, so we manually set it here
Expand Down Expand Up @@ -212,7 +213,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
// EndBlock implements the ABCI interface.
func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
if app.deliverState.ms.TracingEnabled() {
app.deliverState.ms = app.deliverState.ms.SetTracingContext(nil).(sdk.CacheMultiStore)
app.deliverState.ms = app.deliverState.ms.SetTracingContext(nil).(storetypes.CacheMultiStore)
}

if app.endBlocker != nil {
Expand Down Expand Up @@ -717,7 +718,7 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e
// use custom query multistore if provided
qms := app.qms
if qms == nil {
qms = app.cms.(sdk.MultiStore)
qms = app.cms.(storetypes.MultiStore)
}

lastBlockHeight := qms.LatestVersion()
Expand Down Expand Up @@ -880,7 +881,7 @@ 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.cms.(sdk.Queryable)
queryable, ok := app.cms.(storetypes.Queryable)
if !ok {
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "multistore doesn't support queries"), app.trace)
}
Expand Down
20 changes: 11 additions & 9 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

dbm "github.com/cosmos/cosmos-db"

"github.com/cosmos/gogoproto/jsonpb"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -18,6 +19,7 @@ import (
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
"github.com/cosmos/cosmos-sdk/store/snapshots"
snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -45,8 +47,8 @@ func TestABCI_InitChain(t *testing.T) {
logger := defaultLogger()
app := baseapp.NewBaseApp(name, logger, db, nil)

capKey := sdk.NewKVStoreKey("main")
capKey2 := sdk.NewKVStoreKey("key2")
capKey := storetypes.NewKVStoreKey("main")
capKey2 := storetypes.NewKVStoreKey("key2")
app.MountStores(capKey, capKey2)

// set a value in the store on init chain
Expand Down Expand Up @@ -745,7 +747,7 @@ func TestABCI_Query_SimulateTx(t *testing.T) {
gasConsumed := uint64(5)
anteOpt := func(bapp *baseapp.BaseApp) {
bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasConsumed))
newCtx = ctx.WithGasMeter(storetypes.NewGasMeter(gasConsumed))
return
})
}
Expand Down Expand Up @@ -910,7 +912,7 @@ func TestABCI_TxGasLimits(t *testing.T) {
gasGranted := uint64(10)
anteOpt := func(bapp *baseapp.BaseApp) {
bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasGranted))
newCtx = ctx.WithGasMeter(storetypes.NewGasMeter(gasGranted))

// AnteHandlers must have their own defer/recover in order for the BaseApp
// to know how much gas was used! This is because the GasMeter is created in
Expand All @@ -919,7 +921,7 @@ func TestABCI_TxGasLimits(t *testing.T) {
defer func() {
if r := recover(); r != nil {
switch rType := r.(type) {
case sdk.ErrorOutOfGas:
case storetypes.ErrorOutOfGas:
err = sdkerrors.Wrapf(sdkerrors.ErrOutOfGas, "out of gas in location: %v", rType.Descriptor)
default:
panic(r)
Expand Down Expand Up @@ -993,12 +995,12 @@ func TestABCI_MaxBlockGasLimits(t *testing.T) {
gasGranted := uint64(10)
anteOpt := func(bapp *baseapp.BaseApp) {
bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasGranted))
newCtx = ctx.WithGasMeter(storetypes.NewGasMeter(gasGranted))

defer func() {
if r := recover(); r != nil {
switch rType := r.(type) {
case sdk.ErrorOutOfGas:
case storetypes.ErrorOutOfGas:
err = sdkerrors.Wrapf(sdkerrors.ErrOutOfGas, "out of gas in location: %v", rType.Descriptor)
default:
panic(r)
Expand Down Expand Up @@ -1088,12 +1090,12 @@ func TestABCI_GasConsumptionBadTx(t *testing.T) {
gasWanted := uint64(5)
anteOpt := func(bapp *baseapp.BaseApp) {
bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasWanted))
newCtx = ctx.WithGasMeter(storetypes.NewGasMeter(gasWanted))

defer func() {
if r := recover(); r != nil {
switch rType := r.(type) {
case sdk.ErrorOutOfGas:
case storetypes.ErrorOutOfGas:
log := fmt.Sprintf("out of gas in location: %v", rType.Descriptor)
err = sdkerrors.Wrap(sdkerrors.ErrOutOfGas, log)
default:
Expand Down
32 changes: 16 additions & 16 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ type (
// from disk. This is useful for state migration, when loading a datastore written with
// an older version of the software. In particular, if a module changed the substore key name
// (or removed a substore) between two versions of the software.
StoreLoader func(ms sdk.CommitMultiStore) error
StoreLoader func(ms storetypes.CommitMultiStore) error
)

// BaseApp reflects the ABCI application implementation.
type BaseApp struct { //nolint: maligned
// initialized on creation
logger log.Logger
name string // application name from abci.Info
db dbm.DB // common DB backend
cms sdk.CommitMultiStore // Main (uncached) state
qms sdk.MultiStore // Optional alternative multistore for querying only.
storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader()
grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls
msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages
name string // application name from abci.Info
db dbm.DB // common DB backend
cms storetypes.CommitMultiStore // Main (uncached) state
qms storetypes.MultiStore // Optional alternative multistore for querying only.
storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader()
grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls
msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages
interfaceRegistry codectypes.InterfaceRegistry
txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx
txEncoder sdk.TxEncoder // marshal sdk.Tx into []byte
Expand Down Expand Up @@ -86,7 +86,7 @@ type BaseApp struct { //nolint: maligned
prepareProposalState *state // for PrepareProposal

// an inter-block write-through cache provided to the context during deliverState
interBlockCache sdk.MultiStorePersistentCache
interBlockCache storetypes.MultiStorePersistentCache

// absent validators from begin block
voteInfos []abci.VoteInfo
Expand Down Expand Up @@ -300,14 +300,14 @@ func (app *BaseApp) LoadLatestVersion() error {
}

// DefaultStoreLoader will be used by default and loads the latest version
func DefaultStoreLoader(ms sdk.CommitMultiStore) error {
func DefaultStoreLoader(ms storetypes.CommitMultiStore) error {
return ms.LoadLatestVersion()
}

// CommitMultiStore returns the root multi-store.
// App constructor can use this to access the `cms`.
// UNSAFE: must not be used during the abci life cycle.
func (app *BaseApp) CommitMultiStore() sdk.CommitMultiStore {
func (app *BaseApp) CommitMultiStore() storetypes.CommitMultiStore {
return app.cms
}

Expand Down Expand Up @@ -381,7 +381,7 @@ func (app *BaseApp) setMinRetainBlocks(minRetainBlocks uint64) {
app.minRetainBlocks = minRetainBlocks
}

func (app *BaseApp) setInterBlockCache(cache sdk.MultiStorePersistentCache) {
func (app *BaseApp) setInterBlockCache(cache storetypes.MultiStorePersistentCache) {
app.interBlockCache = cache
}

Expand Down Expand Up @@ -576,18 +576,18 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context

// cacheTxContext returns a new context based off of the provided context with
// a branched multi-store.
func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context, sdk.CacheMultiStore) {
func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context, storetypes.CacheMultiStore) {
ms := ctx.MultiStore()
// TODO: https://github.com/cosmos/cosmos-sdk/issues/2824
msCache := ms.CacheMultiStore()
if msCache.TracingEnabled() {
msCache = msCache.SetTracingContext(
sdk.TraceContext(
storetypes.TraceContext(
map[string]interface{}{
"txHash": fmt.Sprintf("%X", tmhash.Sum(txBytes)),
},
),
).(sdk.CacheMultiStore)
).(storetypes.CacheMultiStore)
}

return ctx.WithMultiStore(msCache), msCache
Expand Down Expand Up @@ -657,7 +657,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re
if app.anteHandler != nil {
var (
anteCtx sdk.Context
msCache sdk.CacheMultiStore
msCache storetypes.CacheMultiStore
)

// Branch context before AnteHandler call in case it aborts.
Expand Down
12 changes: 6 additions & 6 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
)

var (
capKey1 = sdk.NewKVStoreKey("key1")
capKey2 = sdk.NewKVStoreKey("key2")
capKey1 = storetypes.NewKVStoreKey("key1")
capKey2 = storetypes.NewKVStoreKey("key2")

// testTxPriority is the CheckTx priority that we set in the test
// AnteHandler.
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestSetLoader(t *testing.T) {
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))

key := sdk.NewKVStoreKey(storeKey)
key := storetypes.NewKVStoreKey(storeKey)
rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil)

err := rs.LoadLatestVersion()
Expand All @@ -241,7 +241,7 @@ func TestSetLoader(t *testing.T) {
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault))

key := sdk.NewKVStoreKey(storeKey)
key := storetypes.NewKVStoreKey(storeKey)
rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil)

err := rs.LoadLatestVersion()
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestSetLoader(t *testing.T) {
opts = append(opts, tc.setLoader)
}
app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...)
app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey))
app.MountStores(storetypes.NewKVStoreKey(tc.loadStoreKey))
err := app.LoadLatestVersion()
require.Nil(t, err)

Expand Down Expand Up @@ -613,7 +613,7 @@ func TestLoadVersionPruning(t *testing.T) {
app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)

// make a cap key and mount the store
capKey := sdk.NewKVStoreKey("key1")
capKey := storetypes.NewKVStoreKey("key1")
app.MountStores(capKey)

err := app.LoadLatestVersion() // needed to make stores non-nil
Expand Down
8 changes: 3 additions & 5 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import (
"io"

dbm "github.com/cosmos/cosmos-db"

"github.com/cosmos/cosmos-sdk/codec/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store"
"github.com/cosmos/cosmos-sdk/store/metrics"
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
"github.com/cosmos/cosmos-sdk/store/snapshots"
Expand Down Expand Up @@ -76,7 +74,7 @@ func SetIAVLDisableFastNode(disable bool) func(*BaseApp) {

// SetInterBlockCache provides a BaseApp option function that sets the
// inter-block cache.
func SetInterBlockCache(cache sdk.MultiStorePersistentCache) func(*BaseApp) {
func SetInterBlockCache(cache storetypes.MultiStorePersistentCache) func(*BaseApp) {
return func(app *BaseApp) { app.setInterBlockCache(cache) }
}

Expand Down Expand Up @@ -128,7 +126,7 @@ func (app *BaseApp) SetDB(db dbm.DB) {
app.db = db
}

func (app *BaseApp) SetCMS(cms store.CommitMultiStore) {
func (app *BaseApp) SetCMS(cms storetypes.CommitMultiStore) {
if app.sealed {
panic("SetEndBlocker() on sealed BaseApp")
}
Expand Down Expand Up @@ -270,7 +268,7 @@ func (app *BaseApp) SetTxEncoder(txEncoder sdk.TxEncoder) {
// SetQueryMultiStore set a alternative MultiStore implementation to support grpc query service.
//
// Ref: https://github.com/cosmos/cosmos-sdk/issues/13317
func (app *BaseApp) SetQueryMultiStore(ms sdk.MultiStore) {
func (app *BaseApp) SetQueryMultiStore(ms storetypes.MultiStore) {
app.qms = ms
}

Expand Down
3 changes: 2 additions & 1 deletion baseapp/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"runtime/debug"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -47,7 +48,7 @@ func newRecoveryMiddleware(handler RecoveryHandler, next recoveryMiddleware) rec
// newOutOfGasRecoveryMiddleware creates a standard OutOfGas recovery middleware for app.runTx method.
func newOutOfGasRecoveryMiddleware(gasWanted uint64, ctx sdk.Context, next recoveryMiddleware) recoveryMiddleware {
handler := func(recoveryObj interface{}) error {
err, ok := recoveryObj.(sdk.ErrorOutOfGas)
err, ok := recoveryObj.(storetypes.ErrorOutOfGas)
if !ok {
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions baseapp/state.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package baseapp

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

type state struct {
ms sdk.CacheMultiStore
ms storetypes.CacheMultiStore
ctx sdk.Context
}

// CacheMultiStore calls and returns a CacheMultiStore on the state's underling
// CacheMultiStore.
func (st *state) CacheMultiStore() sdk.CacheMultiStore {
func (st *state) CacheMultiStore() storetypes.CacheMultiStore {
return st.ms.CacheMultiStore()
}

Expand Down
Loading

0 comments on commit c822836

Please sign in to comment.