From 924f26510a667bd636fb92b26aa8ecc21b216786 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 23 Jun 2021 16:44:42 +0800 Subject: [PATCH] Refactor for new DB interface - Refactor store/ and types/ packages - leaves out IAVL and multistore code pending confirmed deprecation - some hacks to glue existing tmdb usage and get compile/tests working --- store/README.md | 2 +- store/cachekv/memiterator.go | 2 +- store/cachekv/store.go | 2 +- store/cachekv/store_bench_test.go | 4 ++-- store/cachekv/store_test.go | 31 ++++++++++++++++--------------- store/cachemulti/store.go | 2 +- store/dbadapter/store.go | 9 +++++++-- store/dbadapter/store_test.go | 6 +++--- store/gaskv/store_test.go | 10 +++++----- store/listenkv/store_test.go | 6 +++--- store/mem/store.go | 8 ++++---- store/prefix/store_test.go | 19 ++++++++++--------- store/rootmulti/store.go | 2 +- store/smt/iterator.go | 2 +- store/smt/iterator_test.go | 2 +- store/smt/proof_test.go | 4 ++-- store/smt/store.go | 6 +++--- store/smt/store_test.go | 2 +- store/tracekv/store_test.go | 6 +++--- store/transient/store.go | 6 +++--- store/types/iterator_test.go | 5 +++-- store/types/store.go | 5 +++-- store/types/utils_test.go | 5 +++-- types/query/pagination.go | 4 ++-- types/query/pagination_test.go | 6 +++--- types/store_test.go | 5 +++-- 26 files changed, 86 insertions(+), 75 deletions(-) diff --git a/store/README.md b/store/README.md index 3607cbb71bb8..bce032be2963 100644 --- a/store/README.md +++ b/store/README.md @@ -127,4 +127,4 @@ type Store struct { } ``` -`Store.Store` is a `dbadapter.Store` with a `dbm.NewMemDB()`. All `KVStore` methods are reused. When `Store.Commit()` is called, new `dbadapter.Store` is assigned, discarding previous reference and making it garbage collected. +`Store.Store` is a `dbadapter.Store` with an in-memory backing `DB`. All `KVStore` methods are reused. When `Store.Commit()` is called, new `dbadapter.Store` is assigned, discarding previous reference and making it garbage collected. diff --git a/store/cachekv/memiterator.go b/store/cachekv/memiterator.go index b197ac141660..4b4db6847850 100644 --- a/store/cachekv/memiterator.go +++ b/store/cachekv/memiterator.go @@ -3,7 +3,7 @@ package cachekv import ( "errors" - dbm "github.com/tendermint/tm-db" + dbm "github.com/cosmos/cosmos-sdk/db" "github.com/cosmos/cosmos-sdk/types/kv" ) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 48c59d8da8d3..2c73dd93d3e5 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -7,7 +7,7 @@ import ( "sync" "time" - dbm "github.com/tendermint/tm-db" + dbm "github.com/cosmos/cosmos-sdk/db" "github.com/cosmos/cosmos-sdk/internal/conv" "github.com/cosmos/cosmos-sdk/store/listenkv" diff --git a/store/cachekv/store_bench_test.go b/store/cachekv/store_bench_test.go index 2957fe6a6503..18338604ba23 100644 --- a/store/cachekv/store_bench_test.go +++ b/store/cachekv/store_bench_test.go @@ -5,7 +5,7 @@ import ( "sort" "testing" - dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/dbadapter" @@ -13,7 +13,7 @@ import ( func benchmarkCacheKVStoreIterator(numKVs int, b *testing.B) { b.ReportAllocs() - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} cstore := cachekv.NewStore(mem) keys := make([]string, numKVs) diff --git a/store/cachekv/store_test.go b/store/cachekv/store_test.go index 0404f33f2a28..0bd5cad47700 100644 --- a/store/cachekv/store_test.go +++ b/store/cachekv/store_test.go @@ -4,9 +4,10 @@ import ( "fmt" "testing" + dbm "github.com/cosmos/cosmos-sdk/db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/dbadapter" @@ -14,7 +15,7 @@ import ( ) func newCacheKVStore() types.CacheKVStore { - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} return cachekv.NewStore(mem) } @@ -22,7 +23,7 @@ func keyFmt(i int) []byte { return bz(fmt.Sprintf("key%0.8d", i)) } func valFmt(i int) []byte { return bz(fmt.Sprintf("value%0.8d", i)) } func TestCacheKVStore(t *testing.T) { - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} st := cachekv.NewStore(mem) require.Empty(t, st.Get(keyFmt(1)), "Expected `key1` to be empty") @@ -65,7 +66,7 @@ func TestCacheKVStore(t *testing.T) { } func TestCacheKVStoreNoNilSet(t *testing.T) { - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} st := cachekv.NewStore(mem) require.Panics(t, func() { st.Set([]byte("key"), nil) }, "setting a nil value should panic") require.Panics(t, func() { st.Set(nil, []byte("value")) }, "setting a nil key should panic") @@ -73,7 +74,7 @@ func TestCacheKVStoreNoNilSet(t *testing.T) { } func TestCacheKVStoreNested(t *testing.T) { - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} st := cachekv.NewStore(mem) // set. check its there on st and not on mem. @@ -228,7 +229,7 @@ func TestCacheKVMergeIteratorDeleteLast(t *testing.T) { func TestCacheKVMergeIteratorDeletes(t *testing.T) { st := newCacheKVStore() - truth := dbm.NewMemDB() + truth := memdb.NewDB() // set some items and write them nItems := 10 @@ -245,7 +246,7 @@ func TestCacheKVMergeIteratorDeletes(t *testing.T) { // reset st = newCacheKVStore() - truth = dbm.NewMemDB() + truth = memdb.NewDB() // set some items and write them for i := 0; i < nItems; i++ { @@ -264,7 +265,7 @@ func TestCacheKVMergeIteratorChunks(t *testing.T) { st := newCacheKVStore() // Use the truth to check values on the merge iterator - truth := dbm.NewMemDB() + truth := memdb.NewDB() // sets to the parent setRange(t, st, truth, 0, 20) @@ -293,7 +294,7 @@ func TestCacheKVMergeIteratorChunks(t *testing.T) { func TestCacheKVMergeIteratorRandom(t *testing.T) { st := newCacheKVStore() - truth := dbm.NewMemDB() + truth := memdb.NewDB() start, end := 25, 975 max := 1000 @@ -324,7 +325,7 @@ func randInt(n int) int { } // useful for replaying a error case if we find one -func doOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, op int, args ...int) { +func doOp(t *testing.T, st types.CacheKVStore, truth dbm.DBReadWriter, op int, args ...int) { switch op { case opSet: k := args[0] @@ -349,7 +350,7 @@ func doOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, op int, args ...int } } -func doRandomOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, maxKey int) { +func doRandomOp(t *testing.T, st types.CacheKVStore, truth dbm.DBReadWriter, maxKey int) { r := randInt(totalOps) switch r { case opSet: @@ -390,7 +391,7 @@ func assertIterateDomain(t *testing.T, st types.KVStore, expectedN int) { require.Equal(t, expectedN, i) } -func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem dbm.DB, r []keyRange) { +func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem dbm.DBReadWriter, r []keyRange) { // iterate over each and check they match the other itr := st.Iterator(nil, nil) itr2, err := mem.Iterator(nil, nil) // ground truth @@ -421,7 +422,7 @@ func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem dbm.DB, r []ke require.False(t, itr2.Valid()) } -func assertIterateDomainCompare(t *testing.T, st types.KVStore, mem dbm.DB) { +func assertIterateDomainCompare(t *testing.T, st types.KVStore, mem dbm.DBReadWriter) { // iterate over each and check they match the other itr := st.Iterator(nil, nil) itr2, err := mem.Iterator(nil, nil) // ground truth @@ -445,7 +446,7 @@ func checkIterators(t *testing.T, itr, itr2 types.Iterator) { //-------------------------------------------------------- -func setRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) { +func setRange(t *testing.T, st types.KVStore, mem dbm.DBReadWriter, start, end int) { for i := start; i < end; i++ { st.Set(keyFmt(i), valFmt(i)) err := mem.Set(keyFmt(i), valFmt(i)) @@ -453,7 +454,7 @@ func setRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) { } } -func deleteRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) { +func deleteRange(t *testing.T, st types.KVStore, mem dbm.DBReadWriter, start, end int) { for i := start; i < end; i++ { st.Delete(keyFmt(i)) err := mem.Delete(keyFmt(i)) diff --git a/store/cachemulti/store.go b/store/cachemulti/store.go index 05637a45ff16..76f934e484fb 100644 --- a/store/cachemulti/store.go +++ b/store/cachemulti/store.go @@ -72,7 +72,7 @@ func NewStore( traceWriter io.Writer, traceContext types.TraceContext, listeners map[types.StoreKey][]types.WriteListener, ) Store { - return NewFromKVStore(dbadapter.Store{DB: db}, stores, keys, traceWriter, traceContext, listeners) + return NewFromKVStore(dbadapter.NewStore(db), stores, keys, traceWriter, traceContext, listeners) } func newCacheMultiStoreFromCMS(cms Store) Store { diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index 2f0ceb5df54a..36c307419491 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,7 +3,8 @@ package dbadapter import ( "io" - dbm "github.com/tendermint/tm-db" + dbm "github.com/cosmos/cosmos-sdk/db" + tmdb "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/listenkv" @@ -13,7 +14,11 @@ import ( // Wrapper type for dbm.Db with implementation of KVStore type Store struct { - dbm.DB + DB dbm.DBReadWriter +} + +func NewStore(db tmdb.DB) Store { + return Store{DB: dbm.MungeDBRW(db)} } // Get wraps the underlying DB's Get method panicing on error. diff --git a/store/dbadapter/store_test.go b/store/dbadapter/store_test.go index 9f8ac71b25cf..305ec05c7582 100644 --- a/store/dbadapter/store_test.go +++ b/store/dbadapter/store_test.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/dbadapter" "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/tests/mocks" + mocks "github.com/cosmos/cosmos-sdk/tests/mocks/db" ) var errFoo = errors.New("dummy") @@ -21,7 +21,7 @@ func TestAccessors(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() - mockDB := mocks.NewMockDB(mockCtrl) + mockDB := mocks.NewMockDBReadWriter(mockCtrl) store := dbadapter.Store{mockDB} key := []byte("test") value := []byte("testvalue") @@ -76,7 +76,7 @@ func TestAccessors(t *testing.T) { func TestCacheWraps(t *testing.T) { mockCtrl := gomock.NewController(t) - mockDB := mocks.NewMockDB(mockCtrl) + mockDB := mocks.NewMockDBReadWriter(mockCtrl) store := dbadapter.Store{mockDB} cacheWrapper := store.CacheWrap() diff --git a/store/gaskv/store_test.go b/store/gaskv/store_test.go index e111a72329a7..332617287049 100644 --- a/store/gaskv/store_test.go +++ b/store/gaskv/store_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/cosmos/cosmos-sdk/store/dbadapter" "github.com/cosmos/cosmos-sdk/store/gaskv" @@ -19,7 +19,7 @@ func keyFmt(i int) []byte { return bz(fmt.Sprintf("key%0.8d", i)) } func valFmt(i int) []byte { return bz(fmt.Sprintf("value%0.8d", i)) } func TestGasKVStoreBasic(t *testing.T) { - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} meter := types.NewGasMeter(10000) st := gaskv.NewStore(mem, meter, types.KVGasConfig()) @@ -40,7 +40,7 @@ func TestGasKVStoreBasic(t *testing.T) { } func TestGasKVStoreIterator(t *testing.T) { - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} meter := types.NewGasMeter(10000) st := gaskv.NewStore(mem, meter, types.KVGasConfig()) require.False(t, st.Has(keyFmt(1))) @@ -92,14 +92,14 @@ func TestGasKVStoreIterator(t *testing.T) { } func TestGasKVStoreOutOfGasSet(t *testing.T) { - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} meter := types.NewGasMeter(0) st := gaskv.NewStore(mem, meter, types.KVGasConfig()) require.Panics(t, func() { st.Set(keyFmt(1), valFmt(1)) }, "Expected out-of-gas") } func TestGasKVStoreOutOfGasIterator(t *testing.T) { - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} meter := types.NewGasMeter(20000) st := gaskv.NewStore(mem, meter, types.KVGasConfig()) st.Set(keyFmt(1), valFmt(1)) diff --git a/store/listenkv/store_test.go b/store/listenkv/store_test.go index 5d4fd0cca9c4..1bd850ee4a5d 100644 --- a/store/listenkv/store_test.go +++ b/store/listenkv/store_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/require" - dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/db/memdb" ) func bz(s string) []byte { return []byte(s) } @@ -45,7 +45,7 @@ func newListenKVStore(w io.Writer) *listenkv.Store { func newEmptyListenKVStore(w io.Writer) *listenkv.Store { listener := types.NewStoreKVPairWriteListener(w, testMarshaller) - memDB := dbadapter.Store{DB: dbm.NewMemDB()} + memDB := dbadapter.Store{DB: memdb.NewDB()} return listenkv.NewStore(memDB, testStoreKey, []types.WriteListener{listener}) } @@ -277,7 +277,7 @@ func TestListenKVStorePrefix(t *testing.T) { } func TestListenKVStoreGetStoreType(t *testing.T) { - memDB := dbadapter.Store{DB: dbm.NewMemDB()} + memDB := dbadapter.Store{DB: memdb.NewDB()} store := newEmptyListenKVStore(nil) require.Equal(t, memDB.GetStoreType(), store.GetStoreType()) } diff --git a/store/mem/store.go b/store/mem/store.go index c8aa6dca5997..899fb0c91e10 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,7 +3,7 @@ package mem import ( "io" - dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/dbadapter" @@ -24,11 +24,11 @@ type Store struct { } func NewStore() *Store { - return NewStoreWithDB(dbm.NewMemDB()) + return NewStoreWithDB(memdb.NewDB()) } -func NewStoreWithDB(db *dbm.MemDB) *Store { // nolint: interfacer - return &Store{Store: dbadapter.Store{DB: db}} +func NewStoreWithDB(db *memdb.MemDB) *Store { // nolint: interfacer + return &Store{Store: dbadapter.Store{DB: db.ReadWriter()}} } // GetStoreType returns the Store's type. diff --git a/store/prefix/store_test.go b/store/prefix/store_test.go index bf49e9cfe528..1b84d2a6649b 100644 --- a/store/prefix/store_test.go +++ b/store/prefix/store_test.go @@ -6,8 +6,9 @@ import ( "github.com/cosmos/cosmos-sdk/store/cachekv" + dbm "github.com/cosmos/cosmos-sdk/db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/stretchr/testify/require" - dbm "github.com/tendermint/tm-db" tiavl "github.com/cosmos/iavl" @@ -89,7 +90,7 @@ func testPrefixStore(t *testing.T, baseStore types.KVStore, prefix []byte) { } func TestIAVLStorePrefix(t *testing.T) { - db := dbm.NewMemDB() + db := dbm.MungeTmdb(memdb.NewDB()) tree, err := tiavl.NewMutableTree(db, cacheSize) require.NoError(t, err) iavlStore := iavl.UnsafeNewStore(tree) @@ -99,13 +100,13 @@ func TestIAVLStorePrefix(t *testing.T) { func TestPrefixKVStoreNoNilSet(t *testing.T) { meter := types.NewGasMeter(100000000) - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} gasStore := gaskv.NewStore(mem, meter, types.KVGasConfig()) require.Panics(t, func() { gasStore.Set([]byte("key"), nil) }, "setting a nil value should panic") } func TestPrefixStoreIterate(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() baseStore := dbadapter.Store{DB: db} prefix := []byte("test") prefixStore := NewStore(baseStore, prefix) @@ -151,7 +152,7 @@ func TestCloneAppend(t *testing.T) { } func TestPrefixStoreIteratorEdgeCase(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() baseStore := dbadapter.Store{DB: db} // overflow in cpIncr @@ -181,7 +182,7 @@ func TestPrefixStoreIteratorEdgeCase(t *testing.T) { } func TestPrefixStoreReverseIteratorEdgeCase(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() baseStore := dbadapter.Store{DB: db} // overflow in cpIncr @@ -209,7 +210,7 @@ func TestPrefixStoreReverseIteratorEdgeCase(t *testing.T) { iter.Close() - db = dbm.NewMemDB() + db = memdb.NewDB() baseStore = dbadapter.Store{DB: db} // underflow in cpDecr @@ -240,7 +241,7 @@ func TestPrefixStoreReverseIteratorEdgeCase(t *testing.T) { // Tests below are ported from https://github.com/tendermint/tendermint/blob/master/libs/db/prefix_db_test.go func mockStoreWithStuff() types.KVStore { - db := dbm.NewMemDB() + db := memdb.NewDB() store := dbadapter.Store{DB: db} // Under "key" prefix store.Set(bz("key"), bz("value")) @@ -430,7 +431,7 @@ func TestPrefixDBReverseIterator4(t *testing.T) { } func TestCacheWraps(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() store := dbadapter.Store{DB: db} cacheWrapper := store.CacheWrap() diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index c8df42ce3ce1..8a62ad9ba8d1 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -880,7 +880,7 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID return store, err case types.StoreTypeDB: - return commitDBStoreAdapter{Store: dbadapter.Store{DB: db}}, nil + return commitDBStoreAdapter{Store: dbadapter.NewStore(db)}, nil case types.StoreTypeTransient: _, ok := key.(*types.TransientStoreKey) diff --git a/store/smt/iterator.go b/store/smt/iterator.go index 459460d77532..98c0a5003099 100644 --- a/store/smt/iterator.go +++ b/store/smt/iterator.go @@ -3,7 +3,7 @@ package smt import ( "bytes" - dbm "github.com/tendermint/tm-db" + dbm "github.com/cosmos/cosmos-sdk/db" ) type Iterator struct { diff --git a/store/smt/iterator_test.go b/store/smt/iterator_test.go index 6a724e665a1e..b5e85c230762 100644 --- a/store/smt/iterator_test.go +++ b/store/smt/iterator_test.go @@ -5,10 +5,10 @@ import ( "sort" "testing" + dbm "github.com/cosmos/cosmos-sdk/db" "github.com/cosmos/cosmos-sdk/store/smt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - dbm "github.com/tendermint/tm-db" ) func TestIteration(t *testing.T) { diff --git a/store/smt/proof_test.go b/store/smt/proof_test.go index 75e7974bc214..b137a9aa3125 100644 --- a/store/smt/proof_test.go +++ b/store/smt/proof_test.go @@ -7,14 +7,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/db/memdb" smtstore "github.com/cosmos/cosmos-sdk/store/smt" "github.com/lazyledger/smt" - dbm "github.com/tendermint/tm-db" ) func TestProofOpInterface(t *testing.T) { hasher := sha256.New() - tree := smt.NewSparseMerkleTree(dbm.NewMemDB(), hasher) + tree := smt.NewSparseMerkleTree(memdb.NewDB(), hasher) key := []byte("foo") value := []byte("bar") root, err := tree.Update(key, value) diff --git a/store/smt/store.go b/store/smt/store.go index b70b097515d9..cb88149d1539 100644 --- a/store/smt/store.go +++ b/store/smt/store.go @@ -7,12 +7,12 @@ import ( "sync" "time" + dbm "github.com/cosmos/cosmos-sdk/db" "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/tracekv" "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" abci "github.com/tendermint/tendermint/abci/types" - dbm "github.com/tendermint/tm-db" "github.com/lazyledger/smt" ) @@ -36,7 +36,7 @@ var ( // Store Implements types.KVStore and CommitKVStore. type Store struct { tree *smt.SparseMerkleTree - db dbm.DB + db dbm.DBReadWriter version int64 @@ -48,7 +48,7 @@ type Store struct { mtx sync.RWMutex } -func NewStore(underlyingDB dbm.DB) *Store { +func NewStore(underlyingDB dbm.DBReadWriter) *Store { return &Store{ tree: smt.NewSparseMerkleTree(underlyingDB, sha256.New()), db: underlyingDB, diff --git a/store/smt/store_test.go b/store/smt/store_test.go index a655e4b6d320..9cf21d820dfb 100644 --- a/store/smt/store_test.go +++ b/store/smt/store_test.go @@ -5,8 +5,8 @@ import ( "github.com/stretchr/testify/assert" + dbm "github.com/cosmos/cosmos-sdk/db" "github.com/cosmos/cosmos-sdk/store/smt" - dbm "github.com/tendermint/tm-db" ) func TestVersioning(t *testing.T) { diff --git a/store/tracekv/store_test.go b/store/tracekv/store_test.go index db9a981237f4..57ba29e958b5 100644 --- a/store/tracekv/store_test.go +++ b/store/tracekv/store_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/cosmos/cosmos-sdk/store/dbadapter" "github.com/cosmos/cosmos-sdk/store/prefix" @@ -38,7 +38,7 @@ func newTraceKVStore(w io.Writer) *tracekv.Store { } func newEmptyTraceKVStore(w io.Writer) *tracekv.Store { - memDB := dbadapter.Store{DB: dbm.NewMemDB()} + memDB := dbadapter.Store{DB: memdb.NewDB()} tc := types.TraceContext(map[string]interface{}{"blockHeight": 64}) return tracekv.NewStore(memDB, w, tc) @@ -277,7 +277,7 @@ func TestTraceKVStorePrefix(t *testing.T) { } func TestTraceKVStoreGetStoreType(t *testing.T) { - memDB := dbadapter.Store{DB: dbm.NewMemDB()} + memDB := dbadapter.Store{DB: memdb.NewDB()} store := newEmptyTraceKVStore(nil) require.Equal(t, memDB.GetStoreType(), store.GetStoreType()) } diff --git a/store/transient/store.go b/store/transient/store.go index 572ab55f7697..2a3b6807e5ca 100644 --- a/store/transient/store.go +++ b/store/transient/store.go @@ -1,7 +1,7 @@ package transient import ( - dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/cosmos/cosmos-sdk/store/dbadapter" "github.com/cosmos/cosmos-sdk/store/types" @@ -17,13 +17,13 @@ type Store struct { // Constructs new MemDB adapter func NewStore() *Store { - return &Store{Store: dbadapter.Store{DB: dbm.NewMemDB()}} + return &Store{Store: dbadapter.Store{DB: memdb.NewDB()}} } // Implements CommitStore // Commit cleans up Store. func (ts *Store) Commit() (id types.CommitID) { - ts.Store = dbadapter.Store{DB: dbm.NewMemDB()} + ts.Store = dbadapter.Store{DB: memdb.NewDB()} return } diff --git a/store/types/iterator_test.go b/store/types/iterator_test.go index 3086917b605b..84b9f8da7ba4 100644 --- a/store/types/iterator_test.go +++ b/store/types/iterator_test.go @@ -3,15 +3,16 @@ package types_test import ( "testing" + dbm "github.com/cosmos/cosmos-sdk/db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/stretchr/testify/require" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/iavl" "github.com/cosmos/cosmos-sdk/store/types" ) func newMemTestKVStore(t *testing.T) types.KVStore { - db := dbm.NewMemDB() + db := dbm.MungeTmdb(memdb.NewDB()) store, err := iavl.LoadStore(db, types.CommitID{}, false) require.NoError(t, err) return store diff --git a/store/types/store.go b/store/types/store.go index a79b7cd5e67b..423d26153fdd 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -4,9 +4,10 @@ import ( "fmt" "io" + dbm "github.com/cosmos/cosmos-sdk/db" abci "github.com/tendermint/tendermint/abci/types" tmstrings "github.com/tendermint/tendermint/libs/strings" - dbm "github.com/tendermint/tm-db" + tmdb "github.com/tendermint/tm-db" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -153,7 +154,7 @@ type CommitMultiStore interface { // Mount a store of type using the given db. // If db == nil, the new store will use the CommitMultiStore db. - MountStoreWithDB(key StoreKey, typ StoreType, db dbm.DB) + MountStoreWithDB(key StoreKey, typ StoreType, db tmdb.DB) // Panics on a nil key. GetCommitStore(key StoreKey) CommitStore diff --git a/store/types/utils_test.go b/store/types/utils_test.go index 32064d7e1821..0c1453112be7 100644 --- a/store/types/utils_test.go +++ b/store/types/utils_test.go @@ -4,15 +4,16 @@ import ( "bytes" "testing" + dbm "github.com/cosmos/cosmos-sdk/db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/stretchr/testify/require" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/rootmulti" "github.com/cosmos/cosmos-sdk/store/types" ) func initTestStores(t *testing.T) (types.KVStore, types.KVStore) { - db := dbm.NewMemDB() + db := dbm.MungeTmdb(memdb.NewDB()) ms := rootmulti.NewStore(db) key1 := types.NewKVStoreKey("store1") diff --git a/types/query/pagination.go b/types/query/pagination.go index 3244e283259e..378771aaaaef 100644 --- a/types/query/pagination.go +++ b/types/query/pagination.go @@ -4,10 +4,10 @@ import ( "fmt" "math" - db "github.com/tendermint/tm-db" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + dbm "github.com/cosmos/cosmos-sdk/db" "github.com/cosmos/cosmos-sdk/store/types" ) @@ -141,7 +141,7 @@ func Paginate( return res, nil } -func getIterator(prefixStore types.KVStore, start []byte, reverse bool) db.Iterator { +func getIterator(prefixStore types.KVStore, start []byte, reverse bool) dbm.Iterator { if reverse { var end []byte if start != nil { diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index da07a5e1b093..7bf1956ad46f 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -76,7 +76,7 @@ func (s *paginationTestSuite) TestPagination() { addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) app.AccountKeeper.SetAccount(ctx, acc1) - s.Require().NoError(simapp.FundAccount(app.BankKeeper, ctx, addr1, balances)) + s.Require().NoError(simapp.FundAccount(app, ctx, addr1, balances)) s.T().Log("verify empty page request results a max of defaultLimit records and counts total records") pageReq := &query.PageRequest{} @@ -185,7 +185,7 @@ func (s *paginationTestSuite) TestReversePagination() { addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) app.AccountKeeper.SetAccount(ctx, acc1) - s.Require().NoError(simapp.FundAccount(app.BankKeeper, ctx, addr1, balances)) + s.Require().NoError(simapp.FundAccount(app, ctx, addr1, balances)) s.T().Log("verify paginate with custom limit and countTotal, Reverse false") pageReq := &query.PageRequest{Limit: 2, CountTotal: true, Reverse: true, Key: nil} @@ -306,7 +306,7 @@ func ExamplePaginate() { addr1 := sdk.AccAddress([]byte("addr1")) acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) app.AccountKeeper.SetAccount(ctx, acc1) - err := simapp.FundAccount(app.BankKeeper, ctx, addr1, balances) + err := simapp.FundAccount(app, ctx, addr1, balances) if err != nil { // should return no error fmt.Println(err) } diff --git a/types/store_test.go b/types/store_test.go index 9c3ef2f79dd6..fbbb8dade693 100644 --- a/types/store_test.go +++ b/types/store_test.go @@ -3,8 +3,9 @@ package types_test import ( "testing" + dbm "github.com/cosmos/cosmos-sdk/db" + "github.com/cosmos/cosmos-sdk/db/memdb" "github.com/stretchr/testify/suite" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/rootmulti" "github.com/cosmos/cosmos-sdk/store/types" @@ -107,7 +108,7 @@ func (s *storeTestSuite) TestDiffKVStores() { } func (s *storeTestSuite) initTestStores() (types.KVStore, types.KVStore) { - db := dbm.NewMemDB() + db := dbm.MungeTmdb(memdb.NewDB()) ms := rootmulti.NewStore(db) key1 := types.NewKVStoreKey("store1")