diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index ba5ec2696e72..0c8e45eb9398 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -147,7 +147,7 @@ func NewBaseApp( logger: logger, name: name, db: db, - cms: store.NewCommitMultiStore(db), + cms: store.NewCommitMultiStore(db, logger), storeLoader: DefaultStoreLoader, router: NewRouter(), queryRouter: NewQueryRouter(), diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index ff307b105ff0..5db905cad9b3 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -258,7 +258,7 @@ func useDefaultLoader(app *BaseApp) { } func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { - rs := rootmulti.NewStore(db) + rs := rootmulti.NewStore(db, log.NewNopLogger()) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) @@ -275,7 +275,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { } func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { - rs := rootmulti.NewStore(db) + rs := rootmulti.NewStore(db, log.NewNopLogger()) rs.SetPruning(store.PruneDefault) key := sdk.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) diff --git a/go.mod b/go.mod index b40e7f4e5245..fa650395c514 100644 --- a/go.mod +++ b/go.mod @@ -70,4 +70,4 @@ replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 replace github.com/tendermint/tm-db => github.com/osmosis-labs/tm-db v0.6.5-0.20210911033928-ba9154613417 -replace github.com/cosmos/iavl => github.com/osmosis-labs/iavl v0.17.3-fast.1.0.20220207021926-5f889f6b44d5 +replace github.com/cosmos/iavl => github.com/osmosis-labs/iavl v0.17.3-osmo-v1 diff --git a/go.sum b/go.sum index dfc1be99045d..5a5b6ebf0b3b 100644 --- a/go.sum +++ b/go.sum @@ -618,8 +618,10 @@ github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4 github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs= github.com/osmosis-labs/iavl v0.17.3-fast.1.0.20220207021926-5f889f6b44d5 h1:Yxj5CB5vnE2BSWbfWlDFzmyccDQmaFVGTms5RlD2Rgo= github.com/osmosis-labs/iavl v0.17.3-fast.1.0.20220207021926-5f889f6b44d5/go.mod h1:lJEOIlsd3sVO0JDyXWIXa9/Ur5FBscP26zJx0KxHjto= -github.com/osmosis-labs/iavl v0.17.3-fast.2 h1:8jCq1xaZq5KiQzo86fOHF0TkiAEdxUKe5MJ/Xmwz4b8= -github.com/osmosis-labs/iavl v0.17.3-fast.2/go.mod h1:lJEOIlsd3sVO0JDyXWIXa9/Ur5FBscP26zJx0KxHjto= +github.com/osmosis-labs/iavl v0.17.3-fast.4 h1:P6872Aq9Q+X2nCQFMpUb+VCP0rNYZPW5OKa4tTnzR+A= +github.com/osmosis-labs/iavl v0.17.3-fast.4/go.mod h1:lJEOIlsd3sVO0JDyXWIXa9/Ur5FBscP26zJx0KxHjto= +github.com/osmosis-labs/iavl v0.17.3-osmo-v1 h1:orHUut98Miu2+bsFiNZJ29B3ogrbiBbQpti94L2w3Z4= +github.com/osmosis-labs/iavl v0.17.3-osmo-v1/go.mod h1:lJEOIlsd3sVO0JDyXWIXa9/Ur5FBscP26zJx0KxHjto= github.com/osmosis-labs/tm-db v0.6.5-0.20210911033928-ba9154613417 h1:otchJDd2SjFWfs7Tse3ULblGcVWqMJ50BE02XCaqXOo= github.com/osmosis-labs/tm-db v0.6.5-0.20210911033928-ba9154613417/go.mod h1:dptYhIpJ2M5kUuenLr+Yyf3zQOv1SgBZcl8/BmWlMBw= github.com/otiai10/copy v1.6.0 h1:IinKAryFFuPONZ7cm6T6E2QX/vcJwSnlaA5lfoaXIiQ= diff --git a/store/iavl/store.go b/store/iavl/store.go index b68238c24dd2..ced9894414ae 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -3,6 +3,7 @@ package iavl import ( "errors" "fmt" + "github.com/tendermint/tendermint/libs/log" "io" "time" @@ -41,20 +42,29 @@ 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) { - return LoadStoreWithInitialVersion(db, id, lazyLoading, 0) +func LoadStore(db dbm.DB, logger log.Logger, id types.CommitID, lazyLoading bool) (types.CommitKVStore, error) { + return LoadStoreWithInitialVersion(db, logger, id, lazyLoading, 0) } // LoadStoreWithInitialVersion returns an IAVL Store as a CommitKVStore setting its initialVersion // 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 dbm.DB, logger log.Logger, 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 } + if tree.IsUpgradeable() && logger != nil { + logger.Info( + "Upgrading IAVL storage for faster queries + execution on live state. This may take a while", + "version", initialVersion, + "commit", fmt.Sprintf("%X", id), + "is_lazy", lazyLoading, + ) + } + if lazyLoading { _, err = tree.LazyLoadVersion(id.Version) } else { @@ -65,6 +75,10 @@ func LoadStoreWithInitialVersion(db dbm.DB, id types.CommitID, lazyLoading bool, return nil, err } + if logger != nil { + logger.Debug("Finished loading IAVL tree") + } + return &Store{ tree: tree, }, nil diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index 26cf27db8bf0..3f635a707129 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -3,6 +3,7 @@ package iavl import ( crand "crypto/rand" "fmt" + "github.com/tendermint/tendermint/libs/log" "testing" "github.com/cosmos/cosmos-sdk/store/cachekv" @@ -93,17 +94,17 @@ func TestLoadStore(t *testing.T) { require.Equal(t, string(hcStore.Get([]byte("hello"))), "ciao") // Querying a new store at some previous non-pruned height H - newHStore, err := LoadStore(db, cIDH, false) + newHStore, err := LoadStore(db, log.NewNopLogger(), cIDH, false) require.NoError(t, err) require.Equal(t, string(newHStore.Get([]byte("hello"))), "hallo") // Querying a new store at some previous pruned height Hp - newHpStore, err := LoadStore(db, cIDHp, false) + newHpStore, err := LoadStore(db, log.NewNopLogger(), cIDHp, false) require.NoError(t, err) require.Equal(t, string(newHpStore.Get([]byte("hello"))), "hola") // Querying a new store at current height H - newHcStore, err := LoadStore(db, cIDHc, false) + newHcStore, err := LoadStore(db, log.NewNopLogger(), cIDHc, false) require.NoError(t, err) require.Equal(t, string(newHcStore.Get([]byte("hello"))), "ciao") } diff --git a/store/rootmulti/proof_test.go b/store/rootmulti/proof_test.go index f0bd29063ad1..2c301a3b2ac9 100644 --- a/store/rootmulti/proof_test.go +++ b/store/rootmulti/proof_test.go @@ -1,6 +1,7 @@ package rootmulti import ( + "github.com/tendermint/tendermint/libs/log" "testing" "github.com/stretchr/testify/require" @@ -14,7 +15,7 @@ import ( func TestVerifyIAVLStoreQueryProof(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - iStore, err := iavl.LoadStore(db, types.CommitID{}, false) + iStore, err := iavl.LoadStore(db, nil, types.CommitID{}, false) store := iStore.(*iavl.Store) require.Nil(t, err) store.Set([]byte("MYKEY"), []byte("MYVALUE")) @@ -57,7 +58,7 @@ func TestVerifyIAVLStoreQueryProof(t *testing.T) { func TestVerifyMultiStoreQueryProof(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - store := NewStore(db) + store := NewStore(db, nil) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil) @@ -112,7 +113,7 @@ func TestVerifyMultiStoreQueryProof(t *testing.T) { func TestVerifyMultiStoreQueryProofAbsence(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - store := NewStore(db) + store := NewStore(db, log.NewNopLogger()) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 07dd864de1e3..3a8e2592f19e 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -5,6 +5,7 @@ import ( "compress/zlib" "encoding/binary" "fmt" + "github.com/tendermint/tendermint/libs/log" "io" "math" "sort" @@ -46,6 +47,7 @@ const ( // the CommitMultiStore interface. type Store struct { db dbm.DB + logger log.Logger lastCommitInfo *types.CommitInfo pruningOpts types.PruningOptions storesParams map[types.StoreKey]storeParams @@ -72,9 +74,10 @@ 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 dbm.DB, logger log.Logger) *Store { return &Store{ db: db, + logger: logger, pruningOpts: types.PruneNothing, storesParams: make(map[types.StoreKey]storeParams), stores: make(map[types.StoreKey]types.CommitKVStore), @@ -876,9 +879,9 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID var err error if params.initialVersion == 0 { - store, err = iavl.LoadStore(db, id, rs.lazyLoading) + store, err = iavl.LoadStore(db, rs.logger, id, rs.lazyLoading) } else { - store, err = iavl.LoadStoreWithInitialVersion(db, id, rs.lazyLoading, params.initialVersion) + store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, id, rs.lazyLoading, params.initialVersion) } if err != nil { diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index cf7653b076cb..254efdfa1614 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "errors" "fmt" + "github.com/tendermint/tendermint/libs/log" "io" "io/ioutil" "math/rand" @@ -30,7 +31,7 @@ import ( func TestStoreType(t *testing.T) { db := dbm.NewMemDB() - store := NewStore(db) + store := NewStore(db, log.NewNopLogger()) store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, db) } @@ -53,7 +54,7 @@ func TestGetCommitKVStore(t *testing.T) { func TestStoreMount(t *testing.T) { db := dbm.NewMemDB() - store := NewStore(db) + store := NewStore(db, log.NewNopLogger()) key1 := types.NewKVStoreKey("store1") key2 := types.NewKVStoreKey("store2") @@ -831,7 +832,7 @@ func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) { b.StartTimer() for i := 0; i < b.N; i++ { - target := NewStore(dbm.NewMemDB()) + target := NewStore(dbm.NewMemDB(), log.NewNopLogger()) for key := range source.stores { target.MountStoreWithDB(key, types.StoreTypeIAVL, nil) } @@ -861,7 +862,7 @@ func benchmarkMultistoreSnapshotRestore(b *testing.B, stores uint8, storeKeys ui b.StartTimer() for i := 0; i < b.N; i++ { - target := NewStore(dbm.NewMemDB()) + target := NewStore(dbm.NewMemDB(), log.NewNopLogger()) for key := range source.stores { target.MountStoreWithDB(key, types.StoreTypeIAVL, nil) } @@ -887,7 +888,7 @@ var ( ) func newMultiStoreWithMounts(db dbm.DB, pruningOpts types.PruningOptions) *Store { - store := NewStore(db) + store := NewStore(db, log.NewNopLogger()) store.pruningOpts = pruningOpts store.MountStoreWithDB(testStoreKey1, types.StoreTypeIAVL, nil) @@ -898,7 +899,7 @@ func newMultiStoreWithMounts(db dbm.DB, pruningOpts types.PruningOptions) *Store } func newMultiStoreWithMixedMounts(db dbm.DB) *Store { - store := NewStore(db) + store := NewStore(db, log.NewNopLogger()) store.MountStoreWithDB(types.NewKVStoreKey("iavl1"), types.StoreTypeIAVL, nil) store.MountStoreWithDB(types.NewKVStoreKey("iavl2"), types.StoreTypeIAVL, nil) store.MountStoreWithDB(types.NewKVStoreKey("iavl3"), types.StoreTypeIAVL, nil) @@ -935,7 +936,7 @@ func newMultiStoreWithMixedMountsAndBasicData(db dbm.DB) *Store { } func newMultiStoreWithGeneratedData(db dbm.DB, stores uint8, storeKeys uint64) *Store { - multiStore := NewStore(db) + multiStore := NewStore(db, log.NewNopLogger()) r := rand.New(rand.NewSource(49872768940)) // Fixed seed for deterministic tests keys := []*types.KVStoreKey{} @@ -967,7 +968,7 @@ func newMultiStoreWithGeneratedData(db dbm.DB, stores uint8, storeKeys uint64) * } func newMultiStoreWithModifiedMounts(db dbm.DB, pruningOpts types.PruningOptions) (*Store, *types.StoreUpgrades) { - store := NewStore(db) + store := NewStore(db, log.NewNopLogger()) store.pruningOpts = pruningOpts store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil) diff --git a/store/store.go b/store/store.go index 2c068c413f47..a367e4ee3dfc 100644 --- a/store/store.go +++ b/store/store.go @@ -1,6 +1,7 @@ package store import ( + "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cache" @@ -8,8 +9,8 @@ import ( "github.com/cosmos/cosmos-sdk/store/types" ) -func NewCommitMultiStore(db dbm.DB) types.CommitMultiStore { - return rootmulti.NewStore(db) +func NewCommitMultiStore(db dbm.DB, logger log.Logger) types.CommitMultiStore { + return rootmulti.NewStore(db, logger) } func NewCommitKVStoreCacheManager() types.MultiStorePersistentCache { diff --git a/store/types/iterator_test.go b/store/types/iterator_test.go index 3086917b605b..942983683c9e 100644 --- a/store/types/iterator_test.go +++ b/store/types/iterator_test.go @@ -1,6 +1,7 @@ package types_test import ( + "github.com/tendermint/tendermint/libs/log" "testing" "github.com/stretchr/testify/require" @@ -12,7 +13,7 @@ import ( func newMemTestKVStore(t *testing.T) types.KVStore { db := dbm.NewMemDB() - store, err := iavl.LoadStore(db, types.CommitID{}, false) + store, err := iavl.LoadStore(db, log.NewNopLogger(), types.CommitID{}, false) require.NoError(t, err) return store } diff --git a/store/types/utils_test.go b/store/types/utils_test.go index 32064d7e1821..391b42b33023 100644 --- a/store/types/utils_test.go +++ b/store/types/utils_test.go @@ -2,6 +2,7 @@ package types_test import ( "bytes" + "github.com/tendermint/tendermint/libs/log" "testing" "github.com/stretchr/testify/require" @@ -13,7 +14,7 @@ import ( func initTestStores(t *testing.T) (types.KVStore, types.KVStore) { db := dbm.NewMemDB() - ms := rootmulti.NewStore(db) + ms := rootmulti.NewStore(db, log.NewNopLogger()) key1 := types.NewKVStoreKey("store1") key2 := types.NewKVStoreKey("store2") diff --git a/testutil/context.go b/testutil/context.go index 2fb9865a2696..bf1ef78a5471 100644 --- a/testutil/context.go +++ b/testutil/context.go @@ -12,7 +12,7 @@ import ( // DefaultContext creates a sdk.Context with a fresh MemDB that can be used in tests. func DefaultContext(key sdk.StoreKey, tkey sdk.StoreKey) sdk.Context { db := dbm.NewMemDB() - cms := store.NewCommitMultiStore(db) + cms := store.NewCommitMultiStore(db, log.NewNopLogger()) cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) cms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) err := cms.LoadLatestVersion() diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index da07a5e1b093..529200515d70 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -3,6 +3,7 @@ package query_test import ( gocontext "context" "fmt" + "github.com/tendermint/tendermint/libs/log" "testing" "github.com/stretchr/testify/suite" @@ -340,7 +341,7 @@ func setupTest() (*simapp.SimApp, sdk.Context, codec.Codec) { appCodec := app.AppCodec() db := dbm.NewMemDB() - ms := store.NewCommitMultiStore(db) + ms := store.NewCommitMultiStore(db, log.NewNopLogger()) ms.LoadLatestVersion() diff --git a/types/store_test.go b/types/store_test.go index 9c3ef2f79dd6..645d4eb6917b 100644 --- a/types/store_test.go +++ b/types/store_test.go @@ -1,6 +1,7 @@ package types_test import ( + "github.com/tendermint/tendermint/libs/log" "testing" "github.com/stretchr/testify/suite" @@ -108,7 +109,7 @@ func (s *storeTestSuite) TestDiffKVStores() { func (s *storeTestSuite) initTestStores() (types.KVStore, types.KVStore) { db := dbm.NewMemDB() - ms := rootmulti.NewStore(db) + ms := rootmulti.NewStore(db, log.NewNopLogger()) key1 := types.NewKVStoreKey("store1") key2 := types.NewKVStoreKey("store2") diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index a347a5f5427e..4aa785bbb307 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -29,7 +29,7 @@ type SubspaceTestSuite struct { func (suite *SubspaceTestSuite) SetupTest() { db := dbm.NewMemDB() - ms := store.NewCommitMultiStore(db) + ms := store.NewCommitMultiStore(db, log.NewNopLogger()) ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) suite.NoError(ms.LoadLatestVersion()) diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index ec2bfa824d07..c339aa4045f9 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -30,7 +30,7 @@ func defaultLogger() log.Logger { } func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { - rs := rootmulti.NewStore(db) + rs := rootmulti.NewStore(db, log.NewNopLogger()) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) @@ -47,7 +47,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { } func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { - rs := rootmulti.NewStore(db) + rs := rootmulti.NewStore(db, log.NewNopLogger()) rs.SetPruning(store.PruneNothing) key := sdk.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil)