diff --git a/Makefile b/Makefile index 367e69cca6..76b47e860a 100644 --- a/Makefile +++ b/Makefile @@ -223,11 +223,11 @@ TEST_TARGETS := test-unit test-unit-amino test-unit-proto test-ledger-mock test- # Test runs-specific rules. To add a new test target, just add # a new rule, customise ARGS or TEST_PACKAGES ad libitum, and # append the new rule to the TEST_TARGETS list. -test-unit: ARGS=-tags='cgo ledger test_ledger_mock norace' -test-unit-amino: ARGS=-tags='ledger test_ledger_mock test_amino norace' -test-ledger: ARGS=-tags='cgo ledger norace' -test-ledger-mock: ARGS=-tags='ledger test_ledger_mock norace' -test-race: ARGS=-race -tags='cgo ledger test_ledger_mock' +test-unit: ARGS=-tags='cgo ledger test_ledger_mock norace goleveldb' +test-unit-amino: ARGS=-tags='ledger test_ledger_mock test_amino norace goleveldb' +test-ledger: ARGS=-tags='cgo ledger norace goleveldb' +test-ledger-mock: ARGS=-tags='ledger test_ledger_mock norace goleveldb' +test-race: ARGS=-race -tags='cgo ledger test_ledger_mock goleveldb' test-race: TEST_PACKAGES=$(PACKAGES_NOSIMULATION) $(TEST_TARGETS): run-tests diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 7ebd08bb69..f1dbc7569f 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -6,7 +6,7 @@ import ( abci "github.com/line/ostracon/abci/types" ostprototypes "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" sdk "github.com/line/lbm-sdk/v2/types" @@ -14,7 +14,7 @@ import ( func TestGetBlockRentionHeight(t *testing.T) { logger := defaultLogger() - db := dbm.NewMemDB() + db := memdb.NewDB() name := t.Name() testCases := map[string]struct { @@ -103,7 +103,7 @@ func TestGetBlockRentionHeight(t *testing.T) { for name, tc := range testCases { tc := tc - tc.bapp.SetParamStore(¶mStore{db: dbm.NewMemDB()}) + tc.bapp.SetParamStore(¶mStore{db: memdb.NewDB()}) tc.bapp.InitChain(abci.RequestInitChain{ ConsensusParams: &abci.ConsensusParams{ Evidence: &ostprototypes.EvidenceParams{ @@ -124,7 +124,7 @@ func TestBaseAppCreateQueryContextRejectsNegativeHeights(t *testing.T) { t.Parallel() logger := defaultLogger() - db := dbm.NewMemDB() + db := memdb.NewDB() name := t.Name() app := NewBaseApp(name, logger, db, nil) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 17a715928b..1636cd663e 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -11,7 +11,7 @@ import ( "github.com/line/ostracon/crypto/tmhash" "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/codec/types" "github.com/line/lbm-sdk/v2/snapshots" @@ -48,7 +48,7 @@ type BaseApp struct { // nolint: maligned // initialized on creation logger log.Logger name string // application name from abci.Info - db dbm.DB // common DB backend + db tmdb.DB // common DB backend cms sdk.CommitMultiStore // Main (uncached) state storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader() router sdk.Router // handle any kind of message @@ -136,7 +136,7 @@ type BaseApp struct { // nolint: maligned // // NOTE: The db is used to store the version number for now. func NewBaseApp( - name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp), + name string, logger log.Logger, db tmdb.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp), ) *BaseApp { app := &BaseApp{ logger: logger, diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 9ae71ca8a8..0648ca6f76 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -17,7 +17,8 @@ import ( abci "github.com/line/ostracon/abci/types" "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -38,7 +39,7 @@ var ( ) type paramStore struct { - db *dbm.MemDB + db *memdb.MemDB } func (ps *paramStore) Set(_ sdk.Context, key []byte, value interface{}) { @@ -80,7 +81,7 @@ func defaultLogger() log.Logger { func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp { logger := defaultLogger() - db := dbm.NewMemDB() + db := memdb.NewDB() codec := codec.NewLegacyAmino() registerTestCodec(codec) return NewBaseApp(name, logger, db, testTxDecoder(codec), options...) @@ -112,7 +113,7 @@ func setupBaseApp(t *testing.T, options ...func(*BaseApp)) *BaseApp { require.Equal(t, t.Name(), app.Name()) app.MountStores(capKey1, capKey2) - app.SetParamStore(¶mStore{db: dbm.NewMemDB()}) + app.SetParamStore(¶mStore{db: memdb.NewDB()}) // stores are mounted err := app.LoadLatestVersion() @@ -136,7 +137,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options snapshotTimeout := 1 * time.Minute snapshotDir, err := ioutil.TempDir("", "baseapp") require.NoError(t, err) - snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), snapshotDir) + snapshotStore, err := snapshots.NewStore(memdb.NewDB(), snapshotDir) require.NoError(t, err) teardown := func() { os.RemoveAll(snapshotDir) @@ -207,7 +208,7 @@ func TestMountStores(t *testing.T) { func TestLoadVersion(t *testing.T) { logger := defaultLogger() pruningOpt := SetPruning(store.PruneNothing) - db := dbm.NewMemDB() + db := memdb.NewDB() name := t.Name() app := NewBaseApp(name, logger, db, nil, pruningOpt) @@ -257,7 +258,7 @@ func useDefaultLoader(app *BaseApp) { app.SetStoreLoader(DefaultStoreLoader) } -func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { +func initStore(t *testing.T, db tmdb.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) @@ -274,7 +275,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { require.Equal(t, int64(1), commitID.Version) } -func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { +func checkStore(t *testing.T, db tmdb.DB, ver int64, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneDefault) key := sdk.NewKVStoreKey(storeKey) @@ -315,7 +316,7 @@ func TestSetLoader(t *testing.T) { tc := tc t.Run(name, func(t *testing.T) { // prepare a db with some data - db := dbm.NewMemDB() + db := memdb.NewDB() initStore(t, db, tc.origStoreKey, k, v) // load the app with the existing db @@ -343,7 +344,7 @@ func TestSetLoader(t *testing.T) { func TestAppVersionSetterGetter(t *testing.T) { logger := defaultLogger() pruningOpt := SetPruning(store.PruneDefault) - db := dbm.NewMemDB() + db := memdb.NewDB() name := t.Name() app := NewBaseApp(name, logger, db, nil, pruningOpt) @@ -363,7 +364,7 @@ func TestAppVersionSetterGetter(t *testing.T) { func TestLoadVersionInvalid(t *testing.T) { logger := log.NewNopLogger() pruningOpt := SetPruning(store.PruneNothing) - db := dbm.NewMemDB() + db := memdb.NewDB() name := t.Name() app := NewBaseApp(name, logger, db, nil, pruningOpt) @@ -400,7 +401,7 @@ func TestLoadVersionPruning(t *testing.T) { Interval: 1, } pruningOpt := SetPruning(pruningOptions) - db := dbm.NewMemDB() + db := memdb.NewDB() name := t.Name() app := NewBaseApp(name, logger, db, nil, pruningOpt) @@ -457,7 +458,7 @@ func testLoadVersionHelper(t *testing.T, app *BaseApp, expectedHeight int64, exp func TestOptionFunction(t *testing.T) { logger := defaultLogger() - db := dbm.NewMemDB() + db := memdb.NewDB() bap := NewBaseApp("starting name", logger, db, nil, testChangeNameHelper("new name")) require.Equal(t, bap.name, "new name", "BaseApp should have had name changed via option function") } @@ -554,7 +555,7 @@ func TestInitChainer(t *testing.T) { name := t.Name() // keep the db and logger ourselves so // we can reload the same app later - db := dbm.NewMemDB() + db := memdb.NewDB() logger := defaultLogger() app := NewBaseApp(name, logger, db, nil) capKey := sdk.NewKVStoreKey("main") @@ -633,7 +634,7 @@ func TestInitChainer(t *testing.T) { func TestInitChain_WithInitialHeight(t *testing.T) { name := t.Name() - db := dbm.NewMemDB() + db := memdb.NewDB() logger := defaultLogger() app := NewBaseApp(name, logger, db, nil) @@ -649,7 +650,7 @@ func TestInitChain_WithInitialHeight(t *testing.T) { func TestBeginBlock_WithInitialHeight(t *testing.T) { name := t.Name() - db := dbm.NewMemDB() + db := memdb.NewDB() logger := defaultLogger() app := NewBaseApp(name, logger, db, nil) @@ -902,7 +903,7 @@ func incrementingCounter(t *testing.T, store sdk.KVStore, counterKey []byte, cou return &sdk.Result{}, nil } -//--------------------------------------------------------------------- +// --------------------------------------------------------------------- // Tx processing - CheckTx, DeliverTx, SimulateTx. // These tests use the serialized tx as input, while most others will use the // Check(), Deliver(), Simulate() methods directly. @@ -2005,7 +2006,7 @@ func TestWithRouter(t *testing.T) { } func TestBaseApp_EndBlock(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() name := t.Name() logger := defaultLogger() @@ -2016,7 +2017,7 @@ func TestBaseApp_EndBlock(t *testing.T) { } app := NewBaseApp(name, logger, db, nil) - app.SetParamStore(¶mStore{db: dbm.NewMemDB()}) + app.SetParamStore(¶mStore{db: memdb.NewDB()}) app.InitChain(abci.RequestInitChain{ ConsensusParams: cp, }) diff --git a/baseapp/grpcrouter_test.go b/baseapp/grpcrouter_test.go index 70a28cce63..8c71b8a923 100644 --- a/baseapp/grpcrouter_test.go +++ b/baseapp/grpcrouter_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/line/ostracon/libs/log" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/baseapp" @@ -52,7 +52,7 @@ func TestGRPCGatewayRouter(t *testing.T) { func TestRegisterQueryServiceTwice(t *testing.T) { // Setup baseapp. - db := dbm.NewMemDB() + db := memdb.NewDB() encCfg := simapp.MakeTestEncodingConfig() app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder()) app.SetInterfaceRegistry(encCfg.InterfaceRegistry) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index b67d5e97bc..6fe4e068bb 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -7,7 +7,7 @@ import ( abci "github.com/line/ostracon/abci/types" "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/baseapp" @@ -19,7 +19,7 @@ import ( ) func TestRegisterMsgService(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() // Create an encoding config that doesn't register testdata Msg services. encCfg := simapp.MakeTestEncodingConfig() @@ -44,7 +44,7 @@ func TestRegisterMsgService(t *testing.T) { func TestRegisterMsgServiceTwice(t *testing.T) { // Setup baseapp. - db := dbm.NewMemDB() + db := memdb.NewDB() encCfg := simapp.MakeTestEncodingConfig() app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder()) app.SetInterfaceRegistry(encCfg.InterfaceRegistry) @@ -71,7 +71,7 @@ func TestMsgService(t *testing.T) { priv, _, _ := testdata.KeyTestPubAddr() encCfg := simapp.MakeTestEncodingConfig() testdata.RegisterInterfaces(encCfg.InterfaceRegistry) - db := dbm.NewMemDB() + db := memdb.NewDB() app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder()) app.SetInterfaceRegistry(encCfg.InterfaceRegistry) testdata.RegisterMsgServer( diff --git a/baseapp/options.go b/baseapp/options.go index 5c2dfd8d41..120462b37d 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/codec/types" "github.com/line/lbm-sdk/v2/snapshots" @@ -104,7 +104,7 @@ func (app *BaseApp) SetAppVersion(v string) { app.appVersion = v } -func (app *BaseApp) SetDB(db dbm.DB) { +func (app *BaseApp) SetDB(db tmdb.DB) { if app.sealed { panic("SetDB() on sealed BaseApp") } diff --git a/crypto/keyring/legacy.go b/crypto/keyring/legacy.go index 476b7e8709..a20e7191b9 100644 --- a/crypto/keyring/legacy.go +++ b/crypto/keyring/legacy.go @@ -6,7 +6,7 @@ import ( "strings" ostos "github.com/line/ostracon/libs/os" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/pkg/errors" "github.com/line/lbm-sdk/v2/crypto" @@ -45,12 +45,12 @@ var _ LegacyKeybase = dbKeybase{} // // NOTE: dbKeybase will be deprecated in favor of keyringKeybase. type dbKeybase struct { - db dbm.DB + db tmdb.DB } // newDBKeybase creates a new dbKeybase instance using the provided DB for // reading and writing keys. -func newDBKeybase(db dbm.DB) dbKeybase { +func newDBKeybase(db tmdb.DB) dbKeybase { return dbKeybase{ db: db, } diff --git a/go.mod b/go.mod index c1ae333e67..46ee491201 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ module github.com/line/lbm-sdk/v2 require ( github.com/99designs/keyring v1.1.6 - github.com/DataDog/zstd v1.4.5 // indirect github.com/armon/go-metrics v0.3.6 github.com/bgentry/speakeasy v0.1.0 github.com/btcsuite/btcd v0.21.0-beta @@ -12,22 +11,19 @@ require ( github.com/confio/ics23/go v0.6.3 github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/ledger-cosmos-go v0.11.1 - github.com/dgraph-io/ristretto v0.0.3 // indirect - github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25 github.com/gogo/gateway v1.1.0 github.com/gogo/protobuf v1.3.3 github.com/golang/mock v1.4.4 github.com/golang/protobuf v1.4.3 - github.com/golang/snappy v0.0.2 // indirect github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/hashicorp/golang-lru v0.5.4 - github.com/line/iavl/v2 v2.0.0-init.1 - github.com/line/ostracon v0.34.9-0.20210316071456-5fea666cc7ce - github.com/line/tm-db/v2 v2.0.0-init.1 + github.com/line/iavl/v2 v2.0.0-init.1.0.20210325055816-6304f1fd2f09 + github.com/line/ostracon v0.34.9-0.20210325081149-c7c246b1be58 + github.com/line/tm-db/v2 v2.0.0-init.1.0.20210325025547-0ea105c02281 github.com/magiconair/properties v1.8.4 github.com/mattn/go-isatty v0.0.12 github.com/otiai10/copy v1.4.2 diff --git a/go.sum b/go.sum index 505e7c7ce5..1294d1a899 100644 --- a/go.sum +++ b/go.sum @@ -18,9 +18,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM= github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= -github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= -github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -123,13 +122,11 @@ github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0 github.com/dgraph-io/badger/v2 v2.2007.1/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= github.com/dgraph-io/badger/v2 v2.2007.2 h1:EjjK0KqwaFMlPin1ajhP943VPENHJdEz1KLIegjaI3k= github.com/dgraph-io/badger/v2 v2.2007.2/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= +github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de h1:t0UHb5vdojIDUqktM6+xJAfScFBsVpXZmqC9dsgJmeA= github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= -github.com/dgraph-io/ristretto v0.0.3 h1:jh22xisGBjrEVnRZ1DVTpBVQm0Xndu8sMl0CWDzSIBI= -github.com/dgraph-io/ristretto v0.0.3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= -github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= @@ -202,9 +199,8 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw= -github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -320,6 +316,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= @@ -328,13 +325,13 @@ github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOS github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/line/iavl/v2 v2.0.0-init.1 h1:Qn+57tRRRlCsyMsgZs9YcoLlPPBi6QMVMhEwjHubCVk= -github.com/line/iavl/v2 v2.0.0-init.1/go.mod h1:isewgbbDSuyhB67oiOoX9ide3AOug2Y35gFqZaHI3L4= +github.com/line/iavl/v2 v2.0.0-init.1.0.20210325055816-6304f1fd2f09 h1:11L4wU4iYYRfOP20qo7909Q0gkd1NG8GOjSPu3Bblcg= +github.com/line/iavl/v2 v2.0.0-init.1.0.20210325055816-6304f1fd2f09/go.mod h1:lOUXCMWnB9G5wDfungP5nhnHAFgVBwB0/iqFhH44OIs= github.com/line/ostracon v0.34.9-0.20210315041958-2a1f43c788f5/go.mod h1:1THU+kF+6fxLaNYQKcdNyLCO6t9LnqSMaExDMiLozbM= -github.com/line/ostracon v0.34.9-0.20210316071456-5fea666cc7ce h1:NLEQisrrFLOHCTfY6oFARnPWO2avqPmmas8lTfgMLCc= -github.com/line/ostracon v0.34.9-0.20210316071456-5fea666cc7ce/go.mod h1:PthHRpDto0bepI2qpZdTSNIx50Jr7HOiecKGyIxm09s= -github.com/line/tm-db/v2 v2.0.0-init.1 h1:oYM+IJk1GuxDx/OPhCbyvGLnpyQYa7dWg1IDjTOqdjQ= -github.com/line/tm-db/v2 v2.0.0-init.1/go.mod h1:TiTwPFffNAqep0nV0YWaxPjElbCp6yG4K8SCxy69mE4= +github.com/line/ostracon v0.34.9-0.20210325081149-c7c246b1be58 h1:k+/hsrZ1RFIlL9+PRDzKPY+5YKFDWklReIgbeYmt+c4= +github.com/line/ostracon v0.34.9-0.20210325081149-c7c246b1be58/go.mod h1:JQ5id/iSwal6/BAoN119QEzfTKm90DNPqB1mPiCR8Jk= +github.com/line/tm-db/v2 v2.0.0-init.1.0.20210325025547-0ea105c02281 h1:HwehzGvsgPHND01825UbjjiKgwfbqIYFAnvn6OheLQs= +github.com/line/tm-db/v2 v2.0.0-init.1.0.20210325025547-0ea105c02281/go.mod h1:TiTwPFffNAqep0nV0YWaxPjElbCp6yG4K8SCxy69mE4= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY= @@ -803,6 +800,7 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U= diff --git a/server/export_test.go b/server/export_test.go index 512a40a0e9..06553cc3ad 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -18,7 +18,8 @@ import ( "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" osttypes "github.com/line/ostracon/types" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/client" "github.com/line/lbm-sdk/v2/client/flags" @@ -128,7 +129,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *o } logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) - db := dbm.NewMemDB() + db := memdb.NewDB() encCfg := simapp.MakeTestEncodingConfig() app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg, simapp.EmptyAppOptions{}) @@ -149,7 +150,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *o app.Commit() cmd := server.ExportCmd( - func(_ log.Logger, _ dbm.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOptons types.AppOptions) (types.ExportedApp, error) { + func(_ log.Logger, _ tmdb.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOptons types.AppOptions) (types.ExportedApp, error) { encCfg := simapp.MakeTestEncodingConfig() var simApp *simapp.SimApp diff --git a/server/mock/store.go b/server/mock/store.go index 3cd830d2bd..c0dc254c97 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -3,7 +3,7 @@ package mock import ( "io" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" store "github.com/line/lbm-sdk/v2/store/types" sdk "github.com/line/lbm-sdk/v2/types" @@ -67,7 +67,7 @@ func (ms multiStore) GetCommitStore(key sdk.StoreKey) sdk.CommitStore { panic("not implemented") } -func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) { +func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db tmdb.DB) { ms.kv[key] = kvStore{store: make(map[string][]byte)} } diff --git a/server/mock/store_test.go b/server/mock/store_test.go index 9e2f3079b5..7111233bf8 100644 --- a/server/mock/store_test.go +++ b/server/mock/store_test.go @@ -5,13 +5,13 @@ import ( "github.com/stretchr/testify/require" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" sdk "github.com/line/lbm-sdk/v2/types" ) func TestStore(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() cms := NewCommitMultiStore() key := sdk.NewKVStoreKey("test") diff --git a/server/types/app.go b/server/types/app.go index b8d2831242..98f23e9242 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -8,7 +8,7 @@ import ( abci "github.com/line/ostracon/abci/types" "github.com/line/ostracon/libs/log" osttypes "github.com/line/ostracon/types" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/spf13/cobra" "github.com/line/lbm-sdk/v2/client" @@ -50,7 +50,7 @@ type ( // AppCreator is a function that allows us to lazily initialize an // application using various configurations. - AppCreator func(log.Logger, dbm.DB, io.Writer, AppOptions) Application + AppCreator func(log.Logger, tmdb.DB, io.Writer, AppOptions) Application // ModuleInitFlags takes a start command and adds modules specific init flags. ModuleInitFlags func(startCmd *cobra.Command) @@ -70,5 +70,5 @@ type ( // AppExporter is a function that dumps all app state to // JSON-serializable structure and returns the current validator set. - AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string, AppOptions) (ExportedApp, error) + AppExporter func(log.Logger, tmdb.DB, io.Writer, int64, bool, []string, AppOptions) (ExportedApp, error) ) diff --git a/server/util.go b/server/util.go index 950ee402b2..1b040b6311 100644 --- a/server/util.go +++ b/server/util.go @@ -16,7 +16,7 @@ import ( ostcfg "github.com/line/ostracon/config" ostlog "github.com/line/ostracon/libs/log" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -360,7 +360,7 @@ func addrToIP(addr net.Addr) net.IP { return ip } -func openDB(rootDir string) (dbm.DB, error) { +func openDB(rootDir string) (tmdb.DB, error) { dataDir := filepath.Join(rootDir, "data") return sdk.NewLevelDB("application", dataDir) } diff --git a/simapp/app.go b/simapp/app.go index aa9656ec73..e13779f402 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -12,7 +12,7 @@ import ( "github.com/line/ostracon/libs/log" ostos "github.com/line/ostracon/libs/os" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/rakyll/statik/fs" "github.com/spf13/cast" @@ -193,7 +193,7 @@ func init() { // NewSimApp returns a reference to an initialized SimApp. func NewSimApp( - logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool, + logger log.Logger, db tmdb.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { diff --git a/simapp/app_test.go b/simapp/app_test.go index d5d658900c..fcf7ec15b5 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/line/ostracon/libs/log" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" abci "github.com/line/ostracon/abci/types" @@ -14,7 +14,7 @@ import ( func TestSimAppExportAndBlockedAddrs(t *testing.T) { encCfg := MakeTestEncodingConfig() - db := dbm.NewMemDB() + db := memdb.NewDB() app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}) for acc := range maccPerms { diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 0aa111b16d..3625717fc9 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -10,7 +10,7 @@ import ( abci "github.com/line/ostracon/abci/types" "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/baseapp" @@ -298,7 +298,7 @@ func TestAppStateDeterminism(t *testing.T) { logger = log.NewNopLogger() } - db := dbm.NewMemDB() + db := memdb.NewDB() app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) fmt.Printf( diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 4ab54e1e09..d15cc40d29 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -8,7 +8,7 @@ import ( ostcli "github.com/line/ostracon/libs/cli" "github.com/line/ostracon/libs/log" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/spf13/cast" "github.com/spf13/cobra" @@ -154,7 +154,7 @@ type appCreator struct { } // newApp is an AppCreator -func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application { +func (a appCreator) newApp(logger log.Logger, db tmdb.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application { var cache sdk.MultiStorePersistentCache if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) { @@ -204,7 +204,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a // appExport creates a new simapp (optionally at a given height) // and exports state. func (a appCreator) appExport( - logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, + logger log.Logger, db tmdb.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOpts servertypes.AppOptions) (servertypes.ExportedApp, error) { var simApp *simapp.SimApp diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index ce6a844c78..720f49e08e 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -13,7 +13,7 @@ import ( "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" osttypes "github.com/line/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" bam "github.com/line/lbm-sdk/v2/baseapp" @@ -50,7 +50,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{ } func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { - db := dbm.NewMemDB() + db := memdb.NewDB() encCdc := MakeTestEncodingConfig() app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{}) if withGenesis { diff --git a/simapp/utils.go b/simapp/utils.go index b9e312f124..7cdea9c235 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "github.com/line/ostracon/libs/log" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/codec" "github.com/line/lbm-sdk/v2/simapp/helpers" @@ -19,7 +19,7 @@ import ( // SetupSimulation creates the config, db (levelDB), temporary directory and logger for // the simulation tests. If `FlagEnabledValue` is false it skips the current test. // Returns error on an invalid db intantiation or temp dir creation. -func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, log.Logger, bool, error) { +func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, tmdb.DB, string, log.Logger, bool, error) { if !FlagEnabledValue { return simtypes.Config{}, nil, "", nil, true, nil } @@ -104,7 +104,7 @@ func CheckExportSimulation( } // PrintStats prints the corresponding statistics from the app DB. -func PrintStats(db dbm.DB) { +func PrintStats(db tmdb.DB) { fmt.Println("\nLevelDB Stats") fmt.Println(db.Stats()["leveldb.stats"]) fmt.Println("LevelDB cached block size", db.Stats()["leveldb.cachedblock"]) diff --git a/snapshots/helpers_test.go b/snapshots/helpers_test.go index 1c973d3958..22f7ddb46c 100644 --- a/snapshots/helpers_test.go +++ b/snapshots/helpers_test.go @@ -10,9 +10,10 @@ import ( "testing" "time" - db "github.com/line/tm-db/v2" "github.com/stretchr/testify/require" + "github.com/line/tm-db/v2/memdb" + "github.com/line/lbm-sdk/v2/snapshots" "github.com/line/lbm-sdk/v2/snapshots/types" ) @@ -105,7 +106,7 @@ func setupBusyManager(t *testing.T) *snapshots.Manager { require.NoError(t, err) t.Cleanup(func() { _ = os.RemoveAll(tempdir) }) - store, err := snapshots.NewStore(db.NewMemDB(), tempdir) + store, err := snapshots.NewStore(memdb.NewDB(), tempdir) require.NoError(t, err) hung := newHungSnapshotter() mgr := snapshots.NewManager(store, hung) diff --git a/snapshots/store.go b/snapshots/store.go index 96cd95749f..382a8f2bb8 100644 --- a/snapshots/store.go +++ b/snapshots/store.go @@ -11,7 +11,7 @@ import ( "sync" "github.com/gogo/protobuf/proto" - db "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/snapshots/types" sdkerrors "github.com/line/lbm-sdk/v2/types/errors" @@ -24,7 +24,7 @@ const ( // Store is a snapshot store, containing snapshot metadata and binary chunks. type Store struct { - db db.DB + db tmdb.DB dir string mtx sync.Mutex @@ -32,7 +32,7 @@ type Store struct { } // NewStore creates a new snapshot store. -func NewStore(db db.DB, dir string) (*Store, error) { +func NewStore(db tmdb.DB, dir string) (*Store, error) { if dir == "" { return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "snapshot directory not given") } diff --git a/snapshots/store_test.go b/snapshots/store_test.go index 10ca90da5e..77932d1d54 100644 --- a/snapshots/store_test.go +++ b/snapshots/store_test.go @@ -10,10 +10,11 @@ import ( "testing" "time" - db "github.com/line/tm-db/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/line/tm-db/v2/memdb" + "github.com/line/lbm-sdk/v2/snapshots" "github.com/line/lbm-sdk/v2/snapshots/types" "github.com/line/lbm-sdk/v2/testutil" @@ -24,7 +25,7 @@ func setupStore(t *testing.T) *snapshots.Store { require.NoError(t, err) t.Cleanup(func() { _ = os.RemoveAll(tempdir) }) - store, err := snapshots.NewStore(db.NewMemDB(), tempdir) + store, err := snapshots.NewStore(memdb.NewDB(), tempdir) require.NoError(t, err) _, err = store.Save(1, 1, makeChunks([][]byte{ @@ -49,20 +50,20 @@ func setupStore(t *testing.T) *snapshots.Store { func TestNewStore(t *testing.T) { tempdir := t.TempDir() - _, err := snapshots.NewStore(db.NewMemDB(), tempdir) + _, err := snapshots.NewStore(memdb.NewDB(), tempdir) require.NoError(t, err) } func TestNewStore_ErrNoDir(t *testing.T) { - _, err := snapshots.NewStore(db.NewMemDB(), "") + _, err := snapshots.NewStore(memdb.NewDB(), "") require.Error(t, err) } func TestNewStore_ErrDirFailure(t *testing.T) { notADir := filepath.Join(testutil.TempFile(t).Name(), "subdir") - _, err := snapshots.NewStore(db.NewMemDB(), notADir) + _, err := snapshots.NewStore(memdb.NewDB(), notADir) require.Error(t, err) } diff --git a/store/cache/cache_test.go b/store/cache/cache_test.go index 0aa923310f..934f0aae52 100644 --- a/store/cache/cache_test.go +++ b/store/cache/cache_test.go @@ -4,17 +4,18 @@ import ( "fmt" "testing" - "github.com/line/iavl/v2" - dbm "github.com/line/tm-db/v2" "github.com/stretchr/testify/require" + "github.com/line/iavl/v2" + "github.com/line/tm-db/v2/memdb" + "github.com/line/lbm-sdk/v2/store/cache" iavlstore "github.com/line/lbm-sdk/v2/store/iavl" "github.com/line/lbm-sdk/v2/store/types" ) func TestGetOrSetStoreCache(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize) sKey := types.NewKVStoreKey("test") @@ -28,7 +29,7 @@ func TestGetOrSetStoreCache(t *testing.T) { } func TestUnwrap(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize) sKey := types.NewKVStoreKey("test") @@ -42,7 +43,7 @@ func TestUnwrap(t *testing.T) { } func TestStoreCache(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize) sKey := types.NewKVStoreKey("test") diff --git a/store/cachekv/memiterator.go b/store/cachekv/memiterator.go index 953dfce582..936d77f1ac 100644 --- a/store/cachekv/memiterator.go +++ b/store/cachekv/memiterator.go @@ -4,7 +4,7 @@ import ( "container/list" "errors" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/types/kv" ) @@ -25,7 +25,7 @@ func newMemIterator(start, end []byte, items *list.List, ascending bool) *memIte for e := items.Front(); e != nil; e = e.Next() { item := e.Value.(*kv.Pair) - if !dbm.IsKeyInDomain(item.Key, start, end) { + if !tmdb.IsKeyInDomain(item.Key, start, end) { if entered { break } diff --git a/store/cachekv/store.go b/store/cachekv/store.go index b919addf19..ea0097264e 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -10,7 +10,7 @@ import ( "time" "unsafe" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/store/tracekv" "github.com/line/lbm-sdk/v2/store/types" @@ -207,7 +207,7 @@ func (store *Store) dirtyItems(start, end []byte) { n := len(store.unsortedCache) for key := range store.unsortedCache { - if dbm.IsKeyInDomain(strToByte(key), start, end) { + if tmdb.IsKeyInDomain(strToByte(key), start, end) { cacheValue := store.cache[key] unsorted = append(unsorted, &kv.Pair{Key: []byte(key), Value: cacheValue.value}) } diff --git a/store/cachekv/store_bench_test.go b/store/cachekv/store_bench_test.go index f33c55fe7c..1a186b3406 100644 --- a/store/cachekv/store_bench_test.go +++ b/store/cachekv/store_bench_test.go @@ -5,14 +5,14 @@ import ( "sort" "testing" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/store/cachekv" "github.com/line/lbm-sdk/v2/store/dbadapter" ) func benchmarkCacheKVStoreIterator(numKVs int, b *testing.B) { - 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 364a8841e9..4648a1303e 100644 --- a/store/cachekv/store_test.go +++ b/store/cachekv/store_test.go @@ -4,17 +4,19 @@ import ( "fmt" "testing" - ostrand "github.com/line/ostracon/libs/rand" - dbm "github.com/line/tm-db/v2" "github.com/stretchr/testify/require" + ostrand "github.com/line/ostracon/libs/rand" + tmdb "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" + "github.com/line/lbm-sdk/v2/store/cachekv" "github.com/line/lbm-sdk/v2/store/dbadapter" "github.com/line/lbm-sdk/v2/store/types" ) func newCacheKVStore() types.CacheKVStore { - mem := dbadapter.Store{DB: dbm.NewMemDB()} + mem := dbadapter.Store{DB: memdb.NewDB()} return cachekv.NewStore(mem) } @@ -22,7 +24,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 +67,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 +75,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 +230,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 +247,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 +266,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 +295,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 +326,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 tmdb.DB, op int, args ...int) { switch op { case opSet: k := args[0] @@ -349,7 +351,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 tmdb.DB, maxKey int) { r := randInt(totalOps) switch r { case opSet: @@ -390,7 +392,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 tmdb.DB, 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 +423,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 tmdb.DB) { // iterate over each and check they match the other itr := st.Iterator(nil, nil) itr2, err := mem.Iterator(nil, nil) // ground truth @@ -445,7 +447,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 tmdb.DB, start, end int) { for i := start; i < end; i++ { st.Set(keyFmt(i), valFmt(i)) err := mem.Set(keyFmt(i), valFmt(i)) @@ -453,7 +455,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 tmdb.DB, 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 167561cde0..f48dfc71bd 100644 --- a/store/cachemulti/store.go +++ b/store/cachemulti/store.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/store/cachekv" "github.com/line/lbm-sdk/v2/store/dbadapter" @@ -58,7 +58,7 @@ func NewFromKVStore( // NewStore creates a new Store object from a mapping of store keys to // CacheWrapper objects. Each CacheWrapper store is a branched store. func NewStore( - db dbm.DB, stores map[types.StoreKey]types.CacheWrapper, keys map[string]types.StoreKey, + db tmdb.DB, stores map[types.StoreKey]types.CacheWrapper, keys map[string]types.StoreKey, traceWriter io.Writer, traceContext types.TraceContext, ) Store { diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index b425350cee..7d110c37db 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,16 +3,16 @@ package dbadapter import ( "io" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/store/cachekv" "github.com/line/lbm-sdk/v2/store/tracekv" "github.com/line/lbm-sdk/v2/store/types" ) -// Wrapper type for dbm.Db with implementation of KVStore +// Wrapper type for tmdb.Db with implementation of KVStore type Store struct { - dbm.DB + tmdb.DB } // Get wraps the underlying DB's Get method panicing on error. @@ -85,5 +85,5 @@ func (dsa Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.Ca return cachekv.NewStore(tracekv.NewStore(dsa, w, tc)) } -// dbm.DB implements KVStore so we can CacheKVStore it. +// tmdb.DB implements KVStore so we can CacheKVStore it. var _ types.KVStore = Store{} diff --git a/store/gaskv/store_test.go b/store/gaskv/store_test.go index dc936adb90..a8838ef1bb 100644 --- a/store/gaskv/store_test.go +++ b/store/gaskv/store_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/store/dbadapter" "github.com/line/lbm-sdk/v2/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()) @@ -39,7 +39,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))) @@ -91,14 +91,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/iavl/store.go b/store/iavl/store.go index b4a3313145..a26bf81356 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -11,7 +11,7 @@ import ( "github.com/line/iavl/v2" abci "github.com/line/ostracon/abci/types" ostcrypto "github.com/line/ostracon/proto/ostracon/crypto" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/store/cachekv" "github.com/line/lbm-sdk/v2/store/tracekv" @@ -42,7 +42,7 @@ type Store struct { // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the // store's version (id) from the provided DB. An error is returned if the version // fails to load, or if called with a positive version on an empty tree. -func LoadStore(db dbm.DB, id types.CommitID, lazyLoading bool) (types.CommitKVStore, error) { +func LoadStore(db tmdb.DB, id types.CommitID, lazyLoading bool) (types.CommitKVStore, error) { return LoadStoreWithInitialVersion(db, id, lazyLoading, 0) } @@ -50,7 +50,7 @@ func LoadStore(db dbm.DB, id types.CommitID, lazyLoading bool) (types.CommitKVSt // to the one given. Internally, it will load the store's version (id) from the // provided DB. An error is returned if the version fails to load, or if called with a positive // version on an empty tree. -func LoadStoreWithInitialVersion(db dbm.DB, id types.CommitID, lazyLoading bool, initialVersion uint64) (types.CommitKVStore, error) { +func LoadStoreWithInitialVersion(db tmdb.DB, id types.CommitID, lazyLoading bool, initialVersion uint64) (types.CommitKVStore, error) { tree, err := iavl.NewMutableTreeWithOpts(db, defaultIAVLCacheSize, &iavl.Options{InitialVersion: initialVersion}) if err != nil { return nil, err diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index 5a898a901e..6b746d6c40 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -7,7 +7,8 @@ import ( "github.com/line/iavl/v2" abci "github.com/line/ostracon/abci/types" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/store/types" @@ -30,7 +31,7 @@ func randBytes(numBytes int) []byte { } // make a tree with data from above and save it -func newAlohaTree(t *testing.T, db dbm.DB) (*iavl.MutableTree, types.CommitID) { +func newAlohaTree(t *testing.T, db tmdb.DB) (*iavl.MutableTree, types.CommitID) { tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(t, err) @@ -51,7 +52,7 @@ func newAlohaTree(t *testing.T, db dbm.DB) (*iavl.MutableTree, types.CommitID) { } func TestLoadStore(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, _ := newAlohaTree(t, db) store := UnsafeNewStore(tree) @@ -107,7 +108,7 @@ func TestLoadStore(t *testing.T) { } func TestGetImmutable(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, cID := newAlohaTree(t, db) store := UnsafeNewStore(tree) @@ -137,7 +138,7 @@ func TestGetImmutable(t *testing.T) { } func TestTestGetImmutableIterator(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, cID := newAlohaTree(t, db) store := UnsafeNewStore(tree) @@ -160,7 +161,7 @@ func TestTestGetImmutableIterator(t *testing.T) { } func TestIAVLStoreGetSetHasDelete(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, _ := newAlohaTree(t, db) iavlStore := UnsafeNewStore(tree) @@ -185,7 +186,7 @@ func TestIAVLStoreGetSetHasDelete(t *testing.T) { } func TestIAVLStoreNoNilSet(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, _ := newAlohaTree(t, db) iavlStore := UnsafeNewStore(tree) @@ -196,7 +197,7 @@ func TestIAVLStoreNoNilSet(t *testing.T) { } func TestIAVLIterator(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, _ := newAlohaTree(t, db) iavlStore := UnsafeNewStore(tree) iter := iavlStore.Iterator([]byte("aloha"), []byte("hellz")) @@ -269,7 +270,7 @@ func TestIAVLIterator(t *testing.T) { } func TestIAVLReverseIterator(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(t, err) @@ -303,7 +304,7 @@ func TestIAVLReverseIterator(t *testing.T) { } func TestIAVLPrefixIterator(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(t, err) @@ -367,7 +368,7 @@ func TestIAVLPrefixIterator(t *testing.T) { } func TestIAVLReversePrefixIterator(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(t, err) @@ -435,7 +436,7 @@ func nextVersion(iavl *Store) { } func TestIAVLNoPrune(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(t, err) @@ -454,7 +455,7 @@ func TestIAVLNoPrune(t *testing.T) { } func TestIAVLStoreQuery(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(t, err) @@ -556,7 +557,7 @@ func TestIAVLStoreQuery(t *testing.T) { } func BenchmarkIAVLIteratorNext(b *testing.B) { - db := dbm.NewMemDB() + db := memdb.NewDB() treeSize := 1000 tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(b, err) @@ -586,12 +587,12 @@ func BenchmarkIAVLIteratorNext(b *testing.B) { func TestSetInitialVersion(t *testing.T) { testCases := []struct { name string - storeFn func(db *dbm.MemDB) *Store + storeFn func(db *memdb.MemDB) *Store expPanic bool }{ { "works with a mutable tree", - func(db *dbm.MemDB) *Store { + func(db *memdb.MemDB) *Store { tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(t, err) store := UnsafeNewStore(tree) @@ -601,7 +602,7 @@ func TestSetInitialVersion(t *testing.T) { }, { "throws error on immutable tree", - func(db *dbm.MemDB) *Store { + func(db *memdb.MemDB) *Store { tree, err := iavl.NewMutableTree(db, cacheSize) require.NoError(t, err) store := UnsafeNewStore(tree) @@ -620,7 +621,7 @@ func TestSetInitialVersion(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() store := tc.storeFn(db) if tc.expPanic { diff --git a/store/iavl/tree_test.go b/store/iavl/tree_test.go index 561b5e0ea9..96d1572e2c 100644 --- a/store/iavl/tree_test.go +++ b/store/iavl/tree_test.go @@ -4,13 +4,13 @@ import ( "testing" "github.com/line/iavl/v2" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" ) func TestImmutableTreePanics(t *testing.T) { t.Parallel() - immTree := iavl.NewImmutableTree(dbm.NewMemDB(), 100) + immTree := iavl.NewImmutableTree(memdb.NewDB(), 100) it := &immutableTree{immTree} require.Panics(t, func() { it.Set([]byte{}, []byte{}) }) require.Panics(t, func() { it.Remove([]byte{}) }) diff --git a/store/mem/store.go b/store/mem/store.go index ce54292e51..7955982a8f 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,7 +3,7 @@ package mem import ( "io" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/store/cachekv" "github.com/line/lbm-sdk/v2/store/dbadapter" @@ -23,10 +23,10 @@ type Store struct { } func NewStore() *Store { - return NewStoreWithDB(dbm.NewMemDB()) + return NewStoreWithDB(memdb.NewDB()) } -func NewStoreWithDB(db *dbm.MemDB) *Store { // nolint: interfacer +func NewStoreWithDB(db *memdb.MemDB) *Store { // nolint: interfacer return &Store{Store: dbadapter.Store{DB: db}} } diff --git a/store/prefix/store_test.go b/store/prefix/store_test.go index 13d4977d49..9bfa522f50 100644 --- a/store/prefix/store_test.go +++ b/store/prefix/store_test.go @@ -4,10 +4,10 @@ import ( "crypto/rand" "testing" - dbm "github.com/line/tm-db/v2" "github.com/stretchr/testify/require" liavl "github.com/line/iavl/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/store/dbadapter" "github.com/line/lbm-sdk/v2/store/gaskv" @@ -87,7 +87,7 @@ func testPrefixStore(t *testing.T, baseStore types.KVStore, prefix []byte) { } func TestIAVLStorePrefix(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() tree, err := liavl.NewMutableTree(db, cacheSize) require.NoError(t, err) iavlStore := iavl.UnsafeNewStore(tree) @@ -97,13 +97,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) @@ -149,7 +149,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 @@ -179,7 +179,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 @@ -207,7 +207,7 @@ func TestPrefixStoreReverseIteratorEdgeCase(t *testing.T) { iter.Close() - db = dbm.NewMemDB() + db = memdb.NewDB() baseStore = dbadapter.Store{DB: db} // underflow in cpDecr @@ -238,7 +238,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")) diff --git a/store/rootmulti/proof_test.go b/store/rootmulti/proof_test.go index 9cc437a13e..70351fc45e 100644 --- a/store/rootmulti/proof_test.go +++ b/store/rootmulti/proof_test.go @@ -4,7 +4,7 @@ import ( "testing" abci "github.com/line/ostracon/abci/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/store/iavl" @@ -13,7 +13,7 @@ import ( func TestVerifyIAVLStoreQueryProof(t *testing.T) { // Create main tree for testing. - db := dbm.NewMemDB() + db := memdb.NewDB() iStore, err := iavl.LoadStore(db, types.CommitID{}, false) store := iStore.(*iavl.Store) require.Nil(t, err) @@ -56,7 +56,7 @@ func TestVerifyIAVLStoreQueryProof(t *testing.T) { func TestVerifyMultiStoreQueryProof(t *testing.T) { // Create main tree for testing. - db := dbm.NewMemDB() + db := memdb.NewDB() store := NewStore(db) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") @@ -111,7 +111,7 @@ func TestVerifyMultiStoreQueryProof(t *testing.T) { func TestVerifyMultiStoreQueryProofAbsence(t *testing.T) { // Create main tree for testing. - db := dbm.NewMemDB() + db := memdb.NewDB() store := NewStore(db) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 4b853de508..76df836dbc 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -14,7 +14,7 @@ import ( gogotypes "github.com/gogo/protobuf/types" iavltree "github.com/line/iavl/v2" abci "github.com/line/ostracon/abci/types" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/pkg/errors" "github.com/line/lbm-sdk/v2/snapshots" @@ -44,7 +44,7 @@ const ( // cacheMultiStore which is used for branching other MultiStores. It implements // the CommitMultiStore interface. type Store struct { - db dbm.DB + db tmdb.DB lastCommitInfo *types.CommitInfo pruningOpts types.PruningOptions storesParams map[types.StoreKey]storeParams @@ -69,7 +69,7 @@ var ( // store will be created with a PruneNothing pruning strategy by default. After // a store is created, KVStores must be mounted and finally LoadLatestVersion or // LoadVersion must be called. -func NewStore(db dbm.DB) *Store { +func NewStore(db tmdb.DB) *Store { return &Store{ db: db, pruningOpts: types.PruneNothing, @@ -103,7 +103,7 @@ func (rs *Store) GetStoreType() types.StoreType { } // MountStoreWithDB implements CommitMultiStore. -func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db dbm.DB) { +func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db tmdb.DB) { if key == nil { panic("MountIAVLStore() key cannot be nil") } @@ -811,13 +811,13 @@ func (rs *Store) Restore( } func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID, params storeParams) (types.CommitKVStore, error) { - var db dbm.DB + var db tmdb.DB if params.db != nil { - db = dbm.NewPrefixDB(params.db, []byte("s/_/")) + db = tmdb.NewPrefixDB(params.db, []byte("s/_/")) } else { prefix := "s/k:" + params.key.Name() + "/" - db = dbm.NewPrefixDB(rs.db, []byte(prefix)) + db = tmdb.NewPrefixDB(rs.db, []byte(prefix)) } switch params.typ { @@ -889,12 +889,12 @@ func (rs *Store) buildCommitInfo(version int64) *types.CommitInfo { type storeParams struct { key types.StoreKey - db dbm.DB + db tmdb.DB typ types.StoreType initialVersion uint64 } -func getLatestVersion(db dbm.DB) int64 { +func getLatestVersion(db tmdb.DB) int64 { bz, err := db.Get([]byte(latestVersionKey)) if err != nil { panic(err) @@ -935,7 +935,7 @@ func commitStores(version int64, storeMap map[types.StoreKey]types.CommitKVStore } // Gets commitInfo from disk. -func getCommitInfo(db dbm.DB, ver int64) (*types.CommitInfo, error) { +func getCommitInfo(db tmdb.DB, ver int64) (*types.CommitInfo, error) { cInfoKey := fmt.Sprintf(commitInfoKeyFmt, ver) bz, err := db.Get([]byte(cInfoKey)) @@ -953,7 +953,7 @@ func getCommitInfo(db dbm.DB, ver int64) (*types.CommitInfo, error) { return cInfo, nil } -func setCommitInfo(batch dbm.Batch, version int64, cInfo *types.CommitInfo) { +func setCommitInfo(batch tmdb.Batch, version int64, cInfo *types.CommitInfo) { bz, err := cInfo.Marshal() if err != nil { panic(err) @@ -963,7 +963,7 @@ func setCommitInfo(batch dbm.Batch, version int64, cInfo *types.CommitInfo) { batch.Set([]byte(cInfoKey), bz) } -func setLatestVersion(batch dbm.Batch, version int64) { +func setLatestVersion(batch tmdb.Batch, version int64) { bz, err := gogotypes.StdInt64Marshal(version) if err != nil { panic(err) @@ -972,7 +972,7 @@ func setLatestVersion(batch dbm.Batch, version int64) { batch.Set([]byte(latestVersionKey), bz) } -func setPruningHeights(batch dbm.Batch, pruneHeights []int64) { +func setPruningHeights(batch tmdb.Batch, pruneHeights []int64) { bz := make([]byte, 0) for _, ph := range pruneHeights { buf := make([]byte, 8) @@ -983,7 +983,7 @@ func setPruningHeights(batch dbm.Batch, pruneHeights []int64) { batch.Set([]byte(pruneHeightsKey), bz) } -func getPruningHeights(db dbm.DB) ([]int64, error) { +func getPruningHeights(db tmdb.DB) ([]int64, error) { bz, err := db.Get([]byte(pruneHeightsKey)) if err != nil { return nil, fmt.Errorf("failed to get pruned heights: %w", err) @@ -1003,7 +1003,7 @@ func getPruningHeights(db dbm.DB) ([]int64, error) { return prunedHeights, nil } -func flushMetadata(db dbm.DB, version int64, cInfo *types.CommitInfo, pruneHeights []int64) { +func flushMetadata(db tmdb.DB, version int64, cInfo *types.CommitInfo, pruneHeights []int64) { batch := db.NewBatch() defer batch.Close() diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index 13fb116fb4..f4d2460949 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -11,11 +11,13 @@ import ( "math/rand" "testing" - abci "github.com/line/ostracon/abci/types" - dbm "github.com/line/tm-db/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + abci "github.com/line/ostracon/abci/types" + tmdb "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" + snapshottypes "github.com/line/lbm-sdk/v2/snapshots/types" "github.com/line/lbm-sdk/v2/store/iavl" sdkmaps "github.com/line/lbm-sdk/v2/store/internal/maps" @@ -24,13 +26,13 @@ import ( ) func TestStoreType(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() store := NewStore(db) store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, db) } func TestGetCommitKVStore(t *testing.T) { - var db dbm.DB = dbm.NewMemDB() + var db tmdb.DB = memdb.NewDB() ms := newMultiStoreWithMounts(db, types.PruneDefault) err := ms.LoadLatestVersion() require.Nil(t, err) @@ -47,7 +49,7 @@ func TestGetCommitKVStore(t *testing.T) { } func TestStoreMount(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() store := NewStore(db) key1 := types.NewKVStoreKey("store1") @@ -63,7 +65,7 @@ func TestStoreMount(t *testing.T) { } func TestCacheMultiStoreWithVersion(t *testing.T) { - var db dbm.DB = dbm.NewMemDB() + var db tmdb.DB = memdb.NewDB() ms := newMultiStoreWithMounts(db, types.PruneNothing) err := ms.LoadLatestVersion() require.Nil(t, err) @@ -100,7 +102,7 @@ func TestCacheMultiStoreWithVersion(t *testing.T) { } func TestHashStableWithEmptyCommit(t *testing.T) { - var db dbm.DB = dbm.NewMemDB() + var db tmdb.DB = memdb.NewDB() ms := newMultiStoreWithMounts(db, types.PruneNothing) err := ms.LoadLatestVersion() require.Nil(t, err) @@ -124,7 +126,7 @@ func TestHashStableWithEmptyCommit(t *testing.T) { } func TestMultistoreCommitLoad(t *testing.T) { - var db dbm.DB = dbm.NewMemDB() + var db tmdb.DB = memdb.NewDB() store := newMultiStoreWithMounts(db, types.PruneNothing) err := store.LoadLatestVersion() require.Nil(t, err) @@ -171,7 +173,7 @@ func TestMultistoreCommitLoad(t *testing.T) { } func TestMultistoreLoadWithUpgrade(t *testing.T) { - var db dbm.DB = dbm.NewMemDB() + var db tmdb.DB = memdb.NewDB() store := newMultiStoreWithMounts(db, types.PruneNothing) err := store.LoadLatestVersion() require.Nil(t, err) @@ -313,7 +315,7 @@ func TestParsePath(t *testing.T) { } func TestMultiStoreRestart(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() pruning := types.PruningOptions{ KeepRecent: 2, KeepEvery: 3, @@ -396,7 +398,7 @@ func TestMultiStoreRestart(t *testing.T) { } func TestMultiStoreQuery(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() multi := newMultiStoreWithMounts(db, types.PruneNothing) err := multi.LoadLatestVersion() require.Nil(t, err) @@ -484,7 +486,7 @@ func TestMultiStore_Pruning(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() ms := newMultiStoreWithMounts(db, tc.po) require.NoError(t, ms.LoadLatestVersion()) @@ -506,7 +508,7 @@ func TestMultiStore_Pruning(t *testing.T) { } func TestMultiStore_PruningRestart(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() ms := newMultiStoreWithMounts(db, types.NewPruningOptions(2, 3, 11)) require.NoError(t, ms.LoadLatestVersion()) @@ -544,7 +546,7 @@ func TestMultistoreSnapshot_Checksum(t *testing.T) { // This checksum test makes sure that the byte stream remains identical. If the test fails // without having changed the data (e.g. because the Protobuf or zlib encoding changes), // snapshottypes.CurrentFormat must be bumped. - store := newMultiStoreWithGeneratedData(dbm.NewMemDB(), 5, 10000) + store := newMultiStoreWithGeneratedData(memdb.NewDB(), 5, 10000) version := uint64(store.LastCommitID().Version) testcases := []struct { @@ -580,7 +582,7 @@ func TestMultistoreSnapshot_Checksum(t *testing.T) { } func TestMultistoreSnapshot_Errors(t *testing.T) { - store := newMultiStoreWithMixedMountsAndBasicData(dbm.NewMemDB()) + store := newMultiStoreWithMixedMountsAndBasicData(memdb.NewDB()) testcases := map[string]struct { height uint64 @@ -605,7 +607,7 @@ func TestMultistoreSnapshot_Errors(t *testing.T) { } func TestMultistoreRestore_Errors(t *testing.T) { - store := newMultiStoreWithMixedMounts(dbm.NewMemDB()) + store := newMultiStoreWithMixedMounts(memdb.NewDB()) testcases := map[string]struct { height uint64 @@ -629,8 +631,8 @@ func TestMultistoreRestore_Errors(t *testing.T) { } func TestMultistoreSnapshotRestore(t *testing.T) { - source := newMultiStoreWithMixedMountsAndBasicData(dbm.NewMemDB()) - target := newMultiStoreWithMixedMounts(dbm.NewMemDB()) + source := newMultiStoreWithMixedMountsAndBasicData(memdb.NewDB()) + target := newMultiStoreWithMixedMounts(memdb.NewDB()) version := uint64(source.LastCommitID().Version) require.EqualValues(t, 3, version) @@ -655,7 +657,7 @@ func TestMultistoreSnapshotRestore(t *testing.T) { } func TestSetInitialVersion(t *testing.T) { - db := dbm.NewMemDB() + db := memdb.NewDB() multi := newMultiStoreWithMounts(db, types.PruneNothing) require.NoError(t, multi.LoadLatestVersion()) @@ -690,13 +692,13 @@ func BenchmarkMultistoreSnapshotRestore1M(b *testing.B) { func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) { b.StopTimer() - source := newMultiStoreWithGeneratedData(dbm.NewMemDB(), stores, storeKeys) + source := newMultiStoreWithGeneratedData(memdb.NewDB(), stores, storeKeys) version := source.LastCommitID().Version require.EqualValues(b, 1, version) b.StartTimer() for i := 0; i < b.N; i++ { - target := NewStore(dbm.NewMemDB()) + target := NewStore(memdb.NewDB()) for key := range source.stores { target.MountStoreWithDB(key, types.StoreTypeIAVL, nil) } @@ -717,13 +719,13 @@ func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) { func benchmarkMultistoreSnapshotRestore(b *testing.B, stores uint8, storeKeys uint64) { b.StopTimer() - source := newMultiStoreWithGeneratedData(dbm.NewMemDB(), stores, storeKeys) + source := newMultiStoreWithGeneratedData(memdb.NewDB(), stores, storeKeys) version := uint64(source.LastCommitID().Version) require.EqualValues(b, 1, version) b.StartTimer() for i := 0; i < b.N; i++ { - target := NewStore(dbm.NewMemDB()) + target := NewStore(memdb.NewDB()) for key := range source.stores { target.MountStoreWithDB(key, types.StoreTypeIAVL, nil) } @@ -742,7 +744,7 @@ func benchmarkMultistoreSnapshotRestore(b *testing.B, stores uint8, storeKeys ui //----------------------------------------------------------------------- // utils -func newMultiStoreWithMounts(db dbm.DB, pruningOpts types.PruningOptions) *Store { +func newMultiStoreWithMounts(db tmdb.DB, pruningOpts types.PruningOptions) *Store { store := NewStore(db) store.pruningOpts = pruningOpts @@ -753,7 +755,7 @@ func newMultiStoreWithMounts(db dbm.DB, pruningOpts types.PruningOptions) *Store return store } -func newMultiStoreWithMixedMounts(db dbm.DB) *Store { +func newMultiStoreWithMixedMounts(db tmdb.DB) *Store { store := NewStore(db) store.MountStoreWithDB(types.NewKVStoreKey("iavl1"), types.StoreTypeIAVL, nil) store.MountStoreWithDB(types.NewKVStoreKey("iavl2"), types.StoreTypeIAVL, nil) @@ -764,7 +766,7 @@ func newMultiStoreWithMixedMounts(db dbm.DB) *Store { return store } -func newMultiStoreWithMixedMountsAndBasicData(db dbm.DB) *Store { +func newMultiStoreWithMixedMountsAndBasicData(db tmdb.DB) *Store { store := newMultiStoreWithMixedMounts(db) store1 := store.getStoreByName("iavl1").(types.CommitKVStore) store2 := store.getStoreByName("iavl2").(types.CommitKVStore) @@ -790,7 +792,7 @@ func newMultiStoreWithMixedMountsAndBasicData(db dbm.DB) *Store { return store } -func newMultiStoreWithGeneratedData(db dbm.DB, stores uint8, storeKeys uint64) *Store { +func newMultiStoreWithGeneratedData(db tmdb.DB, stores uint8, storeKeys uint64) *Store { multiStore := NewStore(db) r := rand.New(rand.NewSource(49872768940)) // Fixed seed for deterministic tests @@ -822,7 +824,7 @@ func newMultiStoreWithGeneratedData(db dbm.DB, stores uint8, storeKeys uint64) * return multiStore } -func newMultiStoreWithModifiedMounts(db dbm.DB, pruningOpts types.PruningOptions) (*Store, *types.StoreUpgrades) { +func newMultiStoreWithModifiedMounts(db tmdb.DB, pruningOpts types.PruningOptions) (*Store, *types.StoreUpgrades) { store := NewStore(db) store.pruningOpts = pruningOpts diff --git a/store/store.go b/store/store.go index 7b31e436c5..e459da6a47 100644 --- a/store/store.go +++ b/store/store.go @@ -1,14 +1,14 @@ package store import ( - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/store/cache" "github.com/line/lbm-sdk/v2/store/rootmulti" "github.com/line/lbm-sdk/v2/store/types" ) -func NewCommitMultiStore(db dbm.DB) types.CommitMultiStore { +func NewCommitMultiStore(db tmdb.DB) types.CommitMultiStore { return rootmulti.NewStore(db) } diff --git a/store/tracekv/store_test.go b/store/tracekv/store_test.go index f192e6e727..1138dfe4cc 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/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/store/dbadapter" "github.com/line/lbm-sdk/v2/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 508cfd7e93..f8583fc1c5 100644 --- a/store/transient/store.go +++ b/store/transient/store.go @@ -1,7 +1,7 @@ package transient import ( - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/store/dbadapter" "github.com/line/lbm-sdk/v2/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 bf18d6dddc..e38dfd5e22 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/line/tm-db/v2" "github.com/stretchr/testify/require" + "github.com/line/tm-db/v2/memdb" + "github.com/line/lbm-sdk/v2/store/iavl" "github.com/line/lbm-sdk/v2/store/types" ) func newMemTestKVStore(t *testing.T) types.KVStore { - db := dbm.NewMemDB() + db := 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 5a162eee65..cd8dfe2eae 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -6,7 +6,7 @@ import ( abci "github.com/line/ostracon/abci/types" oststrings "github.com/line/ostracon/libs/strings" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" snapshottypes "github.com/line/lbm-sdk/v2/snapshots/types" "github.com/line/lbm-sdk/v2/types/kv" @@ -146,7 +146,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 @@ -219,7 +219,7 @@ type KVStore interface { } // Iterator is an alias db's Iterator for convenience. -type Iterator = dbm.Iterator +type Iterator = tmdb.Iterator // CacheKVStore branches a KVStore and provides read cache functionality. // After calling .Write() on the CacheKVStore, all previously created diff --git a/store/types/utils_test.go b/store/types/utils_test.go index 1fab2c903b..206005d187 100644 --- a/store/types/utils_test.go +++ b/store/types/utils_test.go @@ -4,15 +4,16 @@ import ( "bytes" "testing" - dbm "github.com/line/tm-db/v2" "github.com/stretchr/testify/require" + "github.com/line/tm-db/v2/memdb" + "github.com/line/lbm-sdk/v2/store/rootmulti" "github.com/line/lbm-sdk/v2/store/types" ) func initTestStores(t *testing.T) (types.KVStore, types.KVStore) { - db := dbm.NewMemDB() + db := memdb.NewDB() ms := rootmulti.NewStore(db) key1 := types.NewKVStoreKey("store1") diff --git a/tests/mocks/tendermint_tm_db_DB.go b/tests/mocks/tendermint_tm_db_DB.go index fab3afd2d6..a08e7a5e65 100644 --- a/tests/mocks/tendermint_tm_db_DB.go +++ b/tests/mocks/tendermint_tm_db_DB.go @@ -6,7 +6,7 @@ package mocks import ( gomock "github.com/golang/mock/gomock" - db "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" reflect "reflect" ) @@ -106,10 +106,10 @@ func (mr *MockDBMockRecorder) Has(arg0 interface{}) *gomock.Call { } // Iterator mocks base method -func (m *MockDB) Iterator(arg0, arg1 []byte) (db.Iterator, error) { +func (m *MockDB) Iterator(arg0, arg1 []byte) (tmdb.Iterator, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Iterator", arg0, arg1) - ret0, _ := ret[0].(db.Iterator) + ret0, _ := ret[0].(tmdb.Iterator) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -121,10 +121,10 @@ func (mr *MockDBMockRecorder) Iterator(arg0, arg1 interface{}) *gomock.Call { } // NewBatch mocks base method -func (m *MockDB) NewBatch() db.Batch { +func (m *MockDB) NewBatch() tmdb.Batch { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NewBatch") - ret0, _ := ret[0].(db.Batch) + ret0, _ := ret[0].(tmdb.Batch) return ret0 } @@ -149,10 +149,10 @@ func (mr *MockDBMockRecorder) Print() *gomock.Call { } // ReverseIterator mocks base method -func (m *MockDB) ReverseIterator(arg0, arg1 []byte) (db.Iterator, error) { +func (m *MockDB) ReverseIterator(arg0, arg1 []byte) (tmdb.Iterator, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReverseIterator", arg0, arg1) - ret0, _ := ret[0].(db.Iterator) + ret0, _ := ret[0].(tmdb.Iterator) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/testutil/network/network.go b/testutil/network/network.go index 1924b8e50c..0e6d30655d 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -20,7 +20,7 @@ import ( ostrand "github.com/line/ostracon/libs/rand" "github.com/line/ostracon/node" ostclient "github.com/line/ostracon/rpc/client" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "google.golang.org/grpc" @@ -57,7 +57,7 @@ type AppConstructor = func(val Validator) servertypes.Application func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor { return func(val Validator) servertypes.Application { return simapp.NewSimApp( - val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0, + val.Ctx.Logger, memdb.NewDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0, encodingCfg, simapp.EmptyAppOptions{}, baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), diff --git a/types/context_test.go b/types/context_test.go index 8c2e5b08c8..f223e2a6d8 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -9,7 +9,7 @@ import ( abci "github.com/line/ostracon/abci/types" "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/suite" "github.com/line/lbm-sdk/v2/crypto/keys/secp256k1" @@ -27,7 +27,7 @@ func TestContextTestSuite(t *testing.T) { } func (s *contextTestSuite) defaultContext(key types.StoreKey) types.Context { - db := dbm.NewMemDB() + db := memdb.NewDB() cms := store.NewCommitMultiStore(db) cms.MountStoreWithDB(key, types.StoreTypeIAVL, db) s.Require().NoError(cms.LoadLatestVersion()) diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index 944692ba67..a29183eb6f 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/suite" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/baseapp" "github.com/line/lbm-sdk/v2/codec" @@ -216,7 +216,7 @@ func setupTest() (*simapp.SimApp, sdk.Context, codec.Marshaler) { ctx := app.BaseApp.NewContext(false, ostproto.Header{Height: 1}) appCodec := app.AppCodec() - db := dbm.NewMemDB() + db := memdb.NewDB() ms := store.NewCommitMultiStore(db) ms.LoadLatestVersion() diff --git a/types/store_test.go b/types/store_test.go index f4334c81ec..970ba64a77 100644 --- a/types/store_test.go +++ b/types/store_test.go @@ -3,9 +3,10 @@ package types_test import ( "testing" - dbm "github.com/line/tm-db/v2" "github.com/stretchr/testify/suite" + "github.com/line/tm-db/v2/memdb" + "github.com/line/lbm-sdk/v2/store/rootmulti" "github.com/line/lbm-sdk/v2/store/types" sdk "github.com/line/lbm-sdk/v2/types" @@ -112,7 +113,7 @@ func (s *storeTestSuite) TestDiffKVStores() { } func (s *storeTestSuite) initTestStores() (types.KVStore, types.KVStore) { - db := dbm.NewMemDB() + db := memdb.NewDB() ms := rootmulti.NewStore(db) key1 := types.NewKVStoreKey("store1") diff --git a/types/utils.go b/types/utils.go index 8fcae9ff74..7dfb27b3f2 100644 --- a/types/utils.go +++ b/types/utils.go @@ -6,18 +6,19 @@ import ( "fmt" "time" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/metadb" ) var ( // This is set at compile time. Could be cleveldb, defaults is goleveldb. DBBackend = "" - backend = dbm.GoLevelDBBackend + backend = metadb.GoLevelDBBackend ) func init() { if len(DBBackend) != 0 { - backend = dbm.BackendType(DBBackend) + backend = metadb.BackendType(DBBackend) } } @@ -85,14 +86,14 @@ func ParseTimeBytes(bz []byte) (time.Time, error) { } // NewLevelDB instantiate a new LevelDB instance according to DBBackend. -func NewLevelDB(name, dir string) (db dbm.DB, err error) { +func NewLevelDB(name, dir string) (db tmdb.DB, err error) { defer func() { if r := recover(); r != nil { err = fmt.Errorf("couldn't create db: %v", r) } }() - return dbm.NewDB(name, backend, dir) + return metadb.NewDB(name, backend, dir) } // copy bytes diff --git a/x/crisis/handler_test.go b/x/crisis/handler_test.go index c1aa455ab8..28bc256536 100644 --- a/x/crisis/handler_test.go +++ b/x/crisis/handler_test.go @@ -6,7 +6,7 @@ import ( "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/simapp" @@ -26,7 +26,7 @@ var ( ) func createTestApp() (*simapp.SimApp, sdk.Context, []sdk.AccAddress) { - db := dbm.NewMemDB() + db := memdb.NewDB() app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 1, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{}) ctx := app.NewContext(true, ostproto.Header{}) diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index 09a16dda11..722f53e202 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -7,7 +7,7 @@ import ( abci "github.com/line/ostracon/abci/types" "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/simapp" @@ -67,7 +67,7 @@ func TestImportExportQueues(t *testing.T) { panic(err) } - db := dbm.NewMemDB() + db := memdb.NewDB() app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{}) app2.InitChain( diff --git a/x/ibc/core/03-connection/types/msgs_test.go b/x/ibc/core/03-connection/types/msgs_test.go index a2b4837acf..4007740103 100644 --- a/x/ibc/core/03-connection/types/msgs_test.go +++ b/x/ibc/core/03-connection/types/msgs_test.go @@ -7,8 +7,7 @@ import ( "github.com/stretchr/testify/suite" - abci "github.com/line/ostracon/abci/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/simapp" "github.com/line/lbm-sdk/v2/store/iavl" @@ -20,6 +19,7 @@ import ( commitmenttypes "github.com/line/lbm-sdk/v2/x/ibc/core/23-commitment/types" ibctmtypes "github.com/line/lbm-sdk/v2/x/ibc/light-clients/07-tendermint/types" ibctesting "github.com/line/lbm-sdk/v2/x/ibc/testing" + abci "github.com/line/ostracon/abci/types" ) var ( @@ -45,7 +45,7 @@ func (suite *MsgTestSuite) SetupTest() { suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1)) app := simapp.Setup(false) - db := dbm.NewMemDB() + db := memdb.NewDB() store := rootmulti.NewStore(db) storeKey := storetypes.NewKVStoreKey("iavlStoreKey") diff --git a/x/ibc/core/04-channel/keeper/keeper.go b/x/ibc/core/04-channel/keeper/keeper.go index 75d069db40..96ec1b945b 100644 --- a/x/ibc/core/04-channel/keeper/keeper.go +++ b/x/ibc/core/04-channel/keeper/keeper.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/line/ostracon/libs/log" - db "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" "github.com/line/lbm-sdk/v2/codec" sdk "github.com/line/lbm-sdk/v2/types" @@ -222,7 +222,7 @@ func (k Keeper) HasPacketAcknowledgement(ctx sdk.Context, portID, channelID stri // IteratePacketSequence provides an iterator over all send, receive or ack sequences. // For each sequence, cb will be called. If the cb returns true, the iterator // will close and stop. -func (k Keeper) IteratePacketSequence(ctx sdk.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64) bool) { +func (k Keeper) IteratePacketSequence(ctx sdk.Context, iterator tmdb.Iterator, cb func(portID, channelID string, sequence uint64) bool) { defer iterator.Close() for ; iterator.Valid(); iterator.Next() { portID, channelID, err := host.ParseChannelPath(string(iterator.Key())) @@ -412,7 +412,7 @@ func (k Keeper) LookupModuleByChannel(ctx sdk.Context, portID, channelID string) } // common functionality for IteratePacketCommitment and IteratePacketAcknowledgement -func (k Keeper) iterateHashes(_ sdk.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { +func (k Keeper) iterateHashes(_ sdk.Context, iterator tmdb.Iterator, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/ibc/core/04-channel/types/msgs_test.go b/x/ibc/core/04-channel/types/msgs_test.go index 26d685083b..90607e366b 100644 --- a/x/ibc/core/04-channel/types/msgs_test.go +++ b/x/ibc/core/04-channel/types/msgs_test.go @@ -6,8 +6,7 @@ import ( "github.com/stretchr/testify/suite" - abci "github.com/line/ostracon/abci/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/simapp" "github.com/line/lbm-sdk/v2/store/iavl" @@ -18,6 +17,7 @@ import ( "github.com/line/lbm-sdk/v2/x/ibc/core/04-channel/types" commitmenttypes "github.com/line/lbm-sdk/v2/x/ibc/core/23-commitment/types" "github.com/line/lbm-sdk/v2/x/ibc/core/exported" + abci "github.com/line/ostracon/abci/types" ) const ( @@ -76,7 +76,7 @@ type TypesTestSuite struct { func (suite *TypesTestSuite) SetupTest() { app := simapp.Setup(false) - db := dbm.NewMemDB() + db := memdb.NewDB() store := rootmulti.NewStore(db) storeKey := storetypes.NewKVStoreKey("iavlStoreKey") diff --git a/x/ibc/core/23-commitment/types/commitment_test.go b/x/ibc/core/23-commitment/types/commitment_test.go index f4611311f5..fc84e7c0fa 100644 --- a/x/ibc/core/23-commitment/types/commitment_test.go +++ b/x/ibc/core/23-commitment/types/commitment_test.go @@ -5,11 +5,11 @@ import ( "github.com/stretchr/testify/suite" + "github.com/line/tm-db/v2/memdb" + "github.com/line/lbm-sdk/v2/store/iavl" "github.com/line/lbm-sdk/v2/store/rootmulti" storetypes "github.com/line/lbm-sdk/v2/store/types" - - dbm "github.com/line/tm-db/v2" ) type MerkleTestSuite struct { @@ -21,7 +21,7 @@ type MerkleTestSuite struct { } func (suite *MerkleTestSuite) SetupTest() { - db := dbm.NewMemDB() + db := memdb.NewDB() suite.store = rootmulti.NewStore(db) suite.storeKey = storetypes.NewKVStoreKey("iavlStoreKey") diff --git a/x/params/keeper/common_test.go b/x/params/keeper/common_test.go index d34dffdf19..cb45cd6269 100644 --- a/x/params/keeper/common_test.go +++ b/x/params/keeper/common_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/line/lbm-sdk/v2/simapp" @@ -39,7 +39,7 @@ func createTestCodec() *codec.LegacyAmino { } func defaultContext(key sdk.StoreKey, tkey sdk.StoreKey) sdk.Context { - db := dbm.NewMemDB() + db := memdb.NewDB() cms := store.NewCommitMultiStore(db) cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) cms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) diff --git a/x/params/proposal_handler_test.go b/x/params/proposal_handler_test.go index 16caefbfab..a84c9b8dcb 100644 --- a/x/params/proposal_handler_test.go +++ b/x/params/proposal_handler_test.go @@ -7,7 +7,7 @@ import ( "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/codec" @@ -64,7 +64,7 @@ func newTestInput(t *testing.T) testInput { cdc := codec.NewLegacyAmino() proposal.RegisterLegacyAminoCodec(cdc) - db := dbm.NewMemDB() + db := memdb.NewDB() cms := store.NewCommitMultiStore(db) keyParams := sdk.NewKVStoreKey("params") diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index 988c240cec..018c2d518a 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -7,7 +7,7 @@ import ( "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/suite" "github.com/line/lbm-sdk/v2/codec" @@ -27,7 +27,7 @@ type SubspaceTestSuite struct { } func (suite *SubspaceTestSuite) SetupTest() { - db := dbm.NewMemDB() + db := memdb.NewDB() ms := store.NewCommitMultiStore(db) ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 17f9c7cc54..8095dd4aee 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -12,7 +12,7 @@ import ( abci "github.com/line/ostracon/abci/types" "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/simapp" @@ -39,7 +39,7 @@ type TestSuite struct { var s TestSuite func setupTest(height int64, skip map[int64]bool) TestSuite { - db := dbm.NewMemDB() + db := memdb.NewDB() app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, skip, simapp.DefaultNodeHome, 0, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{}) genesisState := simapp.NewDefaultGenesisState(app.AppCodec()) stateBytes, err := json.MarshalIndent(genesisState, "", " ") diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index b81272e5ff..325e27d82d 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -10,7 +10,8 @@ import ( abci "github.com/line/ostracon/abci/types" "github.com/line/ostracon/libs/log" ostproto "github.com/line/ostracon/proto/ostracon/types" - dbm "github.com/line/tm-db/v2" + tmdb "github.com/line/tm-db/v2" + "github.com/line/tm-db/v2/memdb" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/baseapp" @@ -29,7 +30,7 @@ func defaultLogger() log.Logger { return log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app") } -func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { +func initStore(t *testing.T, db tmdb.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) @@ -46,7 +47,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { require.Equal(t, int64(1), commitID.Version) } -func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { +func checkStore(t *testing.T, db tmdb.DB, ver int64, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) @@ -112,7 +113,7 @@ func TestSetLoader(t *testing.T) { tc := tc t.Run(name, func(t *testing.T) { // prepare a db with some data - db := dbm.NewMemDB() + db := memdb.NewDB() initStore(t, db, tc.origStoreKey, k, v)